/*!
 #####################################################################
 # 
 # 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:    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}); 
		*/
		$("ul.sf-menu").superfish({
								  autoArrows:    false,
   								  dropShadows:   true,
								  pathClass:  'current', 
								  sensitivity: 4,
								  animation:     {height:'show'}
								  });


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


		/* =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();
	
			});
			
			$("#artworkimage .image").click(function(){
					var url = $(this).attr("src");
					url = url.replace("uploads\/","uploads\/full");
					Shadowbox.init();
					Shadowbox.open({
						content:    url,
						player:     "img"
					});					
			});
			
			/**
			 * 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();
			
			function moveItems(){
				$(".scrollable").scrollable({circular: false, mousewheel: true, easing: "swing", disabledClass: 'disabled', speed: 0}).navigator();//.autoscroll({interval: 6000	});
				var api = $(".scrollable").data("scrollable");
				var listItem = document.getElementById('active');
				api.move( Math.ceil( ( $('.gal_thumb').index( listItem ) + 1 ) / 5 ) - 1 );
				$('#cover').fadeOut(100);
			}
			
			if ( $(".scrollable").length ){
				moveItems();
				var numItems = $('.gal_thumb').length;
				if ( numItems < 6 ){
					$('.browse').addClass('disabled');
				};
			}
			
			/* Project slideshows */
			$('.slideshow .slides-container')
			.parents('.slideshow').append('<a class="cycle previous">Previous</a> <a class="cycle next">Next</a>')
			.scrollable({
				items		:	'.slides',
				circular	: 	true,
				mousewheel	:	true,
				speed		:	600,
				easing		:	'easeInSine',
				next		:	'.slideshow .next',
				prev		:	'.slideshow .previous'
			//}).autoscroll({
				//steps		:	1,
				//interval	: 	6000,
				//autopause	: 	true,
				//autoplay	:	true
			}).navigator({
				navi		: 	'.slideshow .navigation',
				naviItem	: 	'a',
				activeClass	: 	'current',
				history		: 	true
			});
			
			// Select first item by default
			$('.slideshow .navigation li|:first-child a').addClass('current');

		/* =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
		------------------------------------------------------------------- */
			/* Square client logos */
		 $('.artwork-list li').bind({
				'mouseenter' : function() {
					$(this).find('.details').animate({
					'top' : '0px'
				}, 300, 'easeOutExpo');
			},
				'mouseleave' : function() {
					$(this).find('.details').animate({
					'top' : '-60px'
				}, 150, 'easeInExpo');
			}
		}); 

	Cufon.set('fontFamily', 'ellianarellespath');
	Cufon.replace('.current', {
	hover: true });
	Cufon.now();

	}
	
	/**
	 * 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() {
		
		var fs = $('#forsale').html();
		var artwork = $('#artwork_icon').html();
		var card = $('#greetings_card_icon').html();
		var christmascard = $('#christmas_card_icon').html();
		var postcard = $('#postcard_icon').html();
		var poster = $('#poster_icon').html();
		var print = $('#print_icon').html();
		var tshirt = $('#tshirt_icon').html();

		if(fs == 1){
			$('#forsale').html("<br/>This piece of artwork is for sale.");
		}
		if(artwork == 1){
			$('#artwork_icon').html("<img src='http://www.arthobbs.com/images/icon-artwork.png' alt='Artwork' title='Artwork' />");
		}
		if(card == 1){
			$('#greetings_card_icon').html("<img src='http://www.arthobbs.com/images/icon-card.png' alt='Greetings Card' title='Greetings Card' />");
		}
		if(christmascard == 1){
			$('#christmas_card_icon').html("<img src='http://www.arthobbs.com/images/icon-christmascard.png' alt='Christmas card' title='Christmas card' />");
		}
		if(postcard == 1){
			$('#postcard_icon').html("<img src='http://www.arthobbs.com/images/icon-postcard.png' alt='Postcard' title='Postcard' />");
		}
		if(poster == 1){
			$('#poster_icon').html("<img src='http://www.arthobbs.com/images/icon-poster.png' alt='Poster' title='Poster' />");
		}
		if(print == 1){
			$('#print_icon').html("<img src='http://www.arthobbs.com/images/icon-print.png' alt='Print' title='Print' />");
		}
		if(tshirt == 1){
			$('#tshirt_icon').html("<img src='http://www.arthobbs.com/images/icon-tshirt.png' alt='T-shirt' title='T-shirt' />");
		}

	}
	
	/**
	 * 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();
			$.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:    'http://www.arthobbs.com/shop/ajax/stock_enquiry.php?id='+id+'&opt1='+opt1+'&opt2='+opt2,
        height:     350,
        width:      600
    });
}
