/* Initialisation des module JS */

var src=''; 
var BaseUrl = '/public/';
var Dossier = 'technosat';
$(function(){ 
	var $scrollables = $(".horcrawler").scrollable({circular: true, delay: 2500}).autoscroll({ autoplay: true});
	
	$scrollables.each(function() {
		var $itemsToClone = $(this).scrollable().getItems().slice(1);
		var $wrap = $(this).scrollable().getItemWrap();
		var clonedClass = $(this).scrollable().getConf().clonedClass;
		$itemsToClone.each(function() {
			$(this).clone(true).appendTo($wrap)
				.addClass(clonedClass + ' hacked-' + clonedClass);
		})
	})
	$(".ctooltip[title]").tooltip({
		   // tweak the position
		   offset: [10, 2],
		   // use the "slide" effect
		   effect: 'slide'
    // add dynamic plugin with optional configuration for bottom edge
	}).dynamic({ bottom: { direction: 'down', bounce: true } });
	
	$(".zoom").click(function(event) {
		event.stopPropagation();
		 id = $(this).attr("id");		 
	});
	 $(".zoom").overlay({
			top: 10,
			effect: 'apple',
			target: '#box',
			mask: { maskId: 'mask' },

			// when box is opened, scroll to correct position (in 0 seconds)
			onBeforeLoad: function() {
				$("#zoomimages .items3 div").empty();
			},
			onLoad: function() {
				$("#zoomimages .items3 div").append('<img class="loading" src="'+ BaseUrl + 'images/large-loading.gif" />'); 
				$(".loading").css("margin-top", "200px");
				$("#box .navi").hide();
				$.ajax({ 
				        type: "POST", 
				        cache: false,
				        dataType:"html",
				        url: BaseUrl+Dossier+'/produit/info/id/'+id, 
						processData :false,
				        success: function(data){ 					 
								zoomer (data);
				        }, 
				        error: function(data, textStatus, errorThrows){
				        	if (data.readyState == 4){
				                data = data.responseText;
					            zoomer(data);
				        	}    
				        } 
				}); 		
			}
	 });
	 
	//Yoxview
		$(".yoxview").yoxview();
		
		
	 $('#btn-search').live('click',function(){ 
			$('#searchform')[0].submit();
		});
	 
	src =$('#captcha').attr('src');

	$('#captcha').remove();

	$('#contcap').html('<img src="'+src+'" id="captcha" name="captcha" width="200" height="50" />');

	$('.formcaptch label').append ('(Si vous n\'arrivez pas à saisir correctement le mot, <a href="" onClick="this.blur(); new_phpcap();return false;" style="color :#ff0000;font-size:7pt">cliquer ici</a> ):'); 

	//envoyer un formulaire 
    $(".langue").bind("click",function(event){
    	event.stopPropagation();
    	langue = $(this);
    	var rel = $(this).attr("rel").split("_");
    	if ($(langue).hasClass(rel[0]+"_active")) {
	    	$('#cont_presentation').block({ 
	            message: null,
	            css : {}
	        });
	    	$(".langue").each(function(){
	    		 var lg = $(this).attr("rel").split("_");
	    		 $(this).removeClass(lg[0]+"_desactive");
	    		 $(this).addClass(lg[0]+"_active");
	    	});
	    	$(langue).removeClass(rel[0]+"_active");
	    	$(langue).addClass(rel[0]+"_desactive");
	    	$("#suite_presentation").attr("href",$("#suite_presentation").attr("rel")+rel[0]);
	    	var suite = "Suite...";
	    	if (rel[0]=="Eng"){
	    		suite = "Read more...";
	    	}else{
	    		if (rel[0]=="Ar") suite = "...إقرأ المزيد";
	    	}
	    	$.ajax({ 
		        type: "POST", 
		        cache: false,
		        dataType:"html",
		        url: BaseUrl+Dossier+'/presentation/info/l/'+rel[0]+'/a/'+rel[1], 
				processData :false,
		        success: function(data){ 	
	    			$('#cont_presentation').empty();
	    			$('#cont_presentation').html(data);
	    			$('#cont_presentation').unblock();
	    			$("#suite_presentation").empty();
	    			$("#suite_presentation").html(suite);
	    			if (rel[0]=="Ar") $("#suite_presentation").css("float","left");
		        }, 
		        error: function(data, textStatus, errorThrows){
		        	if (data.readyState == 4){
		                data = data.responseText;
		                $('#cont_presentation').empty();
		    		$('#cont_presentation').html(data);
		                $('#cont_presentation').unblock();
		                $("#suite_presentation").empty();
	    			$("#suite_presentation").html(suite);
	    			if (rel[0]=="Ar") $("#suite_presentation").css("float","left");
		        	}    
		        } 
		    });
    	}
    })
	

});

function new_phpcap(){ 

	$('#captcha').attr('src',src+'?'+Math.round(Math.random()*100000));

}
function zoomer (data){
	$(".loading").remove();
    
    values = data.split("##");
    topOffset = values[1] - 75;
    $("#zoomimages .items3 div").html(values[0]);
    $("#zoomimages .items3 div img").css("margin-top", values[1]+"px");
	$("#zoomimages img").tooltip({
		position: "bottom center",
		offset: [topOffset, -30],
		opacity: 0.8,
		effect: 'fade',
		// position tooltips relative to the parent scrollable
		relative: true
	});
	//$("#zoomimages .items .info").css("margin-top");
}
		
