$(document).ready(function(){      

	// replace text
	swapValues = [];
	$(".swap").each(function(i){
		swapValues[i] = $(this).val();
		$(this).focus(function(){
	  	if ($(this).val() == swapValues[i]) {
	       	$(this).val("");
	  	}
		}).blur(function(){
	  	if ($.trim($(this).val()) == "") {
			$(this).val(swapValues[i]);
	    	}
		});
	});
	
	// current link
	function filterPath(string) {
		return string
		.replace(/^\//,'')
		.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
		.replace(/\/$/,'');
	} 
	$("#nav a").filter(function() {
		return filterPath(this.pathname) == filterPath(location.pathname);
	}).addClass('current');

	// watches home
	$("#color-bgs li:first").fadeIn();
	$("#watches a:not(:animated)").hover(
		function () {
			var cat = $("."+$(this).parent().attr('class')+"-bg");
			$("#watches-home").attr('class',$(this).parent().attr('class'));
			$(this).find('.watch').stop().animate( { marginTop:"-=20px"}, 200 );
			$(this).find('.reflection').stop().animate( { bottom:"-=20px"}, 200 );
			if ( cat.is(':hidden') ) {
				$(cat).css("z-index","99").fadeIn(900,function(){
					$(this).css("z-index","0");
				});
				$(cat).siblings().fadeOut(900);
			}
		},
		function () {
			$(this).find('.watch').stop().animate( { marginTop:"0"}, 300 );
			$(this).find('.reflection').stop().animate( { bottom:"0"}, 300 );
		}
	);
	
	$("a.left").hide();
	$(".more a").click(function(){
		var toMove = $(this).parent().parent().attr('class');
		var direction = $(this).attr('class');
		if (direction=="right") {
			$("#"+toMove).stop().animate( { marginLeft:"-=338px" }, 300 );
			$(this).hide();
			$("a.left").show();
		} else if (direction="left") {
			$("#"+toMove).stop().animate( { marginLeft:"+=338px" }, 300 );			
			$(this).hide();
			$("a.right").show();
		};
	});
	
	// press page
	$("#articles li:first").fadeIn(500);
	$("#press-thumbs li:first").addClass("current");
	$("#press-thumbs a").click(function(){
		var toLoad = $(this).attr("href");
		$("#press-thumbs li").removeClass("current");
		$(this).parent().addClass("current");
		$("#articles li:visible").fadeOut(500,function(){
			$(toLoad).fadeIn(500);
		});
		return false;
	});
	
	// scrollbar
	$("#details").jScrollPane({showArrows:true, scrollbarWidth: 14, arrowSize: 12});
	
	// t&c
	$(".termslink").click(function(){
		$("#tc-details").parent().slideToggle();
		return false;
	});
	
	// coming soon
	$(".soon").click(function(){
		return false;
	});
	
	// swish
	$("a").swish();
	$("a.soon").swish({hoverclass:"soonhover"});
	$(".black-bg a#back").swish({hoverclass:"darkhover"});

});