$(document).ready(function(){

$("div#navigation ul li#dropdown_nav").hover(

  function () {
  
	
	if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version <= 7){
	$("ul", this).css("left", "0");
	}
  
	$("a", this).addClass("hover");
    $("ul", this).slideDown("fast");

  }, 
  function () {
	$("a", this).removeClass("hover");
    $("ul", this).slideUp("fast");
  }

);

// colour options

$("#colour_options a").click(function(){

$("#colour_options a").removeClass("active");
$(this).addClass("active");
var image_name = '/images/'+$(this).attr("rel")+'.png';
$("#prod_container img").attr("src", image_name);

});


});

function findPos(obj) {
	var curleft = curtop = 0;

	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;

		} while (obj = obj.offsetParent);
	}

	return [curleft,curtop];
}

// browser detect

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function display_none(div){
document.getElementById(div).style.display = "none";
}

function load_mum_popup(which_popup){

box = document.getElementById('MUM_popup');
var divWidth = '375';
var divHeight = '460';

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);
	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.top = scrollingTop+'px';
	box.style.left = scrollingLeft+'px';

	if(which_popup == 'before'){
	document.getElementById('MUM_popup_content').innerHTML = '<img src="/images/MUM_before.jpg" alt="" /><p>Before the make up mode has been applied.</p>';
	}

	else{
	document.getElementById('MUM_popup_content').innerHTML = '<img src="/images/MUM_after.jpg" alt="" /><p>After the make up mode has been applied.</p>';
	}
	
	document.getElementById('MUM_popup').style.display = 'block';
	
}

function load_gallery_item(before_img, after_img){

box = document.getElementById('gallery_popup_container');
var divWidth = '374';
var divHeight = '300';

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);
	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.top = scrollingTop+'px';
	box.style.left = scrollingLeft+'px';
	
	if(before_img.length > 0 && after_img.length > 0){
	document.getElementById('gallery_popup_content').innerHTML = '<div id="gallery_popup_content_left"><img src="/images/gallery/large/'+before_img+'" alt="" width="138" /><p>Before</p></div><div id="gallery_popup_content_right"><img src="/images/gallery/large/'+after_img+'" alt="" width="138" /><p>After</p></div>';
	}
	
	else{
	
		if(before_img.length > 0){
		document.getElementById('gallery_popup_content').innerHTML = '<p style="padding-bottom: 5px;"><img src="/images/gallery/large/'+before_img+'" alt="" width="138" /></p>';
		}
		else{
		document.getElementById('gallery_popup_content').innerHTML = '<p style="padding-bottom: 5px;"><img src="/images/gallery/large/'+after_img+'" alt="" width="138" /></p>';
		}
	}

document.getElementById('gallery_popup_container').style.display = 'block';

}

function store_locator_popup()
{

var divWidth = 375;
var divHeight = 300;
var divID = 'MUM_popup';
var content = '<div id="MUM_popup_top"><a onclick="display_none(\'MUM_popup\');"><img src="/images/close_button.png" alt="Close" title="Close" /></a></div><div id="MUM_popup_content"><h2>Store locator</h2><p style="text-align: left; color: #000000; font-weight: normal;">Please enter your postcode below to find your local stockist.</p><form method="get" action="/store-locator.php"><label for="store_locator_postcode">Postcode</label><input type="text" name="postcode" id="store_locator_postcode" style="float: left; width: 80px;" /><input type="image" src="/images/submit_button.png" alt="Submit" style="float: left; clear: left; margin-top: 10px;" /></form></div><div id="MUM_popup_bottom"></div>';
var box;

if(document.getElementById(divID)){
box = document.getElementById(divID);
}

else{
box = document.createElement("div");
box.setAttribute("id",divID);
document.body.appendChild(box);
}

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);

	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.width = divWidth+'px';
	box.innerHTML = content;
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.top = scrollingTop+'px';

	box.style.left = scrollingLeft+'px';
	box.style.zIndex = '11';
	
	document.getElementById('store_locator_postcode').focus();

}

function newsletter_popup()
{

var divWidth = 375;
var divHeight = 300;
var divID = 'MUM_popup';
var content = '<div id="MUM_popup_top"><a onclick="display_none(\'MUM_popup\');"><img src="/images/close_button.png" alt="Close" title="Close" /></a></div><div id="MUM_popup_content"><h2>Newsletter</h2><p style="text-align: left; color: #000000; font-weight: normal; padding-bottom: 10px;">Please enter your name and email below to subscribe to our newsletter.</p><label for="newsletter_name">Name</label><input type="text" name="name" id="newsletter_name" style="float: left; width: 150px;" /><label for="newsletter_email" style="clear: left; margin-top: 10px;">Email</label><input type="text" name="email" id="newsletter_email" style="float: left; width: 150px; margin-top: 10px;" /><a onclick="newsletter_signup();" style="float: left; clear: left; margin-top: 10px; cursor: pointer;"><img src="/images/submit_button.png" alt="Submit" /></a></div><div id="MUM_popup_bottom"></div>';
var box;

if(document.getElementById(divID)){
box = document.getElementById(divID);
}

else{
box = document.createElement("div");
box.setAttribute("id",divID);
document.body.appendChild(box);
}

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);

	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.width = divWidth+'px';
	box.innerHTML = content;
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.top = scrollingTop+'px';

	box.style.left = scrollingLeft+'px';
	box.style.zIndex = '11';
	
	document.getElementById('newsletter_name').focus();

}

function terms_popup()
{

var divWidth = 375;
var divHeight = 400;
var divID = 'MUM_popup';
var content = '<div id="MUM_popup_top"><a onclick="display_none(\'MUM_popup\');"><img src="/images/close_button.png" alt="Close" title="Close" /></a></div><div id="MUM_popup_content"><h2>Terms &amp; Conditions</h2>'
+ '<div style="float: left; width: 315px; overflow: auto; height: 300px; text-align: left; margin-top: 10px;">'
+ '<ol style="font-size: 0.75em;">'
+ '<li>This  competition closes at 11.59pm  on 31st March 2011</li>'
+ '<li>The  promotion is open to residents of the  U.K.  and Ireland  aged 18 and over.</li>'
+ '<li>The promotion is not open to employees of Casio Electronics Co.  Limited, their agencies or anyone else connected with the creation or  administration of the promotion.</li>'
+ '<li>Only one entry is allowed per person, no bulk or third party entries.</li>'
+ '<li>No responsibility is taken for entries lost, delayed, misdirected  or incomplete due to server functions, virus, bugs or any other causes outside  Casio’s control. Proof of entry is not proof of receipt.</li>'
+ '<Li>The prize is non-exchangeable, non-transferable, and is not  redeemable for cash or other prizes. Casio retains the right to substitute the  prize with another prize of similar value in the event the original prize  offered is not available due to circumstances beyond its reasonable control.</li>'
+ '<li>The winners will be notified within fourteen days of the closing date. The winners are  required to accept the prize within fourteen days of notification. In the  event of non-acceptance, Casio will re-draw and select a new winner (the same  acceptance period will apply for the new winner).</li>'
+ '<li>Winners may be required to take part in promotional activity.</li>'
+ '<li>Casio cannot accept any responsibility for any damage, loss,  injury or disappointment suffered by any entrant as a result of entering the  promotion or accepting the prize or any injury or damage to the entrant\'s or  any other person\'s computer or mobile telephone relating to or resulting from  participation in or downloading any materials in connection with the  promotion.</li>'
+ '<li>The promotion will be governed by English law.</li>'
+ '<li>The  promoter: Casio Electronics Co. Limited. Unit 6,  1000 North  Circular Road,  London,  NW2  7JD.</li>'
+ '<li>Casio reserves the right to make changes to products at any time  and without notice. E&OE..</li>'
+ '<li>There is no legal recourse. Casio\'s decision is final.</li>'
+ '<li>Only one prize per person.</li>'
+ '</ol>'
+ '</div>'
+ '</div><div id="MUM_popup_bottom"></div>';
var box;

if(document.getElementById(divID)){
box = document.getElementById(divID);
}

else{
box = document.createElement("div");
box.setAttribute("id",divID);
document.body.appendChild(box);
}

	var scrollingLeft = Math.round((document.documentElement.clientWidth/2)-(box.style.width/2)) - (divWidth / 2);

	var scrollingTop = Math.round((document.documentElement.clientHeight/2)-(box.style.height/2)+document.documentElement.scrollTop) - (divHeight / 2);

	box.style.width = divWidth+'px';
	box.innerHTML = content;
	box.style.display = 'block';
	box.style.position = 'absolute';
	box.style.top = scrollingTop+'px';

	box.style.left = scrollingLeft+'px';
	box.style.zIndex = '11';
	
}

function ajaxFunction(div, string)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.getElementById(div).innerHTML = xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET",string,true);
  xmlHttp.send(null);
  }
  
// newsletter

function newsletter_signup(){

var u_name = document.getElementById('newsletter_name').value;
var u_email = document.getElementById('newsletter_email').value;

ajaxFunction('MUM_popup_content', '/functions/ajax_newsletter.php?name='+u_name+'&email='+u_email);

}
