/*
Edited: 13 Aug 2008 (Andrew Keats @ 15:45)
Website: 
Created: 22 February 2008
Author: Henry Tapia

NOTE: These scripts are based on jQuery 1.2.3
*/

$(document).ready(function(){ 
	$(document).pngFix(); 
}); 

$(document).ready(function(){
	// this is for the more section of primary nav
	$("li.more>a").click(function () {
    	$("#more-submenu").toggle();
    });
    
 	// invoke swfobject
	if ($("#flash-content").length  > 0) {
		/*$.getScript("/Assets/Scripts/swfobject.js", function()
			 {
				window.setTimeout(function()
				   {*/
					//var flashClass = document.getElementById("flash-content").className
					var flashClass = $("#flash-content").attr("class");
					var flashvars = {};
					var params = { bgcolor: "#000000", wmode: "transparent" };
					var attributes = { id: 'flash-content', name: 'flashcontent' };
					switch (flashClass)
					   {
						case "homepage":
						   	swfobject.embedSWF("/Assets/Media/dunlop_homepage_flash.swf", "flash-content", "780", "508", "8", "/Assets/Media/expressInstall.swf", flashvars, params, attributes );
							break;
						case "tennis":
							swfobject.embedSWF("/Assets/Media/tennis_home.swf", "flash-content", "568", "262", "8", "/Assets/Media/expressInstall.swf", flashvars, params, attributes );
							break;
						default:
							//swfobject.embedSWF("/Assets/Media/tennis_home.swf", "flash-content", "568", "262", "8", "/Assets/Media/expressInstall.swf", flashvars, params, attributes );
							swfobject.embedSWF();
					   }
				   /*}, 250); 
			}
		);*/
		
	}
	
	// invoking the carousel
	if ($('.carousel').length > 0) {
	    // this shows the carousels once content is loaded
	    $('#carousel-content').css('display', 'block');
		$('.carousel').jcarousel();
	}
	
	// left navigation accordion
	$("#category-navigation ul li h2.current").parents("li").addClass("current");
	$("#category-navigation ul li.current").parents("ul").addClass("current");
	$("#category-navigation ul li.current").addClass("active").removeClass('inactive').parents("li").addClass("active");
	$("#category-navigation ul").not(".current").css("display","none");	// leave current sections current
	$("#category-navigation ul li.current").parent("ul").addClass("active");
	$("#category-navigation ul li.current").children("ul").addClass("current");
	$("#category-navigation ul.current li").siblings().not(".first").addClass("inactive");
	$("#category-navigation ul li").each(function() {
			if ($(this).hasClass("active")) {
				$(this).removeClass("inactive");
			}
		});
	$("#category-navigation  ul > li").click(function () {
    	$(this).addClass('active').children('ul').slideDown("easein");
		$(this).children('ul').children('li').addClass('inactive');
		$(this).siblings('li').removeClass('active').children('ul').slideUp("easein");
		$("#category-navigation ul li").each(function() {
			if ($(this).hasClass("active")) {
				$(this).removeClass("inactive");
			}
		});
    });
	
	// show dynamic elements - corresponding with items in hide.css
	$(document).ready(function(){
		$('#category-navigation ul li ul.current').css('display', 'block').slideDown("easein");
	});
	
	// following is for tabs
    var tabContainers = $('div.tabs > div');
    
    $('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        $('div.tabs ul.tabNavigation li').removeClass('active');
        $(this).parent().addClass('active');
        
        return false;
    }).filter(':first').click();
	
	// following is for tabbed images
	var tabbedImages = $('div#image-content div#main-images > img');
	/*var halfDiv = Math.floor($('div#main-images').height()/2);	// calculate container height then half
	tabbedImages.each(function(){
		var halfImg = Math.floor($(this).height()/2)	// calculate image height then half
		$(this).css('margin-top', halfDiv-halfImg);	// calculate margin-top and add to image
	});
	*/
    $('div#image-content ul.list-x-axis a').click(function () {
        tabbedImages.hide().filter(this.hash).show();
        
        $('div#image-content ul.list-x-axis li').removeClass('active');
        $(this).parent().addClass('active');
        
        return false;
    }).filter(':first').click();
	// this gets rid of the hover state on list items without link inside, for tabbed images
		$('div#image-content ul.list-x-axis li').each(function() {
			if ($(this).children('a').length < 1) {
				$(this).css("border-color", "#424242");
			}
	});
	
	// following is for tabbed carousels
    var tabbedCarousels = $('div#carousel-content > div.carousel-box');
    
    $('div#product-scroller-box ul.list-x-axis a').click(function () {
        tabbedCarousels.hide().filter(this.hash).show();
        
        $('div#product-scroller-box ul.list-x-axis li').removeClass('active');
        $(this).parents('li').addClass('active');
        
        return false;
    }).filter(':first').click();
	
	// site map - displaying lists vertically when there are no child elements
		$('#site-map li').each(function() {
			if ($(this).children('ul').length < 1) {
				$(this).css({ float: "none", display: "block", clear: "both"});
			}
	});
		
	// this is for adding gt arrows to breadcrumbs
		$("#main-content .breadcrumbs li").not(":first").each(function(){ 
			$(this).prepend(document.createTextNode(" > "));
			});
	
	//end
});

