﻿var hideWait = false;
var typesvisible = false;
var expertsvisible = false;
function HidePopUp(item)
{
	if(hideWait)
	{
		hideAll(500);
		if(item)
			$(item).hide('medium');
	}
}

function SetupImages(images)
{
	/* preload the images */
	//placeholder for images (not visible)
	$("#navigation").prepend("<div class='placeholder' style='position:absolute; left:-999em;'></div>");	
	//add each image
	for(i=0; i<images.length;i++) {
		$("#navigation .placeholder").prepend("<img src='" + images[i] + "' alt=''/>");
	}
	$("#navigation ul.menu.lvl1 li.lvl1").mouseenter(function() {
		var index = $("#navigation ul.menu.lvl1 li.lvl1").index(this);
		var image = images[index];
		$("#banner").css("background-image", "url(" + image + ")");
		SetBannerText(index);
	}).mouseleave(function() {
		//reset
		var image = images[0];
		$("#banner").css("background-image", "url(" + image + ")");
		SetBannerText(0);
	});
}

function SetBannerText(index)
{//alert(index);
	var index2 = index + 1;
	HideBanners();
	$('.bannercontainer .banner' + index2).show();
}
function HideBanners()
{
	for(var i = 1; i < 10; i++)
	{
		if($(".bannercontainer .banner" + i).css("display") == "block")
		{
			$('.bannercontainer .banner' + i).hide();
		}
	}
}

$(document).ready(function () {

	
    // Fix background image caching problem    
    if (jQuery.browser.msie) 
    {        
        try 
        {
             document.execCommand("BackgroundImageCache", false, true);
        } 
        catch(err) {}    
    }   
    
    $('#expertsLink').css('cursor', 'pointer');	
    $('#expertsLink').mouseenter(function () 
    {
   
    	hideWait=false;
    	var margin = $('#topFiveRes').css('marginRight');
    	
    	if(!expertsvisible)
    	{
    		hideAll(0, function() {
    			expertsvisible = true;
    			$('#topFiveRes').css('display', 'block'); 
    			$('#topFiveRes').animate( { marginRight: '0px' }, 500 );    			
    		});   		
     	}
    }).mouseleave(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp();',2000);	    
    });
    $('#topFiveRes').mouseenter(function() 
    {
    	hideWait=false;
    }).mouseleave(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });

    
    $('#ProductFinder').css('cursor', 'pointer');	
    $('#ProductFinder .content').mouseenter(function () 
    {
    	hideWait=false;
    	var margin = $('#producttypesRes').css('marginRight');
    	  
    	if(!typesvisible)
    	{
    		hideAll(0, function(){
    			typesvisible = true;
	    		$('#producttypesRes').css('display', 'block');
	     	    $('#producttypesRes').animate( { marginRight: "0px" }, 500 );
	     	    
     	    });
     	}  	
    }).mouseleave(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);	    
    }); 
      
    $('#producttypesRes').mouseenter(function() 
    {
    	hideWait=false;
    }).mouseleave(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
    
    $('#producttypesRes li').each(function() {
    	$(this).css('cursor', 'pointer');
    });
    
    $('#producttypesRes li.resAntifouling').click(function () 
    {
    	HideBanners();
		showSubMenu('#prodTypesRes .resAntifouling');    	 	
    });		
	$('#producttypesRes li.resFinishes').click(function () 
    {
    	HideBanners();
    	showSubMenu('#prodTypesRes .resFinishes');  	 	
    });	
	$('#producttypesRes li.resVarnishes').click(function () 
    {
    	HideBanners();
		showSubMenu('#prodTypesRes .resVarnishes'); 	 	
    });    	
	$('#producttypesRes li.resPrimers').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resPrimers'); 	 	
    });   	
	$('#producttypesRes li.resUndercoats').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resUndercoats'); 	 	
    }); 		
	$('#producttypesRes li.resFillers').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resFillers'); 	 	
    });  
    $('#producttypesRes li.resBoatcare').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('.resBoatcare'); 	 	
    });
    $('#producttypesRes li.resThinners').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resThinners'); 	 	
    }); 
    $('#producttypesRes li.resEpiglass').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resEpiglass'); 	 	
    });     
     $('#producttypesRes li.resOsmosis').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resOsmosis'); 	 	
    });     
    $('#producttypesRes li.resMiscellaneous').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resMiscellaneous'); 	 	
    }); 
     $('#producttypesRes li.resWood').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resWood'); 	 	
    });  
     $('#producttypesRes li.resSpecial').click(function () 
    {
    	 HideBanners();
    	 showSubMenu('#prodTypesRes .resSpecial'); 	 	
    });  

      
    $('#prodTypesRes .resAntifouling').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
    $('#prodTypesRes .resFinishes').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
	$('#prodTypesRes .resVarnishes').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
	$('#prodTypesRes .resPrimers').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
	$('#prodTypesRes .resUndercoats').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
	$('#prodTypesRes .resFillers').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
    $('#prodTypesRes .resBoatcare').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });
	$('#prodTypesRes .resThinners').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });		
    $('#prodTypesRes .resEpiglass').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });			
    $('#prodTypesRes .resOsmosis').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });		
	$('#prodTypesRes .resMiscellaneous').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });	
    $('#prodTypesRes .resWood').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });		
    $('#prodTypesRes .resSpecial').mouseover(function()
    {
    	hideWait=false;
	}).mouseout(function()
    {
    	hideWait=true;
	    setTimeout('HidePopUp()',2000);
    });	
    	
	function showSubMenu(name)
	{
	
		var shown = false;
		$('div.bluegld').each(function()
		{
			var display = $(this).css('display');
			if(display == 'block')
			{			
				$(this).css('display', 'none');
							
				shown = true;
				return false;
			}
		});
		showElem(name);
		/*
		if(!shown)
		{
			showElem(name);
		}*/
		

	}
	
	function showElem(name)
	{
		$(name + ' div.bluegld').css('display', 'block');
		/*$(name + ' .bluegld div.glditems').css('overflow', 'hidden');*/
	}
		
	$('.columns').each(function() {
		var counter = 1;
		var pageSize = 13;
		$(this).children('li').each(function() {

			if(counter > pageSize && counter < (pageSize * 2 ) + 1)
			{
				$(this).css('position','relative');
				$(this).css('left','220px');
				$(this).css('top','-195px');
			}
			if(counter > (pageSize * 2 ) && counter < (pageSize * 3 ) + 1)
			{
				$(this).css('position','relative');
				$(this).css('left','0px');
				$(this).css('top','-195px');
			}				
			if(counter > (pageSize * 3 ) && counter < (pageSize * 4 ) + 1)
			{
				$(this).css('position','relative');
				$(this).css('left','220px');
				$(this).css('top','-390px');
			}
			counter++;
		});	

	});
	
	counter = 1;
	pageSize = 8;
	$('#producttypesRes ul li').each(function() {

		if(counter > pageSize && counter < (pageSize * 2 ) + 1)
		{
			$(this).css('position','relative');
			$(this).css('left','123px');
			$(this).css('top','-192px');
		}		
		counter++;
	});	
	
	/*ScrollWindow('.resAntifouling', 2, 196);*/
       
    function ScrollWindow(container, pages, pageheight) 
    {
        $(container).data('currentpage', 0);
        $(container).data('pages', pages);
        $(container).data('pageheight', pageheight);
        
        $(container + ' .bluegld').append("<div class='scrollButton up'></div>");
        $(container + ' .bluegld').append("<div class='scrollButton down'></div>");
        $(container + ' .bluegld .down').click(function() {
            
            var pages = $(container).data('pages');
            var pageheight = $(container).data('pageheight');
            var currentpage = $(container).data('currentpage');
            
            if (currentpage < pages - 1) {
                currentpage++;
                $(container).data('currentpage', currentpage);
                $(container + ' .bluegld ul').animate({
                    marginTop: (-1 * (currentpage * pageheight)) + "px"
                }, 500);
            }
        });
        $(container + ' .up').click(function() {
            var pages = $(container).data('pages');
            var pageheight = $(container).data('pageheight');
            var currentpage = $(container).data('currentpage');
            
            if (currentpage > 0) {
                currentpage--;
                $(container).data('currentpage', currentpage);
                $(container + ' .bluegld ul').animate({
                    marginTop: (-1 * (currentpage * pageheight)) + "px"
                }, 500);
            }
        });
    }

	
	
	
});

	function hideAll(delay, callback)
	{
		var hidden = false
		$('div.bluegld').each(function()
		{
			var display = $(this).css('display');
			if(display == 'block')
			{			
				$(this).css('display', 'none');	
				hidden = true;
			}
		});
		hideMain(delay, callback);		
	}
	
	function hideMain(delay, callback)
	{
		if(!delay)
		{
			delay = 0;
		}
		$('#producttypesRes').animate( { marginRight: "-260px" }, delay, function() { 				
			$('#producttypesRes').css('display', 'none');
			if(document.getElementById('topFiveRes'))
			{			
				$('#topFiveRes').animate( { marginRight: "-260px" }, delay, function() { 
				$('#topFiveRes').css('margin-right', '-260px');				
					$('#topFiveRes').css('display', 'none'); 				
					typesvisible = false;
					expertsvisible = false;		
					if(callback && typeof callback == "function")
						callback();
				});
			}
			else
			{
				typesvisible = false;
				expertsvisible = false;	
				if(callback && typeof callback == "function")
					callback();
			}
		});	
			
		/*$('#producttypesRes').css('margin-right', '-260px');
		$('#producttypesRes').css('display', 'none');
		$('#topFiveRes').css('margin-right', '-260px');
		$('#topFiveRes').css('display', 'none'); 	
		typesvisible = false;
		expertsvisible = false;
				if(callback && typeof callback == "function")
					callback();*/
			
	}	
