/* ===========================================================================
 * SCHEDULE THE BEHAVIOURS
 * =========================================================================== 
 */

var basePath="/"; 
var numSolidImages=4;
var numHomeImages=1;
var numRingImages=3;
var numPendantImages=0;
var numEarringImages=1;
var numSoftImages=3;
 
 
/* Google map functions */
$(window).resize(function()
{
	if(typeof loadMap==='function')
		loadMap();
});

$(window).unload(function()
{
	if(typeof GUnload==='function')
		GUnload();
});

$(document).ready(function()
{
	if(typeof loadMap==='function')
		loadMap();
});
 

$(document).ready(function()
{	
	initBackgroundImage();
	
	
	$("a.lightbox").colorbox();
	$("a.new-window").colorbox({width:"640px", height:"480px", iframe:true});
	
	// Drop down menus for IE6
	$("#navigation li").hover(
		function () 
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);
	
	
	
	
	$("p img.image-left").closest("p").css("padding","0");
	$("p img.image-right").closest("p").css("padding","0");
	$("p img.image-left-border").closest("p").css("padding","0");
	$("p img.image-right-border").closest("p").css("padding","0");
	
	
	
	// External links
	$("a[rel='external']").attr("target","_blank");
	
	
	if(!($("#pfirstname").val() || $("#plastname").val() || $("#pemail").val() || $("#pphone").val() || $("#paddress").val() || $("#pcity").val() || $("#pstate").val() || $("#ppostcode").val() || $("#pcountry").val()))
		$("#partner-form").hide();
	
	$("a#partner").click(function () 
	{
		if ($("#partner-form").is(":hidden")) 
		{
			$("#partner-form").slideDown();
			
			$("#paddress").val($("#address").val());
			$("#pcity").val($("#city").val());
			$("#pstate").val($("#state").val());
			$("#ppostcode").val($("#postcode").val());
			$("#pcountry").val($("#country").val());
			
			return false;
		}
		else
		{
			$("#partner-form").slideUp();
			return false;
		}
	});
	
	
});


	

function tidyPage()
{
	var content2 = document.getElementById("content2");
	if(content2)
	{
		var url = location.href;	
		
		if(url.match("/rings/") || url.match("/pendants/") || url.match("/earrings/"))
	 	{ 
		 	var divs = content2.getElementsByTagName("div");
		 	for(var k=0; k<divs.length; k++)
		 	{
			 	if (divs[k].className.match("content-image") || divs[k].className.match("thumbnail"))
			 	{
				 	divs[k].onmouseover=function() 
					{
						if(this.className == "")
							this.className="hover";
						else
							this.className+=" hover";
					}
					
					divs[k].onmouseout=function() 
					{
						this.className=this.className.replace(new RegExp(" hover\\b"), "");
						this.className=this.className.replace(new RegExp("hover\\b"), "");
					}
					
					divs[k].onfocus=function() 
					{
						if(this.className == "")
							this.className="hover";
						else
							this.className+=" hover";
					}
					
					divs[k].onblur=function() 
					{
						this.className=this.className.replace(new RegExp(" hover\\b"), "");
						this.className=this.className.replace(new RegExp("hover\\b"), "");
					}	
					
					divs[k].onclick=function() 
					{
						if(this.className == "")
							this.className="hover";
						else
							this.className+=" hover";
					}
				}
		 	}
		}
	}	
}

function initBackgroundImage()
{
	
	if (!document.getElementsByTagName) 
 		return;
 		
 	var b = document.getElementsByTagName("body");
 	theBody = b[0];
 	
 	if(theBody.id == 'section-home')
 	{
		randomNumber = Math.ceil(Math.random() * numHomeImages);
		if (theBody.className == "")
			theBody.className = "home"+randomNumber;
		else
			theBody.className += " home"+randomNumber;
 	}
 	else if(theBody.id == 'section-about')
 	{
		randomNumber = Math.ceil(Math.random() * numSolidImages);
		if (theBody.className == "")
			theBody.className = "solid"+randomNumber;
		else
			theBody.className += " solid"+randomNumber;
 	}
 	else if(theBody.id == 'section-rings')
 	{
	 	randomNumber = Math.ceil(Math.random() * numRingImages);
		if (theBody.className == "")
			theBody.className = "rings"+randomNumber;
		else
			theBody.className += " rings"+randomNumber;
 	}
 	else if(theBody.id == 'section-pendants')
 	{
	 	randomNumber = Math.ceil(Math.random() * numPendantImages);
		if (theBody.className == "")
			theBody.className = "pendants"+randomNumber;
		else
			theBody.className += " pendants"+randomNumber;
 	}
 	else if(theBody.id == 'section-earrings')
 	{
	 	randomNumber = Math.ceil(Math.random() * numEarringImages);
		if (theBody.className == "")
			theBody.className = "earrings"+randomNumber;
		else
			theBody.className += " earrings"+randomNumber;
 	}
 	else
 	{
	 	randomNumber = Math.ceil(Math.random() * numSoftImages);
		if (theBody.className == "")
			theBody.className = "soft"+randomNumber;
		else
			theBody.className += " soft"+randomNumber;
 	}
}

