Shadowbox.loadSkin('classic', 'js/skin'); // use the "classic" skin
window.onload = Shadowbox.init;

$(document).ready(function(){ 
	$("ul.sf-menu").superfish({ 
		animation: {height:'show'},   // slide-down effect without fade-in 
		delay:     1200               // 1.2 second delay on mouseout 
	}); 
}); 

function select_options(id){
		
				
			$("#outofstock").hide();
			$("#instock").hide();
			$("#cartbutton").hide();
			$("#showprice").html("Fetching data...");
			$("#showprice").show();
			$("#option2").hide();
			var opt1 = $("colour").val();
			$.ajax({
				method: "get",url: "get_options.php",data: "id="+id,
				success: function(html){ //so, if data is retrieved, store it in html
					$("#showprice").hide();
					$("#option2").html(html); //show the html inside .content div
					$("#option2").show('fast');
					//$("#cartbutton").show();
				 }
			 }); //close $.ajax(
	
 } 
 

function check_stock(id){
		
			$("#outofstock").hide();
			$("#instock").hide();
			$("#cartbutton").hide();
			$("#showprice").html("Fetching data...");
			$("#showprice").show();
			var opt1 = ($("#colour").val());	
			var opt2 = ($("#size").val());	
			$.ajax({
				method: "get",url: "check_stock.php",data: "id="+id+"&opt1="+opt1+"&opt2="+opt2,
				success: function(html){ //so, if data is retrieved, store it in html
					//$("#instockans").html(html);
					if(html.substring(0,1) == '1'){
						$("#showprice").hide();
						$("#showprice").html("Total Price = &pound;"+html.substr(2,html.length)); //show the html inside .content div
						$("#showprice").show("slow");
						$("#instock").show("slow");
						$("#cartbutton").show("slow");
					} else {
						$("#showprice").hide();
						$("#outofstock").show("slow");
					}
				 }
			 }); //close $.ajax(
	
 } 

function stock_enquiry(id){
  // open a welcome message
  	var opt1 = ($("#colour").val());	
	var opt2 = ($("#size").val());	
    Shadowbox.open({
        player:     'iframe',
        title:      'Email me when this product is available',
        content:    'stock_enquiry.php?id='+id+'&opt1='+opt1+'&opt2='+opt2,
        height:     350,
        width:      600
    });
}

function price_match(id){
  // open a welcome message
  	var opt1 = ($("#colour").val());	
	var opt2 = ($("#size").val());	
    Shadowbox.open({
        player:     'iframe',
        title:      'Price Match',
        content:    'price_match.php?id='+id+'&opt1='+opt1+'&opt2='+opt2,
        height:     450,
        width:      600
    });
}

function subscribe(){
		
	var ok = "";
	var email = $("#subscribe_email").val();
	var fname = $("#subscribe_fname").val();
	var sname = $("#subscribe_sname").val();
	var source = $("#subscribe_source").val();
	var pid = $("#subscribe_pid").val();
	ok += email == "" ? "<li>email address</li>" : "";
	ok += !isEmail2(email) ? "<li>email format</li>" : "";
	ok += fname == "" ? "<li>firstname</li>" : "";
	ok += sname == "" ? "<li>surname</li>" : "";
	
	if(ok.length == 0){
		$.ajax({
			method: "get",url: "subscribe.php",data: "email="+escape(email)+"&fname="+escape(fname)+"&sname="+escape(sname)+"&source="+escape(source)+"&pid="+escape(pid),
			success: function(html){ //so, if data is retrieved, store it in html
				$("#keepintouch").html("Thank you for subscribing"); //show the html inside .content div
				return false;
			 }
		 }); //close $.ajax(
	} else {
		$("#sub_warning").html("Please complete your<ul>"+ok+"</ul>");
		$("#sub_warning").show("slow");
	}
	return false;
 } 
 
function isEmail2(who) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(who));
}

// JavaScript Document
/*function toggleP(me,target) {
	$("#"+me).hide();	
	$("#"+target).fadeIn("slow");	
}
$(function() {
	$('.pics').cycle({
		timeout: 10000 ,	
		delay:  1000, 
		speed:  2000
		
	});
}); 
*/

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header
if (parent.frames.length > 0) {
	    parent.location.href = self.document.location
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function use_billing(){
	document.form['delfirstName'].value = document.form['firstName'].value;
	document.form['dellastName'].value = document.form['lastName'].value;
	document.form['deladdress1'].value = document.form['address1'].value;
	document.form['deladdress2'].value = document.form['address2'].value;
	document.form['deltown'].value = document.form['town'].value;
	document.form['delcounty'].value = document.form['county'].value;
	document.form['delpostCode'].value = document.form['postCode'].value;
	document.form['delcountry'].value = document.form['country'].value;
	$("#delcountry").html(document.form['country'].value);
}
