window.onload = pageSetup;
// JavaScript Document
$(document).ready(function(){
		$(document).pngFix();
		$('#product_leftshell').easyTabs({ updateHash: false, animationSpeed:500 });
		
		 $("ul.sf-menu").supersubs({ 
            minWidth:    12,   // minimum width of sub-menus in em units 
            maxWidth:    30,   // maximum width of sub-menus in em units 
            extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                               // due to slight rounding differences and font-family 
        }).superfish({autoArrows:false});  // call supersubs first, then superfish, so that subs are 
                         
		$('#salvo').mouseleave(function(){
			$('#salvo').slideUp();
		});
}); 

	
function pageSetup() {
	
		// Resize page background
		$('#background img').fullbleed({
			minSize: .5
		});
	
	} // End pageSetup()

$(function(){
			$("#ratings").children().not("select").hide();

			// Create target element for onHover titles
			$caption = $("<span/>");
			// Make it available in DOM tree
			$caption.appendTo("#ratings");
		});

function reveal(id){
	$('#'+id).slideDown();
	//return false;
}
function unreveal(id){
	$('#'+id).slideUp();
	//return false;
}

function switch_view(id){
	var view = $("#view_proposed").html();
	if(view == "View Proposed") {
		$("#ok"+id).css("display","none");
		$("#proposed"+id).css("display","block");
		$("#view_proposed").html("View Live");
	} else {
		$("#ok"+id).css("display","block");
		$("#proposed"+id).css("display","none");
		$("#view_proposed").html("View Proposed");
	}
}

function dotree(){
	$("#tree").treeview({
			collapsed: true,
			animated: "medium"
			//control:"#sidetreecontrol",
			//persist: "cookie"
			//unique: true
		});
}	

function switchcats2(catid,dobg){
	$(".currentcat2").animate({"left":"-=596"},800,function(){
		$(".currentcat2").remove();
		});
	$(".new2").load("/ajax/cats2.php?pcid="+catid+"&ajax=true",function(){
		$(".new2").animate({"left":"-=596"},800,function(){
			$(".new2").removeClass("new2").addClass("currentcat2");
			$('.catholder').append('<div class=new2></div>');
			//$('.back').remove();
			if ($('.back').length == 0){
				$("#contentshell_middle").append("<div class='back'>< <a href='' onclick='return switchback()'>Back</a></div>");
			}
			if(dobg == 1){
				
				$('#background').load("/ajax/shop_bg.php?catid="+catid,function(){
					$('#background').fadeOut('fast');								
					$('#background').fadeIn('slow');		
					pageSetup();
				});
			}
		});
	});
	$('#breadcrumb').load("/ajax/shop_breadcrumb.php?catid="+catid);
	
	return false;
}

function switchproduct(prodid,catid){
	$(".currentcat2").animate({"left":"-=596"},800,function(){
		$(".currentcat2").remove();
	});
	$(".new2").load("/ajax/product.php?id="+prodid+"&catid="+catid+"&ajax=true",function(){
		$(".new2").animate({"left":"-=596"},800,function(){
			$(".new2").removeClass("new2").addClass("currentcat2");
			$('.catholder').append('<div class=new2></div>');
		});
	});
	$('#breadcrumb').load("/ajax/shop_breadcrumb.php?catid="+catid+"&id="+prodid);
	return false;
}

function switchback(){
	$(".currentcat2").animate({"left":"+=596"},800,function(){
		$(".currentcat2").remove();
		});
	var pcid=parseInt($("#pcid").attr("value"));
	$(".old").load("/ajax/cats2.php?pcid="+pcid+"&ajax=true",function(){
		$(".old").animate({"left":"+=596"},800,function(){
			$(".old").removeClass("old").addClass("currentcat2");
			$('.catholder').append('<div class=old></div>');
		});
	}
	);
	if (pcid==0){
		$(".back").remove();
	}
	$('#breadcrumb').load("/ajax/shop_breadcrumb.php?catid="+pcid);
	return false;
}

function edit_node(nid,action){
	$('#nodes').html("");
	$('#nodes').load("nodes.php?nid="+nid+"&mode="+action,function(){
																	
	 });
}

function show_msg(msg){
		$('#show_msg').html(msg);
		$('#show_msg').slideDown();
}

function toggleP(me,target) {
	$("#"+me).hide();	
	$("#"+target).fadeIn("slow");	
}

function show_approval(){
	$("#approval").load("/admin/approval_list.php").slideDown();
	//$("#approval").;
}

function show_reject(id){
	$("#"+id).slideDown();
	//$("#approval").;
}

function edit_form(fid,action,id){
	$('#nodes').html("");
	$('#nodes').load("forms.php?fid="+fid+"&mode="+action+"&frmid="+id,function(){															
	 });
}


function select_options(id){
		
				
			$("#outofstock").hide();
			$("#instock").hide();
			$("#cartbutton").hide();
			$("#showprice").html("Fetching data...");
			$("#showprice").show();
			$("#option2").hide();
			var opt1 = $("input[name='attr1']").val();
			$.ajax({
				method: "get",url: "/ajax/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").slideDown('fast');
					//$("#cartbutton").show();
				 }
			 }); //close $.ajax(
	
 } 
 

function check_stock(id){
		
			$("#outofstock").hide();
			$("#instock").hide();
			$("#cartbutton").hide();
			$("#showprice").html("Fetching data...");
			$("#showprice").show();
			//var attr1 = ($("input[name='attr1']:checked").val());	
			//var attr2 = ($("input[name='attr2']:checked").val());	
			var attr1 = $('#attr1').val();	
			var attr2 = $('#attr2').val();
			$.ajax({
				method: "get",url: "/ajax/check_stock.php",data: "id="+id+"&attr1="+attr1+"&attr2="+attr2,
				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("Item Price: &pound;"+html.substr(2,html.length)); //show the html inside .content div
						$("#showprice").slideDown();
						$("#instock").slideDown();
						$("#cartbutton").slideDown();
					} else {
						$("#showprice").hide();
						$("#outofstock").slideDown();
					}
				 }
			 }); //close $.ajax(
	
 } 

function stock_enquiry(id){
  // open a welcome message
  	var opt1 = ($("#attr1").val());	
	var opt2 = ($("#size").val());	
    Shadowbox.open({
        player:     'iframe',
        title:      'Email me when this product is available',
        content:    '/ajax/stock_enquiry.php?id='+id+'&opt1='+opt1+'&opt2='+opt2,
        height:     350,
        width:      600
    });
}

function price_match(id){
  // open a welcome message
  	var opt1 = ($("#attr1").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 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);
}

function edit_project(fid,action,id,table){
	$('#nodes').html("");
	$('#nodes').load("/admin/"+table+".php?fid="+fid+"&mode="+action+"&id="+id,function(){
																	
	 });
}
$(function() {
	$('#productpics').cycle({
		timeout: 5000, 
		speed:   500,
		startingSlide: 0
	});
		pause:1
	$('#goto1').click(function() { 
		$('#productpics').cycle(0); 
		return false; 
	});
	$('#goto2').click(function() { 
		$('#productpics').cycle(1); 
		return false; 
	});
	$('#goto3').click(function() { 
		$('#productpics').cycle(2); 
		return false; 
	});
	$('#goto4').click(function() { 
		$('#productpics').cycle(3); 
		return false; 
	});
	$('#goto5').click(function() { 
		$('#productpics').cycle(4); 
		return false; 
	});
	$('#goto6').click(function() { 
		$('#productpics').cycle(5); 
		return false; 
	});
	$('#goto7').click(function() { 
		$('#productpics').cycle(6); 
		return false; 
	});
	$('#goto8').click(function() { 
		$('#productpics').cycle(7); 
		return false; 
	});
	$('#goto9').click(function() { 
		$('#productpics').cycle(8); 
		return false; 
	});

});
function initialize() {
  var myLatlng = new google.maps.LatLng(51.963361,-1.956339);
  var myOptions = {
	zoom: 14,
	center: myLatlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  var image = 'images/logo_small.png';
  var myLatLng = new google.maps.LatLng(51.962900,-1.956450);
  var beachMarker = new google.maps.Marker({
	  position: myLatLng,
	  map: map,
	  icon: image
  });
}

