
// JavaScript Document
$(document).ready(function(){
						   
		 $("ul.sf-menu").supersubs({ 
            minWidth:    6,   // 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}); 
      
	
		$('#window').cycle({
		timeout: 6000 ,	
		delay:  0, 
		speed:  1500,
		pause:	1,
		autostop: 1,
		autostop: 1
		//next:   '.next', 
		//prev:   '.prev'
		});
		
		$('.pics').cycle({
		timeout: 4000 ,	
		delay:  0, 
		speed: 1000, 
		pause:	1,
		next:   '#next', 
		prev:   '#prev'
		});
	
		$('.banneritems').cycle({
			timeout: 5000,
			delay: 0,
			speed: 1000,
			pause: 1
		});
		
		$('#goto1').click(function() {
			$('#window').cycle(1);
			$('#window').cycle('stop');
			$('.pics2').cycle(0);  
			return false; 
		}); 
		 
		$('#goto2').click(function() {  
			$('#window').cycle(1);
			$('#window').cycle('stop');
			$('.pics2').cycle(1);  
			return false;  
		}); 
		
		$('#goto3').click(function() {  
			$('#window').cycle(1);
			$('#window').cycle('stop');
			$('.pics2').cycle(2);  
			return false;  
		}); 
		
		$('.quotes').cycle({
		timeout: 8000 ,	
		delay:  0, 
		speed:  2000,
		pause:	1,
		random: 1,
		sync:   0,  
		containerResize: 1
	});
		
	$('.reveal').mouseleave(function(){
		//$(this).slideUp();
	}); 
	
	$('.featurebox').hoverIntent( function () {
		var copy = 	$(this).children(".reveal").html();
		$(".midcol2").hide();
		$(".midcol").html("<div class='midbg'><div class='copy'>"+copy+"</div><span class='hpfilterfoot'>&nbsp;</span></div>");
		//$(this).css("position","relative");
		//alert("123123");
	  }, 
	  function () {
		 // $(this).children(".reveal").slideUp();
		 // $(".midcol").html("");
		  //$(this).css("position","absolute");
	  }
	);
	
	$('.welcome').hoverIntent( function () {
		var copy = 	$(this).children(".copy").html();
		$(".midcol2").hide();
		$(".midcol").html("<div class='midbg'><div class='copy'>"+copy+"</div><span class='hpfilterfoot'>&nbsp;</span></div>");
		//$(this).css("position","relative");
		//alert("123123");
	  }, 
	  function () {
		 // $(this).children(".reveal").slideUp();
		 // $(".midcol").html("");
		  //$(this).css("position","absolute");
	  }
	);
	
	$("#hptn1").click(function(e){
		e.preventDefault();
		$(".midcol").html("");
		$(".midcol2").hide();
		$("#tn1").show();
	});
	
	$("#hptn3").click(function(e){
		e.preventDefault();
		$(".midcol").html("");
		$(".midcol2").hide();
		$("#tn3").show();
	});
	
	$("#hptn2").click(function(e){
		e.preventDefault();
		$(".midcol").html("");
		$(".midcol2").hide();
		$("#tn2").show();
	});
	
	$("#hptn4").click(function(e){
		e.preventDefault();
		$(".midcol").html("");
		$(".midcol2").hide();
		$("#tn4").show();
	});
	
	$("#hptn5").click(function(e){
		e.preventDefault();
		$(".midcol").html("");
		$(".midcol2").hide();
		$("#tn5").show();
	});
	
	/*
	$('.cta').hoverIntent( function () {
		$(this).animate({"width":"500"},300);
		$(this).children(".extra").fadeIn();
	  }, 
	  function () {
		 $(this).animate({"width":"210"},300);
		 $(this).children(".extra").fadeOut();
	  }
	);
	*/
	$('.cta').hoverIntent( function () {
		$(this).children(".extra").fadeIn();
	  }, 
	  function () {
		 $(this).children(".extra").fadeOut();
	  }
	);
		
		$(document).pngFix();
		
	$('#loginbox').click(function() {
	  if($(this).val() == "username" || $(this).val() == "password"){			  	
		  $(this).val("");
	  }
	});
		
	$("#translate").hide();
	$(".translate").click(function() {
	  $('#translate').slideToggle();
	 
	});
	
	$("#loginbox").hide();
	$(".loginbox").click(function() {
	  $('#loginbox').slideToggle();
	   return false;
	});

		//dotree();
	$(".copy li").click(function(){
		if($(this).children("ul").css("display") == "none"){
			$(this).parent().siblings("ul").children("li").children("ul").slideUp();
			$(this).siblings().children("ul").slideUp();
			$(this).children("ul").slideDown();
		} else {
			$(this).children("ul").slideUp();
		}
	});	
	


}); 

function showreeal(id){
 $('#reveal'+id).slideDown();
} 

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 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 fbs_click() {
	u=location.href;
	t=document.title;
	window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t),"sharer","toolbar=0,status=0,width=626,height=436");
	return false;
}

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

function check_stock(id){
		
			$("#loading").show();
			$("#outofstock").hide();
			$("#instock").hide();
			$("#cartbutton").hide();
			$("#showprice").html("Fetching data...");
			$("#showprice").show();
			//var attr1 = ($("input[name='attr1']").val());	
			//var attr2 = ($("input[name='attr2']").val());
			var attr1 = $('#attr1').val();	
			var attr2 = $('#attr2').val();
			$.ajax({
				method: "get",url: "../../shop/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'){
						$("#loading").hide();
						$("#showprice").hide();
						$("#showprice").html("Total 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 set_cufon() {
	Cufon.set('fontFamily', 'interstate');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('#nav a');
	Cufon.replace('.title', {
	hover: true });
	Cufon.replace('.topmenu', {
	hover: true });
	Cufon.replace('.pagetitle');
	Cufon.replace('#banner_products_sub_title');
	Cufon.replace('#banner_copy_title');
	Cufon.now();
}
