var totalImages = 30; // Total images used

browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);

ns3up = (browserName == "Netscape" && browserVer >= 3);
ie4up = (browserName.indexOf("Microsoft") >= 0 && browserVer >= 4);

function showPic(imgName) 
{
	if (ns3up || ie4up) 
		imgOn = ("images/nav/" + imgName);
		
	document.mainpic.src = imgOn;
}

if(document.images)
{
	mFX = new Array(totalImages);
	for(i = 0; i < mFX.length; i++)
	{
		mFX[i] = new Image();
	}
	// Top Navigation
	mFX[0].src = "images/nav/home.gif";
	mFX[1].src = "images/nav/home-on.gif";
	mFX[2].src = "images/nav/about.gif";
	mFX[3].src = "images/nav/about-on.gif";
	mFX[4].src = "images/nav/bedrooms.gif";
	mFX[5].src = "images/nav/bedrooms-on.gif";
	mFX[6].src = "images/nav/accessories.gif";
	mFX[7].src = "images/nav/accessories-on.gif";
	mFX[8].src = "images/nav/faq.gif";
	mFX[9].src = "images/nav/faq-on.gif";
	mFX[10].src = "images/nav/testimonials.gif";
	mFX[11].src = "images/nav/testimonials-on.gif";
	mFX[12].src = "images/nav/contact.gif";
	mFX[13].src = "images/nav/contact-on.gif";
	// Bedrooms
	mFX[14].src = "images/pic-african-on.jpg";
	mFX[15].src = "images/pic-african-over.jpg";
	mFX[16].src = "images/pic-venetian-on.jpg";
	mFX[17].src = "images/pic-venetian-over.jpg";
	mFX[18].src = "images/pic-orange-on.jpg";
	mFX[19].src = "images/pic-orange-over.jpg";
	mFX[20].src = "images/pic-suede-on.jpg";
	mFX[21].src = "images/pic-suede-over.jpg";
	mFX[22].src = "images/pic-zen-on.jpg";
	mFX[23].src = "images/pic-zen-over.jpg";
	mFX[24].src = "images/pic-tribal-on.jpg";
	mFX[25].src = "images/pic-tribal-over.jpg";
	// Gallery
	mFX[26].src = "images/bedrooms/african/gallery.gif";
	mFX[27].src = "images/bedrooms/african/gallery-over.gif";
	
	mFX[28].src = "images/nav/bed-linen.gif";
	mFX[29].src = "images/nav/bed-linen-on.gif";
}

function imgFX(img, num)
{
	if(document.images)
	{
		document.images[img].src = mFX[num].src;
	}
}

function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function swapMenu(selMenu)
{
	menuItems = new Array( document.getElementById('thumbzero'),
						   document.getElementById('thumbone'), 
						   document.getElementById('thumbtwo'), 
						   document.getElementById('thumbthree'),
						   document.getElementById('thumbfour'),
						   document.getElementById('thumbfive'),
						   document.getElementById('thumbsix'),
						   document.getElementById('thumbseven'),
						   document.getElementById('thumbeight'),
						   document.getElementById('thumbnine')
								 );
	
	for (i = 0; i < menuItems.length; i++)
	{
		if (menuItems[i].style.display == '')
			menuItems[i].style.display='none';
	}
	
	document.getElementById(selMenu).style.display='';
}

function swapHover(selMenu)
{
	menuItems = new Array( document.getElementById('africanhover'),
						   document.getElementById('tribalhover'),
						   document.getElementById('orangehover'),
						   document.getElementById('suedehover'),
						   document.getElementById('zenhover'),
						   document.getElementById('venetianhover'),
						   document.getElementById('swopper')
						  );
	
	for (i = 0; i < menuItems.length; i++)
	{
		if (menuItems[i].style.display == '')
			menuItems[i].style.display='none';
	}
	
	document.getElementById(selMenu).style.display='';
}

function openPopup(prefix, picUrl) 
{
	window.open(prefix+"popup.php?"+picUrl, "poppis", "resizable=1,HEIGHT=400,WIDTH=400,Left=20%,Top=20%");
}

function openSizes(size) 
{
	document.getElementById(size+'sizes').style.display='';
}

function closeSizes(size) 
{
	document.getElementById(size+'sizes').style.display='none';
}

function openPop() {
	document.getElementById('explanation').style.display='';
}

function closePop() {
	document.getElementById('explanation').style.display='none';
}

function validateCheckout() {

	fv =  new formValidator();
	
	if (fv.isEmpty("Ecom_ShipTo_Postal_Name_First"))
		fv.raiseError("Please specify your first name.");
		
	if (fv.isEmpty("Ecom_ShipTo_Postal_Name_Last"))
		fv.raiseError("Please specify your last name.");
		
	if (fv.isEmpty("Ecom_ShipTo_Online_Email"))
		fv.raiseError("Please specify your email address.");
		
	if (fv.isEmpty("Ecom_ShipTo_Online_Email"))
		fv.raiseError("Please confirm your email address.");
		
	if (fv.isEmpty("Ecom_ShipTo_Telecom_Phone_Number"))
		fv.raiseError("Please specify your telephone number.");
		
	if (fv.isEmpty("Ecom_ShipTo_Postal_Street_Line1"))
		fv.raiseError("Please specify your delivery address line 1.");
		
	if (fv.isEmpty("Ecom_ShipTo_Postal_City"))
		fv.raiseError("Please specify your delivery address city.");
		
	if (fv.isEmpty("Ecom_ShipTo_Postal_PostalCode"))
		fv.raiseError("Please specify your delivery address postal code.");

	if (fv.isEmpty("Ecom_Payment_Card_Name"))
		fv.raiseError("Please specify the name of the Card holder.");
		
	if (fv.isEmpty("Ecom_Payment_Card_Number"))
		fv.raiseError("Please specify the Card number.");
		
	if (fv.isEmpty("Ecom_Payment_Card_Verification"))
		fv.raiseError("Please specify the Card CVC numbers.");
		
	if (fv.isEmpty("Ecom_Payment_Card_Type"))
		fv.raiseError("Please specify the Card Type.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;			
}

function validateCheckoutDD() {

	fv =  new formValidator();
	
	if (fv.isEmpty("first_name"))
		fv.raiseError("Please specify your first name.");
		
	if (fv.isEmpty("surname"))
		fv.raiseError("Please specify your surname.");
		
	if (fv.isEmpty("email_address"))
		fv.raiseError("Please specify your email address.");
		
	if (!fv.isEmailAddress("email_address"))
		fv.raiseError("Please specify a valid email address.");
		
	if (fv.isEmpty("telephone"))
		fv.raiseError("Please specify your telephone number.");
		
	if (fv.isEmpty("delivery_address_1"))
		fv.raiseError("Please specify your delivery address line 1.");
		
	if (fv.isEmpty("city"))
		fv.raiseError("Please specify your delivery address city.");
		
	if (fv.isEmpty("postal_code"))
		fv.raiseError("Please specify your delivery address postal code.");

	if (fv.isEmpty("code"))
		fv.raiseError("Please specify the security code.");
		
	if (fv.numErrors() > 0)
	{
		fv.displayErrors();
		return false;
	}
	else
	  return true;			

}

function openDisclaimer() 
{
	window.open("disclaimer.php","", "scrollbars=yes,resizable=1,HEIGHT=350,WIDTH=520");
}

function openPrivacy() 
{
	window.open("privacy.php","", "scrollbars=yes,resizable=1,HEIGHT=350,WIDTH=520");
}

	jQuery(document).ready(function(){

	//Hide (Collapse) the toggle containers on load
	jQuery(".sideBarContents").hide(); 

	//Switch the "Open" and "Close" state per click
	$("a.trigger").toggle(function(){
		jQuery(this).addClass("active");
		}, function () {
		jQuery(this).removeClass("active");
	});
	
	//Slide up and down on click
	$("a.trigger").click(function(){
		jQuery(this).next(".sideBarContents").slideToggle("slow");
	});

});