

var wwwRoot = '/portals/younique20/';

$(document).ready(function() {

    $('.zoom').fancybox();
    // PNG FIX
    $('img').ifixpng();
    $(".png").ifixpng();

    // RIQUADRI ESPANDIBILI
    $("div.riquadroEspandibile").each(function() {
        $(this).children("h2").each(function() {
            $(this).attr("title", "espandi");
        });
        $(this).children("h2").click(function() {

            $(this).toggleClass("opened");
            if ($(this).attr("title") == "chiudi") { $(this).attr("title", "espandi"); } else { $(this).attr("title", "chiudi"); }
            $(this).siblings("div.contenutoRiquadro").toggle();
        });
    });


    /* POPIN AUTORI */
    $(".popinAuthor a.chiudi").click(function() {
        $.fancybox.close()
    });

    $("a.linkPopinAuthor").fancybox({
        showCloseButton: false,
        overlayOpacity: 0.5,
        overlayColor: '#000'
    });
    /* FINE POPIN AUTORI */

    return;

    /* INIZIALIZZAZIONE MENU */
    $('#top #menu li').each(function() {

        idMenu = $(this).attr('id').replace('menu_', '');
        jQuery("a", this).css('background-image', 'url(' + wwwRoot + 'images/MENU_' + idMenu + '.jpg)');
        jQuery("a", this).html('');
    })
    $('#top #menu li:first-child').css('margin-left', '0px');
    /* FINE INIZIALIZZAZIONE MENU */


    /* INIZIALIZZAZIONE CAMPI BGSWAP */
    $('input.bgSwap').each(function() {

        classSpan = $(this).parent().attr('class');
        value = $(this).val();

        if (value == '') {
            $(this).css('background-image', 'url(' + wwwRoot + 'images/bg' + ucfirst(classSpan) + 'On.gif)');
        }
        else {
            $(this).css('background-image', 'url(' + wwwRoot + 'images/bgInputOff.gif)');
        }

    })

    $('input.bgSwap').focus(function() {

        classSpan = $(this).parent().attr('class');

        $(this).css('background-image', 'url(' + wwwRoot + 'images/bgInputOff.gif)');

    }).blur(function() {

        classSpan = $(this).parent().attr('class');

        value = $(this).val();

        if (value == '') {
            $(this).css('background-image', 'url(' + wwwRoot + 'images/bg' + ucfirst(classSpan) + 'On.gif)');
        }
        else {
            $(this).css('background-image', 'url(' + wwwRoot + 'images/bgInputOff.gif)');
        }
    })
    /* FINE INIZIALIZZAZIONE CAMPI BGSWAP */


    /* INIZIALIZZAZIONE FOOTER */
    $('#footer_wrapper #footer div').each(function() {
        idFooter = $(this).attr('class');
        $(this).children('h2').html('<img src="' + wwwRoot + 'images/footer_' + idFooter + '.png">');
    })
    /* FINEINIZIALIZZAZIONE FOOTER */


    // TITOLI GRAFICI
    imgRenderTitle();

    // CHECKBOX
    renderCheckbox();


    // IE6 FIX
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        newsBox();
    }



    /* FANCYBOX IFRAME */
    $(".fancyBoxIframe").fancybox({
        type: 'iframe',
        showCloseButton: false,
        overlayOpacity: 0.5,
        overlayColor: '#000',
        width: 496,
        height: 400
    });
    /* FINE FANCYBOX IFRAME */


    /* FANCYBOX STANDARD */
    $(".fancybox").fancybox({
        overlayOpacity: 0.5,
        overlayColor: '#000'
    });
    /* FINE FANCYBOX STANDARD */





})




function ucfirst (str) {
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}


function imgRenderTitle()
{
	$('[class^="imgRender"]').each(function(){
		typeImage = $(this).attr('class').replace('imgRender_','');
		idImage   = $(this).attr('id');
		$(this).html('<img src="'+wwwRoot+'images/'+idImage+'.jpg">');
	})
}
function renderCheckbox()
{
	$('input[type="checkbox"]').each(function(){
		randomId = 'checkbox_'+Math.floor(Math.random()*999999999999);
		id      = $(this).attr('id');
		id      = $(this).attr('rel',randomId);
		checked = $(this).attr('checked');
		$(this).after('<div class="checkbox" rel="'+randomId+'"></div>');
		if($('input[rel="'+randomId+'"]').attr('checked')==false)
		{
			$(this).css('background-position','0px -12px ');
		}
		else if($('input[rel="'+randomId+'"]').attr('checked')==true)
		{
			$(this).css('background-position','0px 0px');
		}
		$(this).css('display','none');
	});
	
	$('.checkbox').click(function(){
		id = $(this).attr('rel');
		if($('input[rel="'+id+'"]').attr('checked')==false)
		{
			$('input[rel="'+id+'"]').attr('checked',true);
			$(this).css('background-position','0px -12px ');
		}
		else if($('input[rel="'+id+'"]').attr('checked')==true)
		{
			$('input[rel="'+id+'"]').attr('checked',false);
			$(this).css('background-position','0px 0px');
		}
	})
}


function newsBox()
{
	$(".newsBox").each(function(){

		children = ($(this).children('div').size());
		if(children==2)
		{
			widthContentDiv = $(this).css('width').replace('px','')*1-70
			$(this).children('div:first-child').css('width','64px').css('height','64px').css('display','block').css('float','left');
			$(this).children('div:last-child').css('width',widthContentDiv).css('display','block').css('float','left');
			$(this).append('<div class="clear" style="margin-top:-25px;height:1px !important;display:block;"></div>');
		}

	})

}
