/* UNIFORM	*/
$(function(){
	initUniform();
});

function initUniform() {
//	$("select, input:text, input:checkbox, input:radio, input:file").uniform({ 
	$("select, input:text, input:checkbox, input:radio").uniform({ 
		selectClass:   'selector',
		radioClass: 'radio',
		checkboxClass: 'checker',
//		fileClass: 'uploader',
//		filenameClass: 'filename',
//		fileBtnClass: 'action',
//		fileDefaultText: 'nessun file selezionato',
//		fileBtnText: 'Scegli',
		checkedClass: 'checked',
		focusClass: 'focus',
		disabledClass: 'disabled',
		activeClass: 'active',
		hoverClass: 'hover'
	});	
	$("input:text").focus(function(){
		$(this).parents("div.box_Input").addClass("focus");
	}).blur(function(){
		$(this).parents("div.box_Input").removeClass("focus");
	});

	$("input:text").each(function () {
		if (this.disabled) {
			$(this).parents("div.box_Input").addClass("disabled");
		}
	})
}

/* MENU	*/
function initMenu() {
	$('.js_SubMenu').live("mouseenter", function (event) {
		//$(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').live("mouseleave", function (event) {
		//$(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";
	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);
	}
});

/* RANDOM PAGE COLOR	*/
$(document).ready(function() {
	var colorBody = Math.floor(Math.random()*11) + 1; // numero casuale da 1 a 11 (compresi)
	$("body").addClass("color_" + (colorBody < 10 ? ("0" + colorBody) : colorBody));
});

/* REMOVE VALUE FROM js_FocusInput INPUT	*/
$(document).ready(function() {
	$("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"));
		}
	});
});

/* OPEN POPUP	*/
function openPopup(url, name, w, h)
{
  // 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;
  }
  var win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=no, resizable=no');
  win.focus();
}