var colors = [];
colors['color_00'] = '#000000'; // Black
colors['color_01'] = '#4ABDE6'; // Light Blue
colors['color_02'] = '#018ECC'; // Dark Blue
colors['color_03'] = '#00B3A4'; // Emerald
colors['color_04'] = '#7FC026'; // light green
colors['color_05'] = '#009D00'; // Green
colors['color_06'] = '#DAC301'; // Mustard
colors['color_07'] = '#F09B16'; // Light Orange
colors['color_08'] = '#FF7602'; // Orange
colors['color_09'] = '#FF88CD'; // Light Pink
colors['color_10'] = '#E12D88'; // Dark Pink
colors['color_11'] = '#BB3734'; // Dark Red
var colorBody = "";

$(function() {
	$(".clickable").css({
		"cursor": "pointer"
	}).click(function() {
		document.location.href = $(this).attr("title");
	}); // Terms conditions click handler function
	$('.tc').bind("click", function() {
		$(this).next("div").slideToggle("fast");
	}).next("div").hide(); // Expandable questions
	var cssOff = {
		"font-weight": "normal"
	};
	var cssOn = {
		"font-weight": "bold"
	};
	
	$('.expandable-question').next("div").hide();
	
	$('li.list-expandable').addClass('plusimageapply');
	
	$('.expandable-question').bind("click", function() {
													 
		if ($(this).next("div").is(":visible")) {
			
			$(this).css(cssOff).next("div").slideUp("slow");
			$(this).parent('li.list-expandable').removeClass('minusimageapply');
			$(this).parent('li.list-expandable').addClass('plusimageapply');
		} else {
			$(this).css(cssOn).next("div").slideDown("slow");
			$(this).parent('li.list-expandable').removeClass('plusimageapply');
			$(this).parent('li.list-expandable').addClass('minusimageapply');
		}
	});
	$('input[type="radio"],input[type="checkbox"]').css({
		"border": "0",
		"padding": "0"
	}); 
	$("a.hasSubnav").hover(function() { //When trigger is clicked...  
		//Following events are applied to the subnav itself (moving subnav up and down)  
		$(this).parent().find("ul.tertiary").fadeIn("fast"); //Drop down the subnav on click  
		$(this).parent().hover(function() {}, function() {
			$(this).parent().find("ul.tertiary").fadeOut('fast'); //When the mouse hovers out of the subnav, move it back up  
		}); //Following events are applied to the trigger (Hover events for the trigger)  
	}).hover(function() {
		$(this).addClass("subhover"); //On hover over, add class "subhover"  
	}, function() { //On Hover Out  
		$(this).removeClass("subhover"); //On hover out, remove class "subhover"  
	});
	var x = Math.floor(Math.random() * 11) + 1; // numero casuale da 1 a 11 (compresi)
	var n = (x < 10 ? ("0" + x) : x);
	colorBody = "color_" + n;
	colorize(colorBody, n); //$("body").addClass(colorBody);
	$("input.js_FocusInput").each(function() {
		$(this).attr("mask", $(this).val());
	});
	$("input.js_FocusInput").focus(function() {
		if ($(this).val() == $(this).attr("mask")) {
			$(this).val("");
		}
	});
	$("input.js_FocusInput").blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this).attr("mask"));
		}
	});
	setLozengeBackgrounds(colorBody);
	$('.update_Text_Color').each(function() {
		var t = $('.usp2:first').css("backgroundColor");
		$(this).css("color", t);
	});
	$('.int_trk').bind({
		click: function() {
			//console.log($(this));
			var _category = "Internal Links";
			var _event = "Click";
			var _label = typeof $(this).attr("title") != 'undefined' && $(this).attr("title") != '' ? $(this).attr("title") : $(this).attr("href");
			_gaq.push(['_trackEvent', _category, _event, _label]);
		}
	});
});

function colorize(colorBody, n) {
	var bg_els = ['.box_Offerta .box_Main', 'div.panel_Controls ul li', 'ul.tabs li', 'div.usp5', 'div.usp2', 'div.promo', '.box_Sidebar .box_Menu .box_Content .box_Main', '.list_Menu_Main li.li_Selected .box_Menu_First', '.list_Menu_Main li .box_Sub_Menu .box_Main', '.list_Menu_Top li.li_Selected .box_Menu_First', 'a.link_Buy .ico_Icon', 'ul.tabify li', '.tab_Plans .link_Apri_Dettaglio', '.tab_Plans .view_plan_details', '.tab_Plans .btn_Aggiungi_Offerta', '.tab_Plans .link_Shop', '.hover .box_Menu_First', '.tab_Services th', '.box_Form_Search', '.arrow_Link *', '.usp_content', '.three_recommends', '.bg_color', 'h3.widget-title','h4.clickable_Heading','div.priceplan_mrc','.ui-widget-header'];
	var bg_2_els = ['.list_Menu_Main li:hover', '.box_Menu_First'];
	var font_els = ['div.usp5', 'div.usp2', '.box_FreeHtml div.usp2 h3', 'div.usp2 h3 a', 'div.usp2 p a'];
	var hover_els = ['div.box_Menu_First div:hover'];
	var text_els = ['p.telesales span'];
	for (i in font_els) {
		var $c = font_els[i];
		$($c).css({
			"color": "#FFF"
		});
	}
	for (i in bg_els) {
		var $c = bg_els[i];
		$($c).css({
			"backgroundColor": colors[colorBody]
		});
	}
	for (i in text_els) {
		var $c = text_els[i];
		$($c).css({
			"color": colors[colorBody]
		});
	}
	
	$('.body_color').css({
		"color": colors[colorBody]
	});
	$('.ico_Novita').css('background-image', 'url(/imgs/ico_Novita_' + n + '.png);');
} /* ATTENZIONE: se si utilizza Uniform, ogni volta che si apporta una modifica alle caratteristiche di un elemento 
(per esempio, se si sostituiscono le entries di una select o se si cambia il valore selezionato via javascript), a valle della modifica bisogna richiamare il metodo di update di Uniform
tramite la seguente istruzione:
$.uniform.update();
*/
/* MENU	*/


function initMenu() {
	var origColor;
	var origText;
	$('div.box_Main ul.list_Sub_Menu.list_SubMenu_03_Items.js_sIFR_Sub_Menu li').removeClass('li_First'); // Added 2nd June 2011 - colorize 
	$('.js_SubMenu, .list_Menu_Main li.li_First').live("mouseenter", function(event) {
		origColor = $(this).css("backgroundColor");
		origText = $(this).css("color");
		$(this).css({
			"backgroundColor": colors[colorBody],
			"color": "#FFF"
		}); //$(this).find(".js_SubMenu_Container").fadeIn("fast").css({'z-index': 999});
		$(this).find(".js_SubMenu_Container").show().css({
			'z-index': 999
		}); /*		if (!$(this).hasClass("li_Selected")) {
			sIFR.getReplacementByFlashElement($(this).find(".box_Menu_First object")[0]).changeCSS( 
			[
				'.sIFR-root {color: #FFFFFF; font-size: 16px; font-weight: bold; white-space: nowrap; background-color: transparent;}'
				,'a {text-decoration: none;}'
				,'a:link {color: #FFFFFF;}'
				,'a:hover {color: #FFFFFF; cursor: pointer;}'
			]);
		}*/
	});
	$('.js_SubMenu, .list_Menu_Main li.li_First').live("mouseleave", function(event) {
		$(this).css({
			"backgroundColor": origColor,
			"color": origText
		}); //$(this).find(".js_SubMenu_Container").fadeOut("fast").css({'z-index': 1});
		$(this).find(".js_SubMenu_Container").hide().css({
			'z-index': 1
		}); /*		if (!$(this).hasClass("li_Selected")) {
			sIFR.getReplacementByFlashElement($(this).find(".box_Menu_First object")[0]).resetMovie();
			sIFR.getReplacementByFlashElement($(this).find(".box_Menu_First object")[0]).changeCSS( 
			[
				'.sIFR-root {color: #999999; font-size: 16px; font-weight: bold; white-space: nowrap; background-color: transparent;}'
				,'a {text-decoration: none;}'
				,'a:link {color: #999999;}'
				,'a:hover {color: #FFFFFF; cursor: pointer;}'
			]);
		}*/
	});
}
if ($.browser.msie && $.browser.version.substr(0, 1) == '6') {
	$(function() {
		$('.list_Menu_Main li').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
		
		
		
	});
} /* OPEN a SLIDING BOX	*/
$('.js_Description_Opener').live("click", function() {
	$(this).parents(".js_Description").find(".js_Description_Container").slideToggle("slow");
	$(this).parents(".js_Description").find(".js_Description_Opener").toggleClass("Selected");
});
$(".js_Description_Opener_Multi").live("click", function(event) {
	var title_Opened = "Chiudi i dettagli";
	var text_Opened = "chiudi i dettagli";
	var title_Closed = "Scopri i dettagli";
	var text_Closed = "scopri i dettagli"; // Variabili per il box Services
	if ($(this).parents(".box_Services").size() > 0) {
		title_Opened = "Nascondi gli altri operatori";
		text_Opened = "nascondi gli altri operatori";
		title_Closed = "Scopri gli altri operatori";
		text_Closed = "scopri gli altri operatori";
	}
	var visible = $(this).parents(".js_Description").find(".js_Description_Container").is(":visible");
	var myThis = this;
	if (visible) { // shown -> hidden
		$(this).parents(".js_Description").find(".js_Description_Container").slideUp("slow", function() {
			$(myThis).parents(".js_SuperParent").find(".js_Description").css({
				height: ''
			});
		});
		$(this).removeClass("Selected").attr("title", title_Opened).find("span:eq(0)").html(text_Closed);
	} else { // hidden -> shown
		var origLiH = $(this).parents(".js_Description").height();
		$(this).parents(".js_SuperParent").find(".js_Description_Container:visible").slideUp("slow");
		$(this).parents(".js_Description").find(".js_Description_Container").slideDown("slow", function() {
			var containerH = $(myThis).parents(".js_Description").find(".js_Description_Container").height();
			var liH = $(myThis).parents(".js_Description").height(); //if (liH < containerH) {
			if (liH == origLiH) { // IE6: non viene aggiornata automaticamente la dimensione del container
				$(myThis).parents(".js_Description").css({
					height: (containerH + liH + 20) + 'px'
				}); // 20px padding top + bottom
				$(myThis).parents(".js_Description").prevAll(".js_Description").css({
					height: ''
				});
				$(myThis).parents(".js_Description").nextAll(".js_Description").css({
					height: ''
				});
			}
		});
		$(this).parents(".js_SuperParent").find(".js_Description_Container:visible").parents(".js_Description").find(".js_Description_Opener_Multi").removeClass("Selected").attr("title", title_Closed).find("span:eq(0)").html(text_Closed);
		$(this).addClass("Selected").attr("title", title_Opened).find("span:eq(0)").html(text_Opened);
	}
}); /* OPEN POPUP	*/


function openPopup(url, name, w, h, s) { // Fudge factors for window decoration space.
	// In my tests these work well on all platforms & browsers.
	w += 0;
	h += 0;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2; // IE5 and other old browsers might allow a window that is
	// partially offscreen or wider than the screen. Fix that.
	// (Newer browsers fix this for us, but let's be thorough.)
	if (wleft < 0) {
		w = screen.width;
		wleft = 0;
	}
	if (wtop < 0) {
		h = screen.height;
		wtop = 0;
	}
	if (s == undefined) {
		s = "no";
	}
	var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=' + s + ', resizable=no');
	win.focus();
}
function activate(id) {
	$('#' + id).addClass("active");
	$('#' + id).parent().parent().parent().find("a:first").addClass("active");
}
function getQuerystring(key, default_) {
	if (default_ == null) default_ = "";
	key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
	var qs = regex.exec(window.location.href);
	if (qs == null) return default_;
	else return qs[1];
}
function changeBg() {
	return;
}
function openCoverageWin() {
	var w = 820;
	var h = 500;
	var l = parseInt((screen.availWidth / 2) - (w / 2));
	var t = parseInt((screen.availHeight / 2) - (h / 2));
	var fe = "width=" + w + ",height=" + h + ",status,scrollbars=auto,resizable,left=" + l + ",top=" + t + "screenX=" + l + ",screenY=" + t;
	var g = window.open('http://bing.bizmaps.ie/threeireland/Pages/Public/CoveragePublicPage.aspx', 'coverageWin', fe);
	g.focus();
}
function openNBSCoverageWin() {
	var w = 754;
	var h = 433;
	var l = parseInt((screen.availWidth / 2) - (w / 2));
	var t = parseInt((screen.availHeight / 2) - (h / 2));
	var fe = "width=" + w + ",height=" + h + ",status,scrollbars=auto,resizable,left=" + l + ",top=" + t + "screenX=" + l + ",screenY=" + t;
	var g = window.open('http://bing.bizmaps.ie/threeireland/Pages/Public/NBSPublicPage.aspx', 'coverageNBSWin', fe);
	g.focus();
}
function openCoverageWin() {
	var w = 820;
	var h = 500;
	var l = parseInt((screen.availWidth / 2) - (w / 2));
	var t = parseInt((screen.availHeight / 2) - (h / 2));
	var fe = "width=" + w + ",height=" + h + ",status,scrollbars=auto,resizable,left=" + l + ",top=" + t + "screenX=" + l + ",screenY=" + t;
	var g = window.open('http://bing.bizmaps.ie/threeireland/Pages/Public/CoveragePublicPage.aspx', 'coverageWin', fe);
	g.focus();
}
function openNBSCoverageWin() {
	var w = 820;
	var h = 500;
	var l = parseInt((screen.availWidth / 2) - (w / 2));
	var t = parseInt((screen.availHeight / 2) - (h / 2));
	var fe = "width=" + w + ",height=" + h + ",status,scrollbars=auto,resizable,left=" + l + ",top=" + t + "screenX=" + l + ",screenY=" + t;
	var g = window.open('http://bing.bizmaps.ie/threeireland/Pages/Public/NBSPublicPage.aspx', 'coverageNBSWin', fe);
	g.focus();
}
function setLozengeBackgrounds(color) {
	var pos = "0 0";
	var cArray = new Array(); //
	var start = 0;
	var increments = -100;
	cArray['color_00'] = "0 0";
	cArray['color_01'] = "-100px 0";
	cArray['color_02'] = "-200px 0";
	cArray['color_03'] = "-300px 0";
	cArray['color_04'] = "0 -100px";
	cArray['color_05'] = "-100px -100px";
	cArray['color_06'] = "-200px -100px";
	cArray['color_07'] = "-300px -100px";
	cArray['color_08'] = "0 -200px";
	cArray['color_09'] = "-100px -200px";
	cArray['color_10'] = "-200px -200px";
	cArray['color_11'] = "-300px -200px";
	for (var i in cArray) { //alert('key is: ' + i + ', value is: ' + myArray[i]);
		if (i == color) {
			pos = cArray[i];
		}
	} //console.log($('body').attr("class"));
	$('.feature-lozenge').css({
		backgroundPosition: pos
	});
	
	var isMSIE = /*@cc_on!@*/0;

		if (isMSIE) {
			// do IE-specific things
				$(function() {
						var zIndexNumber = 1000;
						$('.box_Header').each(function() {
						$(this).css('zIndex', zIndexNumber);
						zIndexNumber -= 10;
					});
						$('<!--[if lt IE 7 ]> <html lang="en" class="ie6 no-js"> <![endif]-->').appendTo('head'); 
			});
		} 
}


