/*!
 #####################################################################
 # 
 # Factor 3
 # JavaScript setup routines
 #
 # Hand-crafted by Phenotype (phenotype.net)
 #
 #####################################################################
 */
	
	/* =Assign setup routines
	------------------------------------------------------------------- */
	
		// Called when DOM is ready
		$(document).ready( domSetup );
		
		// Called when entire page is loaded
		$(window).load( pageSetup );
		
		// Called when DOM is unloaded
		$(window).unload( domUnload );
	
	/* =Global variables
	------------------------------------------------------------------- */
	
		// Set site root
		//var siteRoot = '/static/factor3/';
		var siteRoot = '/';
	
	/* =Declare setup routines
	------------------------------------------------------------------- */
	
	/**
	 * domSetup()
	 *
	 * All JavaScript requiring initialisation on DOM LOAD should be called
	 * from this routine.
	 */
	function domSetup() {
		
		/* $("ul.sf-menu").supersubs({ 
            minWidth:    10,   // 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}); 
		*/
		$("ul.sf-menu").supersubs({ 
            minWidth:    10,   // 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,
			  dropShadows:   true,
			  //pathClass:  'current', 
			  sensitivity: 4,
			  animation:     {height:'show'}
			  });


			$('#gallery').cycle({ 
				timeout: 5000, 
				speed:   900,
			});

			$('#hp-gal').cycle({ 
				timeout: 5000,
				sync: 1,
				speed:   900,
				fx: 'fade'
			});
			$('#banner').sprite({fps: 0.5, no_of_frames: 3,start: function() {
        // Fade sprite to 70% opacity when at the start of the drag
        $('#banner').fadeTo('slow', 0);
    },
    stop: function() {
        // Return sprite to 100% opacity when finished
        $('#banner').fadeTo('slow', 1);
    }});


		/* =Enhancements
		------------------------------------------------------------------- */
		
			/**
			 * Multi-column content
			 * Uses <hr /> as separator
			*/
			$('article hr').each(function(){
				
				// Add class to parent
				$(this).parents('article').addClass('multi-column');
				
				// Find siblings before separator
				var before = $(this).prevAll().length;
				// Wrap with column
				$(this).siblings().slice( 0, before ).wrapAll('<div class="column" />');
				
				// Find siblings after separator
				var after = $(this).prevAll().length;
				// Wrap with column
				$(this).siblings().slice( after ).wrapAll('<div class="column last" />');
				
				// Remove separator
				$(this).remove();
	
			});
			
			
			/**
			 * Slideshows
			 */
			 
			/* Clients list slideshow 
			$('.scrollable .scroll-container')
			.parents('.scrollable').append('<a class="cycle previous">Previous</a> <a class="cycle next">Next</a>')
			.scrollable({
				items		:	'.clients-list',
				circular	: 	true,
				mousewheel	:	true,
				speed		:	300,
				easing		:	'easeInSine',
				next		:	'.scrollable .next',
				prev		:	'.scrollable .previous'
			});
			*/
			//$(".scrollable").scrollable();
			
			//$(".scrollable").scrollable({circular: true, mousewheel: true, easing: "swing"}).navigator();//.autoscroll({interval: 6000	});


			

		/* =Navigation
		------------------------------------------------------------------- */
			
			/*
			Setup external links (target attribute not allowed by XHTML 1.1)
			(see http://www.sitepoint.com/article/standards-compliant-world/)
			*/
			$('a[rel="external"]').attr('target','blank');
			
		/* =Animation
		------------------------------------------------------------------- */
		

		$("#email, #fname").focus(function(){
			if ($(this).attr("value") == "Name here..." || $(this).attr("value") == "Email address here..."){
				$(this).val("");
			};
		});
		
		$("#email").blur(function(){
			if ($("#email").attr("value") == "" ){
				$("#email").val("Email address here...");
			};
		});
		
		$("#fname").blur(function(){
			if ($("#fname").attr("value") == "" ){
				$("#fname").val("Name here...");
			};
		});
	
	}
	
	/**
	 * pageSetup()
	 *
	 * All JavaScript requiring initialisation on PAGE LOAD should be called
	 * from this routine (all images and elements should be loaded and ready to
	 * manipulate by this point)
	 */
	function pageSetup() {
		
		

	}
	
	/**
	 * domUnload()
	 *
	 * Called when page/DOM is unloaded
	 */
	function domUnload() {

	}

/*
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();
			
			//alert("/shop/ajax/check_stock.php?id="+id+"&attr1="+attr1+"&attr2="+attr2);
			$.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 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 stock_enquiry(id){
  // open a welcome message
  	var opt1 = ($("#attr1").val());
	var opt2 = ($("#attr2").val());
    Shadowbox.open({
        player:     'iframe',
        title:      'Email me when this product is available',
        content:    '/shop/ajax/stock_enquiry.php?id='+id+'&opt1='+opt1+'&opt2='+opt2,
        height:     350,
        width:      600
    });
}
