$(document).ready(function() {
	var home = true;
	var first_run = true;
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};
		
	$("#s").focus(function() {
		if($(this).val() == 'Search') {
			$(this).val('');
		}
	}, function() {
		if($(this).val() == '') {
			$(this).val('Search');
		}
	});
	
	
	if($('body').hasClass("home")) {
		home = true;
		$("#FeaturedSliderSub").show();
		$('#header').css({backgroundPositionY: '0px'});
		$("#FeaturedSliderVideo").show();

	}
	else {
		home = false;
		$("#FeaturedSliderSub").hide();
		$('#header').css({backgroundPositionY: '-149px'});
	}
	
	$("#link_RedDotLogo").click(function() {
		if(!$("#FeatureSliderVideo").is(':visible')) {
			$("#FeaturedSliderSub").slideDown();
			$("#FeaturedSliderVideo").fadeIn();
			$("#FeaturedSliderX").hide();
			$("#FeaturedSliderVideoX").show();
			
			if(!home) {
				if($.browser.msie) {
					$("#Header").animate({
						backgroundPositionY:'-149px'
					}, 500);
				}
				else {
					$("#Header").animate({
						backgroundPosition:'0px -149px'
					}, 500);
				}
			}
		}
		else {
			$("#FeaturedSliderVideoX").hide();
			$("#FeaturedSliderVideo").fadeOut();
			if(!home) {
				if($.browser.msie) {
					$("#Header").animate({
						backgroundPositionY:'0px'
					}, 500);
				}
				else {
					$("#Header").animate({
						backgroundPosition:'0px 0px'
					}, 500);
				}
			}
			$("#FeaturedSliuderX").show();
		}
	});
	
	$(".arrow").click(function() {
		$("#FeaturedSliderVideo").slideUp();
	});
		
	$(".FeaturedSliderX").click(function() {
		$(this).hide();
		if($(this).attr('id') == "FeaturedSliderX") {
			if($.browser.msie) {
				$("#Header").animate({
					backgroundPositionY:'-149px'
				}, 500);
			}
			else {
				$("#Header").animate({
					backgroundPosition:'0px -149px'
				}, 500);
			}
			
			$(this).parent().slideUp();
		}
		else {
			$(this).parent().fadeOut();
			$("#FeaturedSliderX").show();
		}
	});
	
	function paginate(ind, el)
	{
		if (ind == 0) return '<a class="feat_slider_button" id="Bthe-selection"><img src="'+template_url+'/images/slider/the-selection-over.png"></a>';
		else if (ind == 1) return '<a class="feat_slider_button" id="Bthe-clip"><img src="'+template_url+'/images/slider/the-clip-off.png"></a>';
		else if (ind == 2) return '<a class="feat_slider_button" id="Bthe-light"><img src="'+template_url+'/images/slider/the-light-off.png"></a>';
		else if (ind == 3) return '<a class="feat_slider_button" id="Bthe-smoke"><img src="'+template_url+'/images/slider/the-smoke-off.png"></a>';
	}
	
	function onPagerClick(index, el) {
		if(!$("#FeaturedSliderSub").is(":visible")) {
			$("#FeaturedSliderSub").slideDown();
			if($.browser.msie) {
				$("#Header").animate({
					backgroundPositionY:'0px'
				}, 500);
			}
			else {
				$("#Header").animate({
					backgroundPosition:'0px 0px'
				}, 500);
			}
		}
		else if($("#FeaturedSliderVideo").is(":visible")) {
			$("#FeaturedSliderVideo").slideUp();
		}
		$(".FeaturedSliderX").show();
	}
	
	function onBefore(out_el) {
			
		var old_id = $(out_el).attr('id');
		$("#B"+old_id+" img").attr('src', template_url+"/images/slider/"+old_id+"-off.png");
		
		var id = $(this).attr('id');
		$("#B"+id+" img").attr('src', template_url+"/images/slider/"+id+"-over.png");
		
	}
	
	
	$('#FeaturedSlider').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 0, 
		next:   '#SliderRightArrow', 
		prev:   '#SliderLeftArrow',
		pager: '#FeaturedSliderNav',
	    pagerAnchorBuilder: paginate, 
		before: onBefore, 
		pagerClick: onPagerClick
	});
	
	
	
	
	$(".lights a").hover(function() {
		if(!$(this).hasClass('active')) {
			var id = $(this).attr('id').substr(5);
			$(this).children('.link').attr('src', template_url + "images/header/"+id+"-over.png");
		}
	}, function() {
		if(!$(this).hasClass('active')) {		
			var id = $(this).attr('id').substr(5);
			$(this).children('.link').attr('src', template_url + "images/header/"+id+".png");
		}
	});
	
	$(".rollover").hover(function() {
		var id = $(this).attr('id').substr(5);
		$(this).children('img').attr('src', template_url + "images/rollover/"+id+"-over.png");
		
	}, function() {		
		var id = $(this).attr('id').substr(5);
		$(this).children('img').attr('src', template_url + "images/rollover/"+id+".png");
	});
		
	$(".rollover_img").hover(function() {
		var id = $(this).attr('id').substr(5);
		$(this).attr('src', template_url + "images/rollover/"+id+"-over.png");
		
	}, function() {		
		var id = $(this).attr('id').substr(5);
		$(this).attr('src', template_url + "images/rollover/"+id+".png");
	});
	
});

