$(document).ready(function() {

	var  photosDesc = [["Taj","Vegetal","Jute","Noué main","Champêtre"],
	       ["Block","Singht","Laine et soie","Noué main","Moderne"],
	       ["Mosaic","Singht","Laine et soie","Noué main","Urbain"],
	       ["Bokhara","Privé","Laine et soie","Noué main","Classique"],
	       ["Nain","Privé","Laine et soie","Noué main","Classique"],
	       ["Citrus","Dash et Albert","Coton","Tissé main","Champêtre"],
	       ["Inari","Népalais","Laine","Noué main","Contemporain"],
	       ["Pied de coq","Dhurries","Laine et coton","Tissé main","Contemporain"],
	       ["Water coins","Art morderne","Laine et soie","Noué main","Contemporain"],
	       ["Saggy Chic","Shag","Polyester & coton","Tissé main","Contemporain"],
	       ["Rosalie","Singht","Laine","Noué main","Contemporain"],
	       ["Élément","Novelli","Laine","Tissé main","Contemporain"]];
	
	//apply over to thumbnails
	$(".collection-01 a").each(function(){
		var ref = $(this).parent().attr("ref");
		$(this).css('background',"url('i/"+ref+"-over.jpg') no-repeat");
	});
	
    $("#login-form").hide();
    $(".slide").hide();
    $(".slideshow-container").hide();
    $("#slideshow-home").show();

    $("#loginFormSubmitId").click(function() {
    	var pass = $("#passwordFieldId").val();

    	window.location.href  = "http://"+top.location.host.toString()+ "/espace.php?pass="+pass;

    });
    
    var mouse_is_inside = false;
    $("#login-form").hover(function(){
    	 mouse_is_inside=true; 
    }, function(){
    	mouse_is_inside=false; 
    });
    
    $("body").mouseup(function(){ 
        if(! mouse_is_inside) $("#login-form").hide();
    });

    
    $("#espaceId").click(
      function () {

        if($("#login-form").css('display') == 'none'){

    	       $("#login-form").show();
        }else{
        	    $("#login-form").hide();
        }


      }
    );



    $(".link").click(function () {
        $(".slide").hide();
        $(this).next().toggle('slow');
    });

    $(".collections li").hover(
      function () {
        $(this).find('img:first').hide()
      },
      function () {
        $(this).find('img:first').show()
      }
    );

    $(".collection-01").click(function () {
        $(".list.collections").hide();
        
        var scrollTo = $(this).attr("ref");

        $("#slideshow-01").show();
        $("#slideshow-01 .slideshow").trigger("slideTo","#item"+scrollTo);
    });

    $(".close").click(function () {
        $(this).parent().parent().hide();
        $(".list.collections").show();
    });

    $("#slideshow-01 .slideshow").carouFredSel({
    	items: {
    		visible: 1,
    		width: 290,
    		height: 433
    	},
    	
    	width: 290,
    	height: 433,
    	
    	scroll      : {
    		onAfter : function(oldItems, newItems) { 
    			var itemId = $(newItems).attr("id");
    			var ref = parseInt(itemId.replace("item",""))-1;
    			
    			
    			$("#slideshow-caption").html("<p><strong>"+photosDesc[ref][0]+"</strong><br>"+photosDesc[ref][1]+"<br>"+photosDesc[ref][2]+"<br>"+photosDesc[ref][3]+"<br>"+photosDesc[ref][4]+"</p>");
    		}
    	},
    	auto: false,
    	prev: "#slideshow-01-prev",
    	next: "#slideshow-01-next"
    });

    $("#slideshow-home .slideshow").carouFredSel({
    	items: {
    		visible: 1,
    		width: 322,
    		height: 481
    	},
		width: 322,
    	height: 481,
		
	    onCreate: function(items) {
			var itemId = $(items).attr("ref");
			var ref = parseInt(itemId.replace("item",""))-1;

			if(ref >= 0 && ref < photosDesc.length){

				$("#slideshow-caption").show();	
		    	$("#slideshow-caption").html("<p><strong>"+photosDesc[ref][0]+"</strong><br>"+photosDesc[ref][1]+"<br>"+photosDesc[ref][2]+"<br>"+photosDesc[ref][3]+"<br>"+photosDesc[ref][4]+"</p>");
	
			}else{
    				$("#slideshow-caption").hide();
    			}
    			
	   },
    	scroll      : {
            items    :1 ,
    		onAfter : function(oldItems, newItems) { 
    			var itemId = $(newItems).attr("ref");
    			var ref = parseInt(itemId.replace("item",""))-1;

    			if(ref >= 0 && ref < photosDesc.length){
    				
    				$("#slideshow-caption").show();
    				$("#slideshow-caption").html("<p><strong>"+photosDesc[ref][0]+"</strong><br>"+photosDesc[ref][1]+"<br>"+photosDesc[ref][2]+"<br>"+photosDesc[ref][3]+"<br>"+photosDesc[ref][4]+"</p>");
    			}else{
    				$("#slideshow-caption").hide();
    			}
    			
    		}
    	},
    	auto:  {
    		
    		pauseDuration : 3000,
    		duration : 1000
    		
    	},
    	prev: "#slideshow-home-prev",
    	next: "#slideshow-home-next"
    });

    
});

