﻿$(document).ready(function(){
	//=============================== SHADOWBOX VIDEO
		  
		$('.shadowboxVideo').each(function(){  //Shadowbox per i video
			params = $(this).attr('class').split('_');
		
			gallery	= (typeof(params[1]) !== 'undefined' && params[1] != '')? '['+params[1]+'];' : ';';
			width	= (typeof(params[2]) !== 'undefined')? 'width='+params[2]+';' : '';
			height	= (typeof(params[3]) !== 'undefined')? 'height='+params[3]+';' : '';
			
			$(this).attr('rel', 'shadowbox'+gallery+width+height);
			
	});
	// Shadowbox
	shadowRel();
	Shadowbox.init();
	// Funzione GalleryOne ////////////////
	var lista = $('.images');
	// Girasole ////////////////
	girasole();
	// Box offerte ////////////////
	offersInit();
	offersInitInt();
	// Box video ////////////////
	$('.boxvideo div').cycle({
		fx: 'fade', 
		speed: 600,
		timeout: 4000 
	});
	//videoInit();
	////Funzione per la GalleryOne dei prodotti e delle pagine della sezione "Settori di Applicazione"  //////////////////////
	var lista_img = $('.images_app');
	var lista_li_img = $('.images_app img').length-4;
	var move_img = 0;
	
	$('.gallery_app span.right').click(function(){ 
		if ((move_img < lista_li_img) && (!lista_img.is(':animated'))) {
			lista_img.stop(true).animate({top:'+=-62px'});
			move_img++;
		}
	});
	
	$('.gallery_app span.left').click(function(){
		if ((move_img > 0) && (!lista_img.is(':animated'))) {
			lista_img.stop(true).animate({top:'+=62px'});
			move_img--;
		}
		
	});	
		
	$("#zoom_photo div:first").css({zIndex:'999'})
	
	$(".images_app a").click(function(){
		$("#zoom_photo div").removeAttr('style');
		var classe = $(this).attr("class");
		var img = $("#zoom_photo div." + classe);
		$(img).css({zIndex:'999'});
	});
	
});


/*******************************************************   shadowbox Seo */

function shadowRel(){
    $('a.shadowBox').each(function() {
		var title = $('img', this).attr('alt');
		
		$(this).attr('title',title);						   
        $(this).attr('rel', 'shadowbox['+ $(this).attr('class').replace(/ /g, '_') +']');
    });	
	
	
	
	$('a.shadowBoxVideo').each(function(){
		params = $(this).attr('class').split('_');

		gallery	= (typeof(params[1]) !== 'undefined' && params[1] != '')? '['+params[1]+'];' : ';';
		width	= (typeof(params[2]) !== 'undefined')? 'width='+params[2]+';' : '';
		height	= (typeof(params[3]) !== 'undefined')? 'height='+params[3]+';' : '';
		
		
		$(this).attr('rel', 'shadowbox'+gallery+width+height);
	});
}
	
	
/*******************************************************   GALLERY SHADOWBOX PAGINE DI SEZIONE */

function showGallery(el) {
	var myItem = $('a:first',$(el));
	var itemGallery = myItem.attr('rel').replace(']','');
	var itemGallery = itemGallery.substring(10);
	
	Shadowbox.teardown(myItem);
	
	Shadowbox.open({
        content:    myItem.attr('href'),
        player:     "img",
        title:      myItem.attr('title'),
		gallery:   itemGallery
    });
	
}


var jbase64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=jbase64._utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4);}return output;},decode:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}if(enc4!=64){output=output+String.fromCharCode(chr3);}}output=jbase64._utf8_decode(output);return output;},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128)utftext+=String.fromCharCode(c);else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}return utftext;},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}return string;}};



/*******************************************************   shadowbox Seo */

function shadowRel(){
    $('a.shadowBox').each(function() {
		var title = $('img', this).attr('alt');
		
		$(this).attr('title',title);						   
        $(this).attr('rel', 'shadowbox['+ $(this).attr('class').replace(/ /g, '_') +']');
    });	
	
	
	
	$('a.shadowBoxVideo').each(function(){
		params = $(this).attr('class').split('_');

		gallery	= (typeof(params[1]) !== 'undefined' && params[1] != '')? '['+params[1]+'];' : ';';
		width	= (typeof(params[2]) !== 'undefined')? 'width='+params[2]+';' : '';
		height	= (typeof(params[3]) !== 'undefined')? 'height='+params[3]+';' : '';
		
		
		$(this).attr('rel', 'shadowbox'+gallery+width+height);
	});
}

/*******************************************************   Box offerte */

function offersInit() {
	var list = $('.boxofferte ul > li');
	$('#boxofferte ul').css({paddingLeft:0});

	if(list.length > 2) {
		myInterval = setInterval ( "offersScroll(1)", 7000 );
	}
}

function offersScroll(loop) {
	
	if(loop==1){
		clearInterval(myInterval);
		myInterval = setInterval ( "offersScroll(1)", 7000 );
	}		

	myFirst = $('.boxofferte ul li:first');
	myWidth = $('.boxofferte ul li:first').width();
	
	myArr = $('.boxofferte ul li').filter(':animated');
	if(myArr.length == 0){
		myFirst.animate(
		{ width:0,
		  marginRight:0,
		  marginLeft:-300
		},
		1200,
		'',
		function(){
			myFirst.remove().insertAfter('.boxofferte ul li:last');
			myFirst.css({marginLeft:0});
			myFirst.css({width:300});
			myFirst.css({marginLeft:0});
		}
		
		);
	}

}
/*******************************************************   Box offerte interno */

function offersInitInt() {
	var list = $('.boxofferteint ul > li');
	$('.boxofferteint ul').css({paddingLeft:0});

	if(list.length > 1) {
		myInterval = setInterval ( "offersScrollInt(1)", 7000 );
	}
}

function offersScrollInt(loop) {
	
	if(loop==1){
		clearInterval(myInterval);
		myInterval = setInterval ( "offersScrollInt(1)", 7000 );
	}		

	myFirst = $('.boxofferteint ul li:first');
	myWidth = $('.boxofferteint ul li:first').width();
	
	myArr = $('.boxofferteint ul li').filter(':animated');
	if(myArr.length == 0){
		myFirst.animate(
		{ width:0,
		  marginRight:0,
		  marginLeft:-158
		},
		1200,
		'',
		function(){
			myFirst.remove().insertAfter('.boxofferteint ul li:last');
			myFirst.css({marginLeft:0});
			myFirst.css({width:158});
			myFirst.css({marginLeft:0});
		}
		
		);
	}

}

/*******************************************************   Box video */

function videoInit() {
	var list = $('.boxvideo ul > li');
	$('.boxvideo ul').css({paddingLeft:0});

	if(list.length > 1) {
		myInterval = setInterval ( "videoScrollInt(1)", 7000 );
	}
}

function videoScrollInt(loop) {
	
	if(loop==1){
		clearInterval(myInterval);
		myInterval = setInterval ( "videoScrollInt(1)", 7000 );
	}		

	myFirst = $('.boxvideo ul li:first');
	myWidth = $('.boxvideo ul li:first').width();
	
	myArr = $('.boxvideo ul li').filter(':animated');
	if(myArr.length == 0){
		myFirst.animate(
		{ width:0,
		  marginRight:0,
		  marginLeft:-153
		},
		1200,
		'',
		function(){
			myFirst.remove().insertAfter('.boxvideo ul li:last');
			myFirst.css({marginLeft:0});
			myFirst.css({width:153});
			myFirst.css({marginLeft:0});
		}
		
		);
	}

}

function girasole() {
	var larghezza = window.screen.width;
	if(larghezza > 1500) {
		$('#cipressi').css("display","block")
		$('#girasole').css("display","block")
		$('#spighette').css("display","block")
	}
}

