/* global MailUp scripts */
function countLines(obj) {
	el = obj;
    var divHeight = el.height();
    var lineHeight = parseInt(el.css('line-height'));
    var lines = divHeight / lineHeight;
    return lines;
}

function emailencode() {
	jQuery('a[href*="*"]').each(function() {
		jh=jQuery(this).attr('href');
		if(jQuery(this).text() == "") {
			jQuery(this).attr('href', "mailto:"+jh.replace("*", "@")).text(jh.replace("*", "@"));
		} else {
			jQuery(this).attr('href', "mailto:"+jh.replace("*", "@"));
		}
	});
}
	
jQuery(document).ready(function() {	
	// email encoding
	emailencode();
	
	// tooltips
	jQuery('form img[title]').qtip({ style: { tip: true, classes: "ui-tooltip-dark", width: 520 }});
	jQuery('.nice-tooltip').qtip({ style: { tip: true, classes: "ui-tooltip-dark", width: 520 }});	
	jQuery('a.link-locked').qtip({content: "Per accedere a questa risorsa devi essere registrato.", position: {	 adjust: { x: 24, y: 24 },	my: "top left",	at: "top left"	},	style: {tip: true,	classes: "ui-tooltip-dark"	}});
	jQuery('span.mailup-option-active').qtip({	style: {tip: true,classes: "ui-tooltip-dark"},position: {adjust: {x: -8,y: 2}}});
		
	// toggle hidden blocks
	jQuery('.box-collapsable').find('h3').click(function() {		
		if(jQuery(this).next().css('display')=="none") {
			jQuery(this).next().css({'display':'block'});
		} else {
			jQuery(this).next().css({'display':'none'});
		}
	});	
	
	// toggle hidden tables 
	jQuery('.collapsable-table').find('thead').click(function() {	
		if(jQuery(this).next().find('td,th').css('display')=="none") {
			if (jQuery.browser.msie && jQuery.browser.version ==7) { 
				jQuery(this).next().find('td,th').css({'display':'block'});
			} else {				
				jQuery(this).next().find('td,th').css({'display':'table-cell'});
			}
			jQuery(this).parent().removeClass('collapsed');			
		} else {
			jQuery(this).next().find('td,th').css({'display':'none'});
			jQuery(this).parent().addClass('collapsed');
		}			
	});
	
	if(jQuery('#pcMainArea10-LEFT').length) {
		jQuery('#pcMainArea10').addClass('pcMainArea10-twoCols');
	}
	
	// lightbox
	if($.fancybox) {	
		jQuery('a.video-lightbox').fancybox({type: 'iframe', overlayColor: '#000', width: 690, height: 520});
		jQuery('a.newsletter-lightbox').fancybox({overlayColor: '#000'});
		jQuery('a.privacy-lightbox').fancybox({type: 'iframe',overlayColor: '#000', width: 820, height: 520, autoDimensions: false, centerOnScroll: true});
		jQuery('a.map-lightbox').fancybox({type: 'iframe', overlayColor: '#000', width: 700, height: 520, autoDimensions: false});
		jQuery('a.image-lightbox').fancybox({overlayColor: '#000', titlePosition: 'inside'});
		jQuery('a.home-video-lightbox').fancybox({type: 'iframe', overlayColor: '#000',scrolling: 'no', width: 801, height: 550});
		
		jQuery('span.video-overlay').remove();		
		jQuery('a.video-lightbox').append('<span class="video-overlay"></span>');
		jQuery('a.video-lightbox img').each(function() {
			if(jQuery(this).size()) {
				jQuery(this).parents('a').find('.video-overlay').width(jQuery(this).width()).height(jQuery(this).height()).css({'opacity': '0.2', 'background-color' : '#000'});
			}
		});
		jQuery('a.video-lightbox').hover(
			function() { jQuery(this).find('.video-overlay').css({'opacity': '0.5', 'background-color' : '#000'}); }, 
			function() { 
						jQuery(this).find('.video-overlay').css({'opacity': '0.2', 'background-color' : '#000'});
			});
	}
	// adjust styles	
	jQuery(".half-column").find("h3").each(function() { if(jQuery(this).outerHeight() < 36 && (jQuery(this).next().hasClass('box-icon-text') || jQuery(this).parent().next().hasClass('box-icon-text'))) { jQuery(this).css({ 'margin-top': '28px' }); } else { 	jQuery(this).css({ 'margin-top': '10px' }); } });
	if(jQuery(".PageTitle").outerHeight() < 70) {jQuery('.PageTitle').css({ 'margin-top': '18px' });}
	//if(jQuery('#headerCart').length) {jQuery('body').css({'background-position':'0 41px'}); }
	jQuery('.pc-details-td').width(0);
	
	jQuery('.option-opzioni-comuni, .option-opzioni-avanzate, .option-assistenza').parent().css({ 'background-color':'#fff' });
	jQuery('.PrdAddChargesContent').find('input[name="add"]').attr('src', 'images/sample/IT/pc_button_continue.gif');
	if(jQuery("#custprefPostit p").outerHeight() > 290) {jQuery('#custprefPostit').css({ 'background-image': 'url(images/mailup2011/postit_custpref2.png)' }).height(350);}
	
	// adjust columns' height	
	function adjustColsHeight() {
		if(jQuery('#pcMainArea10-LEFT').height() < jQuery('#pcMainArea10-PC').height()) {
			jQuery('#pcMainArea10-LEFT').height(jQuery('#pcMainArea10-PC').height());
		} else {
			jQuery('#pcMainArea10-PC').height(jQuery('#pcMainArea10-LEFT').height());
		}
	}	
	jQuery('a[href="javascript:Recaptcha.reload()"]').addClass('reloadcaptchalink').css({'position':'relative'}).append("<span class='reloadcaptcha'>Rigenera il codice</span>");
	jQuery('a[href="javascript:Recaptcha.reload()"]').click(function() { _gaq.push(['_trackPageview', 'clic-reload-captcha']); });
});

jQuery('a.video-lightbox img').ready(function() {
	jQuery('a.video-lightbox img').each(function() {
		if(jQuery(this).size()) {
			jQuery(this).parents('a').find('.video-overlay').width(jQuery(this).width()).height(jQuery(this).height()).css({'opacity': '0.2', 'background-color' : '#000'});
		}
	});
});
/* idTabs ~ Sean Catchpole - Version 2.2 - MIT/GPL */
(function(){var dep={"jQuery":"http://code.jquery.com/jquery-latest.min.js"};var init=function(){(function($){$.fn.idTabs=function(){var s={};for(var i=0;i<arguments.length;++i){var a=arguments[i];switch(a.constructor){case Object:$.extend(s,a);break;case Boolean:s.change=a;break;case Number:s.start=a;break;case Function:s.click=a;break;case String:if(a.charAt(0)=='.')s.selected=a;else if(a.charAt(0)=='!')s.event=a;else s.start=a;break;}}
if(typeof s['return']=="function")
s.change=s['return'];return this.each(function(){$.idTabs(this,s);});}
$.idTabs=function(tabs,options){var meta=($.metadata)?$(tabs).metadata():{};var s=$.extend({},$.idTabs.settings,meta,options);if(s.selected.charAt(0)=='.')s.selected=s.selected.substr(1);if(s.event.charAt(0)=='!')s.event=s.event.substr(1);if(s.start==null)s.start=-1;var showId=function(){if($(this).is('.'+s.selected))
return s.change;var id="#"+this.href.split('#')[1];var aList=[];var idList=[];$("a",tabs).each(function(){if(this.href.match(/#/)){aList.push(this);idList.push("#"+this.href.split('#')[1]);}});if(s.click&&!s.click.apply(this,[id,idList,tabs,s]))return s.change;for(i in aList)$(aList[i]).removeClass(s.selected);for(i in idList)$(idList[i]).hide();$(this).addClass(s.selected);$(id).show();return s.change;}
var list=$("a[href*='#']",tabs).unbind(s.event,showId).bind(s.event,showId);list.each(function(){$("#"+this.href.split('#')[1]).hide();});var test=false;if((test=list.filter('.'+s.selected)).length);else if(typeof s.start=="number"&&(test=list.eq(s.start)).length);else if(typeof s.start=="string"&&(test=list.filter("[href*='#"+s.start+"']")).length);if(test){test.removeClass(s.selected);test.trigger(s.event);}
return s;}
$.idTabs.settings={start:0,change:false,click:null,selected:".selected",event:"!click"};$.idTabs.version="2.2";$(function(){$(".idTabs").idTabs();});})(jQuery);}
var check=function(o,s){s=s.split('.');while(o&&s.length)o=o[s.shift()];return o;}
var head=document.getElementsByTagName("head")[0];var add=function(url){var s=document.createElement("script");s.type="text/javascript";s.src=url;head.appendChild(s);}
var s=document.getElementsByTagName('script');var src=s[s.length-1].src;var ok=true;for(d in dep){if(check(this,d))continue;ok=false;add(dep[d]);}if(ok)return init();add(src);})();


