
var addToHomeConfig = {
	animationIn:'bubble',	
	animationOut:'drop',	
	lifespan:10000,	
	expire:10,
	touchIcon:true,
	message:'Aggiungi Linfa al tuo <strong>%device</strong>!'
};

var scrollContent;
var idStart = 1;
var xmlProds;
var xmlCountProds = 0;
var nProds = 0;
var timeInterval = 5000;
var bgPictures = [{ image : 'images/bgs/home/07.jpg' }];	


jQuery.fn.exists = function(){return jQuery(this).length>0;};

function loaded() {
		scrollContent = new iScroll('contentWrapper');
}



function loadProdotti(prodsFileName,prodsTag){
var fileName = "xml/screenshots/"+prodsFileName+".xml";
$.ajax({type: "GET",url: fileName,dataType: "xml",success: function(xml) {

var xmlArr = '<?xml version="1.0"?>';
var numb = 1;
xmlArr += '<prodotti>';
$(xml).find('prodotto').each(function() {
tag = $(this).find('tag').text();
if(tag.toUpperCase()==prodsTag.toUpperCase()){
xmlArr += '<prodotto id="'+numb+'">';
xmlArr += '<nome>'+$(this).find('nome').text()+'</nome>';
xmlArr += '<pic>'+$(this).find('pic').text()+'</pic>';
xmlArr += '</prodotto>';
numb++;
}
});
xmlArr += '</prodotti>';

if(prodsTag!=''){
	if (jQuery.browser.msie)
	{
		var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 
		xmlDoc.loadXML(xmlArr);
		xmlProds = xmlDoc;
	}else{
	xmlProds = xmlArr;
	}
}else{
xmlProds = xml;
}

nProds = $(xmlProds).find('prodotto').length;

changeProds(idStart);
$(document).everyTime(timeInterval, function(i) {changeProds(idStart)});
}});

return xmlCountProds;
}


function changeProds(idStartz){
var idBox = 1;
var id = 0;
var idAum;

if(idStartz>nProds){idStart = 1;idStartz = 1;}
$.each($(xmlProds).find('prodotto'), function(i, l){
		//id = $(this).attr('id');
		if (id==0)id=1;
		else id = id+1;
		
		if(idStartz+idBox-1 == id && idBox<4){
			var title = $(this).find('nome').text();
			var img = $(this).find('pic').text();
			
			var imgDC = 'images/prodotti/'+img;
			
			var timeZ = 500;
			
			
			$('#prodBox'+idBox).find('.prodTitle').html('<h3>'+title+'</h3><br />');

						
			
			$('#prodBox'+idBox).find('.prodPic').fadeOut(timeZ, function() {
			$(this).css('background-image', 'url('+imgDC+')').fadeIn(timeZ)
			$('#prodBox'+idBox).find('.prodPic img').attr('src', 'images/Glossy_base.png')
			
			})
			
			
			// $(this).find('desc').each(function(){	
				// var long = $(this).find('long').text();
				// $('#prodBox'+idBox).find('.prodDescLong').html(long);
			// });
			Cufon.replace('h3'); 
			idAum = id;
		}
});	
idStart = parseInt(idStart) + parseInt(idBox);
}



function loadProdottiHome(){
$.ajax({type: "GET",url: "xml/screenshots/Home.xml",dataType: "xml",success: function(xml) {
xmlProds = xml;
nProds = $(xmlProds).find('prodotto').length;
//times = Math.floor(($(xmlProds).find('prodotto').length)/3)-1;
changeProdsHome(idStart);
$(document).everyTime(timeInterval, function(i) {changeProdsHome(idStart)});
}});
return xmlCountProds;
}

function changeProdsHome(idStartz){
var idBox = 1;
var id = 0;
var idAum;
if(idStartz>nProds){
idStart = 1;
idStartz = 1;
}

$.each($(xmlProds).find('prodotto'), function(i, l){
		//id = $(this).attr('id');
		if (id==0)id=1;
		else id = id+1;
		
		if(idStartz+idBox-1 == id && idBox<4){
			var title = $(this).find('nome').text();
			var url = $(this).find('url').text();
			var img = $(this).find('img').text();
			//$('#prodBoxHome'+idBox).fadeOut();
			$('#prodBoxHome'+idBox).find('.prodHomeDescBrief').html('<h1>'+title+'</h1><br />');
			
			var imgDC = 'images/prodotti/home/'+img;
			var timeZ = 500;
			
			$('#prodBoxHome'+idBox).find('.prodHomePic').fadeOut(timeZ, function() {
			$(this).css('background-image', 'url('+imgDC+')').fadeIn(timeZ,function(){
			
			
			
			})
			
			$('#prodBoxHome'+idBox).find('.prodHomePic img').attr('src', 'images/Glossy_base.png');
			
			})

			// $(this).find('desc').each(function(){
				// var brief = $(this).find('brief').text();
				// var long = $(this).find('long').text();
				// $('#prodBoxHome'+idBox).find('.prodHomeDescBrief').append(brief);
				// $('#prodBoxHome'+idBox).find('.prodHomeDescLong').html(long);
			// });
			Cufon.replace('h1'); 
			//$('#prodBoxHome'+idBox).delay(500).fadeIn();
			idAum = id;
			idBox++;
			
			
			
		}
});	
	
idStart = parseInt(idStart) + parseInt(idBox-1);
}



function loadQuotes(path){




}

$(document).ready(function() {

$("label").inFieldLabels(); 
$("input").attr("autocomplete","off");

//MOBILE MOBILE MOBILE
if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){
/*
$(document).addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
$(document).addEventListener('DOMContentLoaded', loaded, false);
$("#bottomBar").css("position", "static");
$("#topBar").css("position", "absolute");
$("#topBar").css("top", "0px");
$(".middleBox500,.middleBox320,.middleBox140").removeClass("middleBox").addClass('middleBoxMobile');

window.addEventListener('orientationchange', function (evt) {
    switch(window.orientation) {
        case 0: // portrait
        case 180: 
	            
				$("#site").hide();
				$("#rotate").show();
				$("#supersized").hide();
            break;	
		
        case 90: // landscape
        case -90: 
		$("#site").show();
		$("#rotate").hide();
		$("#supersized").show();
		
		break;
    }
}, false);
*/

};





	


//PAGES PAGES PAGES
var prodsTag;
var prodsFileName;
//XML
if($("#prodsPath").exists()){
prodsFileName = $("#prodsPath").val();
if($("#prodsTag").exists()){ 
prodsTag = $("#prodsTag").val();
}
loadProdotti(prodsFileName, prodsTag);
}


if($(".page_contacts").exists()){
//CONTACTS
bgPictures = [{ image : 'images/bgs/contacts/01.jpg' }];		
//MAPS
//http://maps.google.it/maps?q=Viale+Giulio+Cesare,+49,+00193+Roma&hl=it&ll=41.911843,12.46547&spn=0.008431,0.013626&sll=41.442726,12.392578&sspn=17.378113,27.905273&hnear=Viale+Giulio+Cesare,+49,+00192+Roma,+Lazio&t=m&z=16&iwloc=A
var latlngRoma = new google.maps.LatLng(41.911007, 12.464908);

var latlngNY = new google.maps.LatLng(40.751223, -73.979981);
//var latlngStudios = new google.maps.LatLng(40.751223, -73.979981);
var latlngStudios = new google.maps.LatLng(41.910698, 12.465196);
$('#map3').gmap({ 'center': latlngStudios, zoomControl:true,streetViewControl:false,overviewMapControl:false,mapTypeControl:false,zoom:16,'callback': function() {$('#map3').gmap('addMarker', { 'position': latlngStudios } );}});
$('#map2').gmap({ 'center': latlngRoma, zoomControl:true,streetViewControl:false,overviewMapControl:false,mapTypeControl:false,zoom:16,'callback': function() {$('#map2').gmap('addMarker', { 'position': latlngRoma } );}});
$('#map1').gmap({ 'center': latlngNY, zoomControl:true,streetViewControl:false,overviewMapControl:false,mapTypeControl:false,zoom:16,'callback': function() {$('#map1').gmap('addMarker', { 'position': latlngNY } );}});

			
}else if($(".page_home").exists()){
//HOME
loadProdottiHome();
}else if($(".page_about_us").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];	
//ABOUT US
$("#about_us_sub").show().offset({ top: $("li.about_us").offset().top-32, left: $("li.about_us").offset().left });
$(".about_us").addClass('about_us_sub');
}else if($(".page_metodologia").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
//METODOLOGIA
$("#metodologia_sub").offset({ top: $("li.metodologia").offset().top-32, left: $("li.metodologia").offset().left }).delay(1000).fadeIn(400);
$('.metodologia').addClass('metodologia_sub');
}else if($(".page_elearning").exists()){
//ELEARNING

// $("div[class^='page']").each(function(){
    // alert(this.id);
   
// });
//loadQuotes('elearning');
}else if($(".page_ecommunication").exists()){
//ECOMMUNICATION
// if($("#prodsPath").exists()){var prodsFileName = $("#prodsPath").val();}
// loadProdotti();
}else if($(".page_iniziative").exists()){
//bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}else if($(".page_clienti").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}else if($(".page_job").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}else if($(".page_privacy").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}else if($(".subpage_company_overview").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}else if($(".subpage_executive_team").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}else if($(".subpage_it_process").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}else if($(".subpage_content_management").exists()){
bgPictures = [{ image : 'images/bgs/home/02.jpg' }];
}
	
	
	
$.supersized({
		start_slide				:	0,		//Start slide (0 is random) //Requires multiple background images
		vertical_center         :   1,		//Vertically center background
		horizontal_center       :   1,		//Horizontally center background
		min_width		        :   1000,	//Min width allowed (in pixels)
		min_height		        :   700,	//Min height allowed (in pixels)
		fit_portrait         	:   0,		//Portrait images will not exceed browser height
		fit_landscape			:   0,		//Landscape images will not exceed browser width
		image_protect			:	1,		//Disables image dragging and right click with Javascript
		slides					:   bgPictures					
});




if($(".page_home").exists()){$('.home a').addClass('active');}
if($(".page_about_us").exists()){$('.about_us a').addClass('active');}
if($(".page_metodologia").exists()){$('.metodologia a').addClass('active');}
if($(".page_elearning").exists()){$('.elearning a').addClass('active');}
if($(".page_ecommunication").exists()){$('.ecommunication a').addClass('active');}
if($(".page_it").exists()){$('.informationtechnology a').addClass('active');}
if($(".page_clienti").exists()){$('.clienti a').addClass('active');}
if($(".page_contacts").exists()){$('.contacts a').addClass('active');}
if($(".page_privacy").exists()){$('.privacy a').addClass('active');}
if($(".page_job").exists()){$('.job a').addClass('active');}
if($(".page_strategic_planning").exists()){$('.strategic_planning a').addClass('active');}
if($(".page_iniziative").exists()){$('.iniziative a').addClass('active');}




if($(".subpage_company_overview").exists()){$('.company_overview a').addClass('active');}
if($(".subpage_executive_team").exists()){$('.executive_team a').addClass('active');}
if($(".subpage_it_process").exists()){$('.it_process a').addClass('active');}
if($(".subpage_content_management").exists()){$('.content_management a').addClass('active');}
if($(".subpage_webseminar").exists()){$('.webseminar a').addClass('active');}
if($(".subpage_mobilelearning").exists()){$('.mobilelearning a').addClass('active');}
if($(".subpage_rapidlearning").exists()){$('.rapidlearning a').addClass('active');}



if($(".subpage_interactive_classroom_training").exists()){$('.ict a').addClass('active');}
if($(".subpage_tutorial").exists()){$('.tutorial a').addClass('active');}
if($(".subpage_wbt").exists()){$('.wbt a').addClass('active');}
if($(".subpage_web_conference").exists()){$('.web_conference a').addClass('active');}
if($(".subpage_webinar").exists()){$('.webinar a').addClass('active');}
if($(".subpage_edugame").exists()){$('.edugame a').addClass('active');}

if($(".subpage_multimedia_presentation").exists()){$('.multimedia_presentation a').addClass('active');}
if($(".subpage_video_production").exists()){$('.video_production a').addClass('active');}
if($(".subpage_mobilecommunication").exists()){$('.mobilecommunication a').addClass('active');}
if($(".subpage_webtv").exists()){$('.webtv a').addClass('active');}


if($(".subpage_internet_custom_solutions").exists()){$('.ics a').addClass('active');}
if($(".subpage_internet_software_solutions").exists()){$('.iss a').addClass('active');}
if($(".subpage_outsourcing_it").exists()){$('.oit a').addClass('active');}




$("li.about_us").mouseenter(function() {
$("#metodologia_sub").hide()
$("#about_us_sub").show().offset({ top: $("li.about_us").offset().top-32, left: $("li.about_us").offset().left });}).mouseleave(function() {});

$("li.metodologia").mouseenter(function() {
$("#about_us_sub").hide()
$("#metodologia_sub").show().offset({ top: $("li.metodologia").offset().top-32, left: $("li.metodologia").offset().left });
}).mouseleave(function() {});

$("li.footerMenuItem").mouseenter(function() {
if($(this).hasClass('about_us') || $(".page_about_us").exists()){}else{$("#about_us_sub").hide();}
if($(this).hasClass('metodologia') || $(".page_metodologia").exists()){}else{$("#metodologia_sub").hide();}
});


$('#searchBar').delay(1000).css('left', $(window).width()-$('#searchBar').width()).show();
//$('#footerImage').hide().delay(1000).css('top', $(window).height()-$('#footerImage').height());
$('#bottomBar').delay(1000).css('top', $(window).height()-$('#bottomBar').height());

$(window).resize(function() {
$('#searchBar').delay(1000).css('left', $(window).width()-$('#searchBar').width());
//$('#footerImage').delay(1000).css('top', $(window).height()-$('#footerImage').height());
$('#bottomBar').delay(1000).css('top', $(window).height()-$('#bottomBar').height());
});



Cufon.replace('h1,h3,h2',{hover: true}); 
//Cufon.replace('#sub1'); 





var srcDown = "images/homeSlideDown.png";
var srcUp = "images/homeSlideUp.png";

$('.prodToggler').click(function(){
	$(this).hide();
	$(document).stopTime();
	
	
	if($(this).children().hasClass('homeSlideUp') && $(this).parent().css('top')>'100px'){
		$(this).parents(".prodContainerHome").addClass('activated');
		$(this).parent().stop().animate({ top:'-=128px' },500,function(){});
		$(this).children().attr("src", srcDown).addClass('homeSlideDown').removeClass('homeSlideUp');
		$(this).parent().prev().stop().animate({ top:'-=138px'},500,function(){
		
		$(this).animate({ height:'392px'},500)
	
		
		$(this).next().children().show();
		
		});		
	
	}else if($(this).children().hasClass('homeSlideDown') && $(this).parent().css('top')<'1px'){
		$(this).parents(".prodContainerHome").removeClass('activated');
		$(document).everyTime(timeInterval, function(i) {changeProdsHome(idStart)});
		$(this).parent().stop().animate({ top:'+=128px' },500,function(){});
		$(this).children().attr("src", srcUp).addClass('homeSlideUp').removeClass('homeSlideDown');
		$(this).parent().prev().stop().animate({ height:'264px' },500,function(){
		$(this).animate({ top:'+=138px' },500,function(){
		
		$(this).next().children().show();
		});
		
		
		
		});
	}


	if($('#middleSection').children('.activated').exists()){
	
	}else{
	$(document).everyTime(timeInterval, function(i) {changeProdsHome(idStart)});
	}
	
	
	});



$('.prodTogglerDown').click(function(){
//alert('-');
});





$('.actionLink').click(function(){



$('#actionContent').html(
$('#disp_'+$(this).attr('id')).html()
);


Cufon.replace('h1,h3,h2',{hover: true});


});

$('#action_1').trigger('click');


/////////////CONTATTI
var options = { 
        target:        '#risposta',   // target element(s) to be updated with server response 
     //   beforeSubmit:  showRequest,
        success:       showResponse  // post-submit callback 

    }; 

$('#contactform').ajaxForm(options);

function showResponse(responseText, statusText, xhr, $form)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 

} 

$("#contactform").validate(
{
		rules: {
			nome: "required",
			email: {
				required: true,
				email: true
			},
			oggetto: {
				required: true,
				minlength: 2
			},
			messaggio: "required"
		},
		messages: {
			nome: "*",
			email: {
				required: "*",
				email: "Email non valida"
			},
			oggetto: {
				required: "*",
				minlength: "*"
			},
			messaggio: "*"
		}
	}
);

	
});
