/*--------------------------------------------------
input
--------------------------------------------------*/
function input(){
 $("input:text").focus(function(){
 if ($(this).val() == $(this).attr("title")){
 $(this).val("");
 }
}).blur(function(){
 if ($.trim($(this).val()) == ""){
 $(this).val($(this).attr("title"));
 }
 });
} 

/*--------------------------------------------------
Backgrounde Random
--------------------------------------------------*/
function bgFadeRandom() {
var randomImages = ['bg1','bg2','bg3','bg4','bg5'];
var rndNum = Math.floor(Math.random() * randomImages.length);
$("#wrap_bg").css({background: "url(img/" + randomImages[rndNum] + ".jpg) no-repeat top center" });
}

/* Background Fade
- - - - - - - - - - - - - - - - - - - - */
function bgFade(isInit) {
	alert ("ciao");
    winWidth = $(window).width();
    var imgRel;
    var imgEq;
    var imgHeight;
    var imgUrl;
    $("#wrap_bg>div").each(function () {
        imgRel = $(this).attr("rel")
        if (winWidth <= 1024) {
            imgHeight = 397;
            imgEq = 0;
        } else if (winWidth >= 1024 && winWidth < 1440) {
            imgHeight = 558;
            imgEq = 1;
        } else if (winWidth >= 1440) {
            imgHeight = 744;
            imgEq = 2;
        }
        imgUrl = $("#bg-img>div[rel=" + imgRel + "] span:eq(" + imgEq + ")").text();
        $(this).css({ "background": "url(" + imgUrl + ") no-repeat center top" });
        $("#wrap_bg>div").css({ "width": winWidth + "px", "height": imgHeight + "px" });
        $("#head").css({ "min-height": imgHeight + "px" });
    });
}

function fadeCycle() {
    $('#wrap_bg').cycle({
        fx: 'fade',
        speed: 900,
        timeout: 10000,
        before: onBefore
    });
/*    function onBefore() {
        if ($("#etichetta span").text() != this.title) {
            var title = this.title;
            $("#etichetta span").animate({
                opacity: 0
            }, 900, function () {
                $(this).text(title).css({ opacity: 1 })
            });*/
        }

/* alignColHeight */
function alignColHeight() {
	/*if($("#box2").height() > $(".box").height()){
		$(".wrap_col_sx_center").height(($("#col_dx").height()-10));
	} else {
		$("#col_dx").height($("#col_sx").height());
	}*/
	var maxH = 0;
	$("#wrap_blocchetti .box").each(function(){
		maxH = ($(this).height() > maxH) ? $(this).height() : maxH;
	});
	$("#wrap_blocchetti .box").css({height:maxH+"px"});
}

function alignColHeight2() {
	if($(".box_radio").height() > $(".box_radio.ultimo").height()){
		$(".box_radio").height(($(".box_radio.ultimo").height()));
	} else {
		$(".box_radio").height($(".box_radio.ultimo").height());
	}
}

function tabella() {
	$('.scorri_tabella tr:odd').addClass('pari');
}

// select transform
function beautifySelect() {
    $("div.select").each(function() {
        $(this).append('<span class="select close"><span style="width: 262px; overflow: hidden">' + $(this).find("option:selected").html() + '</span></span>')
                                   .find("select")
                                       .css({ opacity: 0 })
                                       .change(function() {
                                           $(this).parent().find("span.select span").html($(this).find(':selected').html());
                                       });
    })
};

$(document).ready(function(){
	bgFadeRandom();
	input();
	alignColHeight();
	alignColHeight2();
	//randomBg()
	//bgFade();
	//fadeCycle();
	tabella();
	beautifySelect();
	$("#offerte_hp .scrollable").scrollable({vertical:false, 
			   size:3, 
			   prev:'.prev', 
			   next:'.next', 
			   loop: false,
			   alert: false,
			   autopause: true,});
	//$('.scorri_tabella td:eq(1n)').addClass('pari');
});

$(window).load(function(){
	alignColHeight();
});


