// URL HASH BOX EXPANDER 

$(document).ready(function(){
	
	if(self.document.location.hash) {
		hashTag = self.document.location.hash.substring(1);
		$('.hash'+hashTag).removeClass("closed");
	} else {
		$('.hashAddress').removeClass("closed");
	}
	
});


//FIND CONTENT BY

$(document).ready(function(){
	
	$(".dropBox").addClass("closed");

	$(".dropBox .dropHeader").click(
		function(){
									
			if ($(this).parents(".dropBox").hasClass("closed")) {
				$(this).parents(".dropBox").removeClass("closed");
			} else {
				$(this).parents(".dropBox").addClass("closed");
			}
			
			$(this).siblings(".dropContent").slideToggle("fast");
	  	}
	);
	
	$(".dropBox").hover(
		function(){
			
	  	}, 
		function () {		
			$(this).addClass("closed");
			$(this).children(".dropContent").slideUp("fast");
		}
	);
	
});


// FILTER BOXES 
	
$(document).ready(function(){
	
	$(".filterExpandable .closed").siblings(".filterContent").hide();
	$(".filterExpandable .closed").siblings(".allNone").hide();
	
	$(".filterExpandable .filterTop").click(
		function(){
			$(this).siblings(".filterContent").slideToggle("fast");
			if ($(this).hasClass("closed")) {
				$(this).removeClass("closed");
				$(this).siblings(".allNone").show("fast");
			} else {
				$(this).addClass("closed");
				$(this).siblings(".allNone").hide("fast");
			}
	  	}
	);
	
	
// SELECT ALL / CLEAR

	$(".allNone li").click(
		function(){
			if ($(this).hasClass("all")) {
				$(this).parent().parent().siblings(".filterContent").find("input:checkbox").each(function() {
   					this.checked = true;
				 });
			} else if ($(this).hasClass("none")) {
				
				$(this).parent().parent().siblings(".filterContent").find("input:checkbox").each(function() {
   					this.checked = false;
					$(this).removeClass("checked");
				 });
			}
			setupShowFilters(false);
	  	}
	);	
	
});


// FILTER SHOWS
	
$(document).ready(function(){
						   
	setupShowFilters(true);
	
	$(".showFilter input:checkbox").click(
		function(){
			$(this).each(function() {
				if (this.checked) {
					//alert($(this).attr("class")+' true');
					filterByShow($(this).attr("class"), true, false);
				} else {
					//alert($(this).attr("class")+' false');
					filterByShow($(this).attr("class"), false, false);
				}
			});
				
		}
	);
	
});

function setupShowFilters(immediate) {
	$(".showFilter input:checkbox").each(function() {
			if (this.checked) {
				filterByShow($(this).attr("class"), true, immediate);
			} else {
				filterByShow($(this).attr("class"), false, immediate);
			}
		}
	);	
}

function filterByShow (showName, action, immediate) {
	$(".filterContent .checkboxList").find("input:checkbox").each(function() {
		if ($(this).hasClass(showName)) {
			if (action) {
				if ($(this).hasClass("checked")) {
					this.checked = true;
					$(this).removeClass("checked");
				}
				//this.checked = true;
				if (immediate) {
					$(this).parent().parent().show();
				} else {
					$(this).parent().parent().slideDown("fast");
				}
			} else {
				if (this.checked) {
					this.checked = false;
					$(this).addClass("checked");
				}
				//this.checked = false;
				if (immediate) {
					$(this).parent().parent().hide();
				} else {
					$(this).parent().parent().slideUp("fast");
				}
			}
		}
	 });
}
	
	
	
// FILTER BOX TABS

	
$(document).ready(function(){
						   
	$(".tabs .tab1.closed").parent().siblings(".tab1Content").hide();
	$(".tabs .tab2.closed").parent().siblings(".tab2Content").hide();
						   
	$(".tabs .tab1").click(
		function(){
			if ($(this).hasClass("closed")) {
				$(this).removeClass("closed");
				$(this).siblings(".tab2").addClass("closed");
				$(this).parent().siblings(".tab1Content").fadeIn("fast");
				$(this).parent().siblings(".tab2Content").hide();
				setupShowFilters(true);
			}
	  	}
	);
	
	$(".tabs .tab2").click(
		function(){
			if ($(this).hasClass("closed")) {
				$(this).removeClass("closed");
				$(this).siblings(".tab1").addClass("closed");
				$(this).parent().siblings(".tab2Content").fadeIn("fast");
				$(this).parent().siblings(".tab1Content").hide();
				setupShowFilters(true);
			}
	  	}
	);
	
});




// RESULTS LIST HEADERS
	
$(document).ready(function(){
						   	
	$(".results .resultHeader.closed").next(".resultList").hide();		   
	
	$(".results .resultHeader").click(
		function(){
			$(this).next(".resultList").slideToggle("fast");
			if ($(this).hasClass("closed")) {
				$(this).removeClass("closed");
			} else {
				$(this).addClass("closed");
			}
	  	}
	);
	
});


// RESULTS LIST RESULTS
	
$(document).ready(function(){
						   	
	$(".results .result.closed .resultDetail").hide();		   
	
	$(".results .result .resultExpand").click(
		function(){
			$(this).siblings(".resultDetail").slideToggle("fast");
			
			if ($(this).parents(".result").hasClass("closed")) {
				$(this).parents(".result").find(".resultSummary .iconSummary").fadeOut("fast");
				$(this).parents(".result").removeClass("closed");
			} else {
				$(this).parents(".result").find(".resultSummary .iconSummary").fadeIn("fast");
				$(this).parents(".result").addClass("closed");
			}
	  	}
	);	   
	
	$(".results .result h3").click(
		function(){
			$(this).parents(".resultSummary").siblings(".resultDetail").slideToggle("fast");
			
			if ($(this).parents(".result").hasClass("closed")) {
				$(this).parents(".result").find(".resultSummary .iconSummary").fadeOut("fast");
				$(this).parents(".result").removeClass("closed");
			} else {
				$(this).parents(".result").find(".resultSummary .iconSummary").fadeIn("fast");
				$(this).parents(".result").addClass("closed");
			}
	  	}
	);
	
});


// QUICK LINK DROPDOWN 

$(document).ready(function(){	   
	
	$(".quicklink .quicklinkToggle").click(
		function(){
			$(this).siblings(".quicklinkContent").slideToggle("fast");
			
			if ($(this).parents(".quicklink").hasClass("closed")) {
				$(this).parents(".quicklink").removeClass("closed");
			} else {
				$(this).parents(".quicklink").addClass("closed");
			}
	  	}
	);
	
	$(".quicklink").hover(
		function(){
			
	  	}, 
		function () {
			$(this).addClass("closed");
			$(this).children(".quicklinkContent").slideUp("fast");
		}
	);
	
});


// SIGN IN DROPDOWN 

$(document).ready(function(){	   
	
	$(".signin .signinToggle").click(
		function(){
			$(this).siblings(".signinContent").slideToggle("fast");
			
			if ($(this).parents(".signin").hasClass("closed")) {
				//$(this).siblings(".signinContent").show();
				$(this).parents(".signin").removeClass("closed");
			} else {
				//$(this).siblings(".signinContent").hide();
				$(this).parents(".signin").addClass("closed");
			}
	  	}
	);
	
		   
	
	$(".signin .closeIt").click(
		function(){
			$(this).parents(".signinContent").slideToggle("fast");
			$(this).parents(".signin").addClass("closed");			
	  	}
	);
	
});





//SCROLLER LIST

$(document).ready(function(){
						   
	currentItem = 0;
	itemWidth = 160;
	
	$('.scroller .scrollerLeft img').click(
		function(e){
			noItems = $(this).parents('.scroller').find('.scrollerList ul').size();
			if (currentItem > 0) {				
				currentItem -= 1;
				$(this).parents('.scroller').find('.scrollerList ul').animate({left: '+='+itemWidth+'px'}, 500);
				e.preventDefault();

			}
	  	}
	);

	$('.scroller .scrollerRight img').click(
		function(e){
			noItems = $(this).parents('.scroller').find('.scrollerList ul li').size();
			if (currentItem < (noItems - 2)) {
				currentItem += 1;
				$(this).parents('.scroller').find('.scrollerList ul').animate({left: '-='+itemWidth+'px'}, 500);
				e.preventDefault();
			}
	  	}
	);
	
});

//WIDE LIST

$(document).ready(function(){
						   
	currentWideItem = 0;
	itemWideWidth = 156;
	
	$('.scrollerWide .scrollerLeft img').click(
		function(e){
			noItems = $(this).parents('.scrollerWide').find('.scrollerList ul').size();
			if (currentWideItem > 0) {				
				currentWideItem -= 1;
				$(this).parents('.scrollerWide').find('.scrollerList ul').animate({left: '+='+itemWideWidth+'px'}, 500);
				e.preventDefault();

			}
	  	}
	);

	$('.scrollerWide .scrollerRight img').click(
		function(e){
			noItems = $(this).parents('.scrollerWide').find('.scrollerList ul li').size();
			if (currentWideItem < (noItems - 3)) {
				currentWideItem += 1;
				$(this).parents('.scrollerWide').find('.scrollerList ul').animate({left: '-='+itemWideWidth+'px'}, 500);
				e.preventDefault();
			}
	  	}
	);
	
});



//SCROLLER LIST

$(document).ready(function(){
						   
	$(".flipper .images .image").hide();
	$(".flipper .images .0").show();	
	
	$('.flipper .buttons li a').mouseenter(
		function(){
			theNumber = $(this).parents('li').attr("class");
			$(this).parents('.flipper').find('.images .'+theNumber).fadeIn(250);
	  	}							   
	);
	
	$('.flipper .buttons li a').mouseout(
		function(){
			theNumber = $(this).parents('li').attr("class");
			$(this).parents('.flipper').find('.images .'+theNumber).fadeOut(250);
	  	}							   
	);
	
});
