$(document).ready(function() {
	$(".paging").show();
	$(".paging a:first").addClass("active");
	var imageWidth = $("#button_frame").width();
	var imageSum = $(".button_slide").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//alert(imageWidth+" "+imageSum+" "+imageReelWidth);
	$("#button_film").css({'width' : imageReelWidth});
	
	rotate = function(){
		var triggerID = $active.attr("rel") - 1; 
		var image_reelPosition = triggerID * imageWidth; 
		//alert(image_reelPosition);
		$(".paging a").removeClass('active'); 
		$active.addClass('active'); 
		$("#button_film").animate({left: -image_reelPosition	}, 500 );
	}; 
	
	rotateSwitch = function(){
		play = setInterval(function(){
			$active = $('.paging a.active').next(); 
			if ( $active.length === 0) {$active = $('.paging a:first');}
			rotate();
		}, 8000);
	};
	
	rotateSwitch(); //Run function on launch
	
	$("#button_film a").hover(function() {clearInterval(play);}, function(){rotateSwitch();});	
	$(".paging a").click(function() {$active = $(this);clearInterval(play);rotate();rotateSwitch();return false;});
});

$(document).ready(function(){
	$('.color_filter, .color_filter_a').click(function(){
		nvar = $(this).text();
		reltag = $(this).attr("rel");
		if (reltag=="0") $(this).removeClass("color_filter").addClass("color_filter_a").attr("rel","1");
		if (reltag=="1") $(this).removeClass("color_filter_a").addClass("color_filter").attr("rel","0");
	});
	$('.size_filter, .size_filter_a').click(function(){
		nvar = $(this).text();
		reltag = $(this).attr("rel");
		if (reltag=="0") $(this).removeClass("size_filter").addClass("size_filter_a").attr("rel","1");
		if (reltag=="1") $(this).removeClass("size_filter_a").addClass("size_filter").attr("rel","0");
	});
	$('.price_filter, .price_filter_a').click(function(){
		nvar = $(this).text();
		reltag = $(this).attr("rel");
		if (reltag=="0") $(this).removeClass("price_filter").addClass("price_filter_a").attr("rel","1");
		if (reltag=="1") $(this).removeClass("price_filter_a").addClass("price_filter").attr("rel","0");
	});
	$('.tag_filter, .tag_filter_a').click(function(){
		nvar = $(this).text();
		reltag = $(this).attr("rel");
		if (reltag=="0") $(this).removeClass("tag_filter").addClass("tag_filter_a").attr("rel","1");
		if (reltag=="1") $(this).removeClass("tag_filter_a").addClass("tag_filter").attr("rel","0");
	});
	$('.glaze_filter, .glaze_filter_a').click(function(){
		nvar = $(this).text();
		reltag = $(this).attr("rel");
		if (reltag=="0") $(this).removeClass("glaze_filter").addClass("glaze_filter_a").attr("rel","1");
		if (reltag=="1") $(this).removeClass("glaze_filter_a").addClass("glaze_filter").attr("rel","0");
	});
	

	$('#submit_filter').click(function(){
		
		var colors = new Array();  
		var prices = new Array();  
		var sizes = new Array();  
		var tags = new Array();  
		var glazes = new Array();  
		
		n=0;
		$(".color_filter_a").each(function(){ colors[n] = $(this).text(); n++; });
		n=0;
		$(".price_filter_a").each(function(){ 
				text = $(this).text();
				text = text.replace("$","");
				prices[n] = text; 
				n++; 
		});
		n=0;
		$(".size_filter_a").each(function(){ sizes[n] = $(this).text(); n++; });
		n=0;
		$(".tag_filter_a ").each(function(){ tags[n]= $(this).text(); n++; });
		n=0;
		$(".glaze_filter_a ").each(function(){ glazes[n]= $(this).text(); n++; });
		
		colorfilter = colors.join(",");
		pricefilter = prices.join(",");
		sizefilter = sizes.join(",");
		tagfilter = tags.join(",");
		glazefilter = glazes.join(",");
		
		sendURL = "?f=filter&colors="+colorfilter+"&prices="+pricefilter+"&sizes="+sizefilter+"&tags="+tagfilter+"&glazes="+glazefilter+"#search";
		//alert(sendURL);
		window.location = sendURL;
	});
	
	
/*	$('.sort').click(function(event){
		event.preventDefault();
		var sorter = $(this).attr("id");
		var pathname = new String(window.location);
		if (pathname.indexOf("?") > -1){
			var patharray = pathname.split("?");
			pos = patharray[1].search("sort");
			if (pos != -1){
				splitter = patharray[1].substring(0, pos-1);
				if (splitter == "") newpath = "?sort="+sorter;
				else newpath = "?"+splitter+"&sort="+sorter;
			}else{
				newpath = "?"+patharray[1]+"&sort="+sorter;
			}
		}else{
			newpath = "?sort="+sorter;
		}
		window.location = newpath;
	});
*/	

});


$(document).ready(function(){
	
	$('.filter_head').click(function(){
		$filter = $(this).next('.toggle');
		if ($filter.is(':visible')){
			 $filter.slideUp();
		}
		else {
			 $filter.slideDown();
		}
	});
	
	$(".buttonImageImg").click(function(){
		image=$(this).attr("src");
		node=$(this).attr("name");
		$("#popup img").attr("src",image);
		$("#popup a").attr("href",node);
		$("#popup").center();
		$("#popup").fadeIn();
	})


});

