//Scripts used on Home Page
function hideBackground() {
    var splash = document.getElementById("splashWrapper");
    splash.style.background = "transparent";
}
function closeFlash() {
    var splash = document.getElementById("splashWrapper");
    splash.innerHTML = "";
    splash.style.width = "0";
    splash.style.height = "0";
    splash.style.visibility = "hidden";
    splash.style.display = "none";
}




// Script used on Collection detail pages
function swapProducts(prodID, prodCount) {
    var i;
    for (i=1;i<=prodCount;i++)
    {
        var divI = document.getElementById('prod' + i + 'Lg');
        //alert(divI.innerHTML);
        divI.style.display = "none";
        divI.style.visibility = "hidden";
    }
    //var div1 = document.getElementById('prod1Lg');
    //var div2 = document.getElementById('prod2Lg');
    //var div3 = document.getElementById('prod3Lg');
    //var div4 = document.getElementById('prod4Lg');
    //div1.style.display = div2.style.display = div3.style.display = div4.style.display = "none";
    //div1.style.visibility = div2.style.visibility = div3.style.visibility = div4.style.visibility = "hidden";
    var divChange = document.getElementById('prod' + prodID + 'Lg');
    divChange.style.display = "block";
    divChange.style.visibility = "visible";
}


//loads jQuery from Google server
google.load("jquery", "1");
google.load("jqueryui", "1");
	
// Image slider moduale for collection image links 
var ImageSlider = {};
ImageSlider.setup = function() 
{
 //Get our elements for faster access and set overlay width
	var div = jQuery('div.sc_menu'),
		ul = jQuery('ul.sc_menu'),
		ulPadding = 15 + (ul.children().length /2); //10;
	
	//Get menu width
	var divWidth = div.width();

	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	
	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + (ulPadding * 4);
		var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth;
		div.scrollLeft(left);
	});

};
// Image slider moduale for collection image links 
var ImageSlider2 = {};
ImageSlider2.setup = function() {
    //Get our elements for faster access and set overlay width
    var div = jQuery('div.sc_menu2'),
		ul = jQuery('ul.sc_menu'),
		ulPadding = 15 + (ul.children().length / 2); //10;

    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars	
    div.css({ overflow: 'hidden' });

    //Find last image container
    var lastLi = ul.find('li:last-child');

    //When user move mouse over menu
    div.mousemove(function(e) {
        //As images are loaded ul width increases,
        //so we recalculate it each time
        var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
        var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth;
        div.scrollLeft(left);
    });

};


//Creates smooth scrolling for jump links
var smoothJumplinks = {};
smoothJumplinks.setup = function ()
{
	jQuery("ul.smooth-links a").click(function () {	
		elementClick = jQuery(this).attr("href")
		destination = jQuery(elementClick).offset().top;
		jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 30 );
		return false;
	})
	
	jQuery("a.smooth-links").click(function () {	
		elementClick = jQuery(this).attr("href")
		destination = jQuery(elementClick).offset().top;
		jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 30 );
		return false;
	})
	
};

//Creates modal window for login screen
var loginWindow = {};
loginWindow.setup = function ()
{
//select all the a tag with name equal to modal
	jQuery('a#login').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = jQuery(this).attr('href');
	
		//Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		//Set height and width to mask to fill up the whole screen
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		jQuery('#mask').fadeIn(500);	
		jQuery('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		//transition effect
		jQuery(id).fadeIn(1000); 
	
	});
	jQuery('a#signin').click(function(e) {
	    //Cancel the link behavior
	    e.preventDefault();
	    //Get the A tag
	    var id = jQuery(this).attr('href');

	    //Get the screen height and width
	    var maskHeight = jQuery(document).height();
	    var maskWidth = jQuery(window).width();

	    //Set height and width to mask to fill up the whole screen
	    jQuery('#mask').css({ 'width': maskWidth, 'height': maskHeight });

	    //transition effect		
	    jQuery('#mask').fadeIn(500);
	    jQuery('#mask').fadeTo("slow", 0.8);

	    //Get the window height and width
	    var winH = jQuery(window).height();
	    var winW = jQuery(window).width();

	    //Set the popup window to center
	    jQuery(id).css('top', winH / 2 - jQuery(id).height() / 2);
	    jQuery(id).css('left', winW / 2 - jQuery(id).width() / 2);

	    //transition effect
	    jQuery(id).fadeIn(1000);

	});
	
	//if close button is clicked
	jQuery('.window a#close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		jQuery('#mask, .window').hide();
	});		
	
	//if mask is clicked
	jQuery('#mask').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
	});	


};






// Loads main functions
google.setOnLoadCallback(function(){
								  
	ImageSlider.setup();
	smoothJumplinks.setup();
	loginWindow.setup();
	
	// Initiates Smooth Menu nav system
	ddsmoothmenu.init({
		mainmenuid: "smoothmenu1", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		//customtheme: ["#1c5a80", "#18374a"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	})


	
	
});
