/* ===========================================================================
 * 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()
{	
	initLinks();
	initBackgroundImage();
	
	// 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;
 	}
}



function initLinks()
{
	if (!document.getElementsByTagName) 
 		return;
 		

 	if(document.body.className.match("new-window"))
 	{
	 	is_popup=true;
 		window.focus();
	}
 
 	var anchors = document.getElementsByTagName("a");
 	for (var i=0; i<anchors.length; i++) 
 	{
   		var anchor = anchors[i];
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
   		{
     		anchor.target = "_blank";
 		}	
     	else if (anchor.className.match("print")) 
     	{
        	anchor.onclick = function() 
        	{
          		printPage();
          		return false;
        	};
    	}
    	else if (anchor.className.match("new-window")) 
     	{
        	anchor.onclick = function() 
        	{
          		popUp(this.getAttribute("href"));
          		return false;
        	};
    	}
    	else if (anchor.className.match("file")) 
     	{
        	anchor.onclick = function() 
        	{
          		window.open(this.getAttribute("href"));
          		return false;
        	};
    	}
    	else if (anchor.className.match("close")) 
     	{
	     	anchor.style.display = 'inline';
	     	anchor.style.visibility = 'visible';
        	anchor.onclick = function() 
        	{
          		window.close();
          		return false;
        	};
    	}
 	}
}


function popUp(URL)
{
	eval("window.open('" + URL + "','windowName', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=600,height=600');");
}

/* Author: Rebecca Skeers rebecca@webmistress.com.au 2005 */
function printPage() 
{
  	if (window.print)
		window.print()
	else
		alert("Sorry, your browser doesn't support the print feature. Use the File menu on your browser to select Print.");
	return false;
}


