$(document).ready(function() {
// PNG fixes
	if ($.browser.msie) {
		$('#strapline').clone(false).attr('id', 'strapline1').appendTo('#strapline');
		//$('#home_top_items').css({'position' : 'relative', 'top' : '-70px'});
		
		$('#channel_promos li a img').each(function(index) {
		var pngSrc = $(this).attr('src');
		$(this).parent().css("filter","\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + pngSrc + ",sizingMethod='image')\"");
		});
		
		$(".flare").css("filter","\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/_img/top10/flare.png',sizingMethod='image')\"");
		$(".white_flash_btn, .white_flash_btn span").css("filter","\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/_img/top10/buttons.png',sizingMethod='image')\"");
		if ($.browser.version == 6) {
			$("#skylineG #skyline").css("filter","\"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='_img/top10/globalSky.png',sizingMethod='image')\"");
		}
	}
	
	// Remove noJS tags and set z-index of logo
	$('#channel_promos li').removeClass('noJsHover');
	$('#skyline').removeClass('noJsGlobal');
	
	// Parallax
	if (!$('.globalNav').length) {
		// Show sections
		sectionTimer = setInterval ( "showSections()", 170 );
		jQuery('#parallax').jparallax({yorigin:0.1}, {ytravel:0}, {takeoverFactor:0.5, takeoverThresh:0.6, ytravel:'20px'}, {ytravel:0}, {takeoverFactor:0.1, takeoverThresh:1, ytravel:'30px'});
	} else {
		$('#skyline').hide();
	}
	
	

	$('#home_top').click(function() {
  		if (!$('.globalNav').length) {clearInterval(sectionTimer);}
  		$('#channel_promos li').show().css({'top' : 0})
	});
	
	// Flare fade in / fade out
	if ($.browser.msie && $('.globalNav').length) {var showHide = 1} else {var showHide = 0}
	
	function flareFadeIn(status, itemLi) {
		switch(showHide)
			{case 0:
				if (status == 0) {
					$(itemLi).children(".flare, .white_flash_btn").fadeIn(500);
				} else {
					$(itemLi).children(".flare, .white_flash_btn").fadeOut('fast');
				}
				break;
			case 1:
				if (status == 0) {
					$(itemLi).children(".flare, .white_flash_btn").show();
				} else {
					$(itemLi).children(".flare, .white_flash_btn").hide();
				}
			}
	}
	
	$("#channel_promos li").hover(
	function(){
	if($(this).children(".flare").is(':hidden') ) {
		flareFadeIn(0, this)
		}
			},
	function(){
		flareFadeIn(1, this);
	}	
	);

	// Expand global nav
	var hoverOff = true;
	
		$("#moreFromTrick").mouseover(function() {
			if (hoverOff == true) {
				$('#moreFromTrick').hide();
				$('#skyline').show();
				$("#moreFrom").addClass('moreFromState');
				$("#skyline").stop().animate({"top": "-366px"}, 200);
			}
		});

		$("#moreFrom").mouseleave(function() {
			if (hoverOff == true) {
				$("#skyline").stop().animate({"top": "-374px"}, 200, function() {
				$('#moreFrom').removeClass('moreFromState');
				$('#skyline').hide();
				$('#moreFromTrick').show();
				});
			  }
		});

	
	$("#moreFrom").toggle(function() {
			hoverOff = false;
			$('#quick_search').hide();
			$("#skyline").stop().animate({"top": "0"}, 400);
			$("#moreFrom span").html('Close').css('background-position', 'right -27px');
		}, function() {
			$('#quick_search').show();
			$("#skyline").animate({"top": "-374px"}, 400, function() {
			$('#moreFrom').removeClass('moreFromState');
			$('#moreFromTrick').show();
			$("#skyline").hide();
			hoverOff = true;
		});
			$("#moreFrom span").html('More from Top10.com').css('background-position', 'right -10px');
			$("body").focus();
	});
	
// End of Doc Ready
});

$(window).load(function () {
	$('#channel_promos .liLink span').addClass('item_image');
})
	
// showSections fucntion 	
	if (!$('.globalNav').length) {var globalI = 0;} else {var globalI = 1;}
	
	function showSections() {
	if (globalI != 0 && !$.browser.msie) {$('#channel_promos li:nth-child('+globalI+')').css('opacity', 0).show().animate({"top": "0px", opacity: 1}, 400)}
	else if (globalI != 0) {
		$('#channel_promos li:nth-child('+globalI+')').fadeIn(250).animate({"top": "0px"}, 500);
		}
	if (globalI == 5) {return clearInterval(sectionTimer);}
	globalI++;
	}
	
