// JavaScript Document

var ProjectShoes = {

	DOMready: function()
	{
		// DECOMMENTARE QUANDO SI VUOLE AGGIUNGERE IL POP UP DELLE FERIE
		/*
		if ($('#body-copy').length > 0) {
			
			var url = document.URL; 
			var str;
			//alert(url)
			if(url.indexOf("IT")>-1)
			{
				str = "<p>Gentile cliente,<br />La informiamo che il termine ultimo per ordini di scarpe con consegna entro il 24.12.2011 &egrave; il 07.12.2011.<br />&nbsp;<br />Cordiali saluti,<br />PERSONAL SHOES</p>"
				
			}	
				
			else if(url.indexOf("EN")>-1)
			{	
				str = "<p>We inform you that the deadline for orders to be delivered before the 24th Dec is the 07th Dec.<br />&nbsp;<br />Best regards,<br />PERSONAL SHOES</p>"
			}
				
				
			$("#slider").after("<li id='chiusura'>"+str+"</li>");
			$("#chiusura").click(function(){$(this).remove()})
		}
		*/
		// FINE CODICE POP UP

		// POST-IT
		/*
		var url = document.URL; 
		var str;
		if(url.indexOf("IT")>-1)
		{
			str = "<p>Il termine ultimo per ordini di scarpe con consegna entro il 24.12.2011 &egrave; il 07.12.2011.</p>"
		}	
			
		else if(url.indexOf("EN")>-1)
		{	
			str = "<p>Tthe deadline for orders to be delivered before the 24th Dec is the 07th Dec.</p>"
		}		

		
		if ($('#scheda').length > 0) {
			$("#scheda").after("<li id='post-it'>"+str+"</li>");
		}		
		
		if ($('div#configuratore').length > 0) {
			$("#configuratore").after("<div id='post-it'>"+str+"</div>");
		}		
		if ($('.configuratore-200').length > 0) {
			$('#post-it').css('left', '500px');
			$('#post-it').css('top', '130px');
			
		}
		*/
		// FINE CODICE POST-IT

	    if ($('.popup').length > 0) { ProjectShoes.popup() }
	    if ($('#natale').length > 0) { ProjectShoes.popupNatale() }
		if ($('#newsletter').length > 0) { ProjectShoes.popupNewsletter() }
	    if ($('.popup-amico').length > 0) { ProjectShoes.popupAmico() }
		if ($('#slider').length > 0) {ProjectShoes.slider()}
		if ($('#contenuto-carrello').length > 0) {ProjectShoes.showCarrello()}
		if ($('.tabella-numero').length > 0) {ProjectShoes.tabellaNumero()}
		if ($('.testo-esempio').length > 0) {ProjectShoes.testoEsempio()}
		if ($('.social-network .flickr').length > 0) {ProjectShoes.flickrGetJson()}
		if ($('#configuratore').length > 0) {ProjectShoes.flashInclude('#configuratore', 'form.swf')}
		/* Configuatore Mod200*/
		if ($('#materiali').length > 0) { ProjectShoes.materiali() };
	}, // fine DOMReady

	slider: function()
	{
		$('#slider').nivoSlider({
			effect:'fold',
			slices:15,
			animSpeed:500,
			pauseTime:5000,
			directionNav:false, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:true, //1,2,3...
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){} //Triggers after all slides have been shown
		});
	}, // fine slider

	showCarrello: function()
	{
		$('.btn-carrello').click(function() {
			$('#contenuto-carrello').slideDown('slow');
		});
		$('#contenuto-carrello').click(function() {
			$('#contenuto-carrello').slideUp('slow');
		});
		

	},

	testoEsempio: function()
	{		
		
		$('.testo-scarpa label input').focus(function() {
			$('.testo-esempio').show();
		});		

		$('.testo-scarpa label input').focusout(function() {
			$('.testo-esempio').hide();
		});
		
		$('.testo-esempio').click(function() {
			$('.testo-esempio').hide();
		});
		
		$('.guarda-esempio').click(function(el) {
			$('.testo-esempio').show();
		});
		
	}, // fine ScrollPane
	
	flashInclude: function(obj, swfFile)
	{
		$(obj).flash( 
		{ 
				// test.swf is the flash document 
				swf: swfFile,
				id: "movie",
				name: "movie",
				width: 758,
				height: 550,
				wmode: 'transparent',
				expressInstaller: '../../../../swf/expressInstall.swf', // optional and temporary	
				flashvars:
				{ 
					//
				}			
		})	
	}, // fine flashInclude

	popupNatale: function()
	{
		$('#natale a').colorbox({'scalePhotos':false, innerWidth:630, innerHeight:450})
    }, // fine popupNatale

	popupNewsletter: function()
	{
		$('.popupNewsletter').colorbox({ iframe: true, innerWidth: 450, innerHeight: 450 })
    }, // fine popupNatale
	
	popup: function()
	{
		$('.popup').colorbox({iframe:true, innerWidth:650, innerHeight:450})
    }, // fine popup

    popupAmico: function() {
        $('.popup-amico').colorbox({ iframe: true, innerWidth: 650, innerHeight: 600 })
    }, // fine popup
	
	controlForm: function()
	{
		if ($(".errore").length > 0) {
			
			$(".errore").click(function () { 
				$(this).slideUp(); 
			});
			
		}	
	},
	
	tabellaNumero: function()
	{
		$('table.tabella-numero tbody tr:even td').addClass('even');
		$('table.tabella-numero tbody tr:even th').addClass('even');
	}, // fine tabellaNumero
    
	tabs: function () { // gestisco le tabs
        $("#tabs").tabs();
    }, // fine Tabs

	materiali: function () { // gestisco le tabs
        
		ProjectShoes.tabs();
		
		$('.elencoColori').click(function() {
  			$('#tabs').animate({
				left: '0'
			  }, 800, function() {
				// Animation complete.
			  });
		});
		
		$('.chiudiColori').click(function() {
  			$('#tabs').animate({
				left: '-540px'
			  }, 800, function() {
				// Animation complete.
			  });
		});
		
		$('.colori li a').colorbox();
		
    }, // fine Tabs
	
	
	flickrGetJson: function()
	{
		// Our very special jQuery JSON fucntion call to Flickr, gets details of the most recent 20 images			   
		//$.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?id=1455754@N21&lang=it-it&format=json&jsoncallback=?", ProjectShoes.flickrGallery);
		$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=51261794@N06&lang=it-it&format=json&jsoncallback=?", ProjectShoes.flickrGallery);
		
	},
	
	flickrGallery: function(data)
	{
		
//		function displayImages(data) {																																   
			// Randomly choose where to start. A random number between 0 and the number of photos we grabbed (20) minus 9 (we are displaying 9 photos).

			var iStart = Math.floor(Math.random()*(11));	
			
			// Reset our counter to 0
			var iCount = 0;								
			
			// Start putting together the HTML string
			var htmlString = "<ul class='cleared'>";
			
			// Now start cycling through our array of Flickr photo details
			$.each(data.items, function(i,item){
										
				// Let's only display 9 photos (a 3x3 grid), starting from a random point in the feed					
				if (iCount > iStart && iCount < (iStart + 10)) {
					
					// I only want the ickle square thumbnails
					var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");		
					
					// Here's where we piece together the HTML
					//htmlString += '<li><a href="' + item.link + '" target="_blank">';
					htmlString += '<li><a href="http://www.flickr.com/photos/projectshoes/show/" target="_blank">';
					htmlString += '<img src="' + sourceSquare + '" alt="' + item.title + '" title="' + item.title + '"/>';
					htmlString += '</a></li>';
				}
				// Increase our counter by 1
				iCount++;
			});		
			
		// Pop our HTML in the #images DIV	
		$('.flickr').html(htmlString + "</ul>");
		
		// Close down the JSON function call
		//}

	
	}
	
} // fine var ProjectShoes

$(document).ready(function() { ProjectShoes.DOMready() });


