//Handling testi camillo
function showTextCamillo(arg)
{
	if (arg)
	{
		$(".camillo_storia_text").hide();
		$("#"+arg).show();
	}
}

//Funzione che apre un div e chiude tutti gli altri
function THISonTHAToff(code) 
{
    ff = document.getElementsByTagName("div");
    for (i = 0; i < ff.length; i++) {
        if (ff[i].id.substr(0,5)=="onOff") {
            ff[i].style.display = "none";
        }
    }   
    for (i = 0; i < ff.length; i++) {
        if (ff[i].id == code) {
            if (ff[i].style.display == "none") {
                ff[i].style.display = "";
            }
        }
    }
}

//Filtra il nome dello sfondo
function cleanBackground(backgroundName)
{
	return backgroundName.replace('s_', '').replace('.jpg','').replace('"','');
}

//Funzione che apre e chiude un div cliccando sul link
function THISonTHISoff(code) 
{
    ff = document.getElementById(code);
		if (ff.style.display == "") {
			ff.style.display = "none";
		} else
		if (ff.style.display == "none") {
			ff.style.display = "";
		}
}

//Funzione che apre la popup
function Popup(url, stile) 
{
	window.open(url, "", stile);
}
	
//Cambia classe
function classChange(element,newclass) 
{
     document.getElementById(element).className = newclass;
}

//Funzione per recuperare i parametri in querystring
jQuery.query = function(s) {
     var r = {};
     var q = s.substring(s.indexOf('?') + 1); 
     q = q.replace(/\&$/, '');
     jQuery.each(q.split('&'), function() {
         var splitted = this.split('=');
         var key = splitted[0];
         var val = splitted[1];
         if (/^[0-9.]+$/.test(val)) val = parseFloat(val);
         if (typeof val == 'number' || val.length > 0) r[key] = val;
     });
     return r;
}; 

/* 
* Controlla se alla chiamata del file ci sono parametri e se siamo nella pagina news
* espande la news corrispondere all' ID specificato
*/

$(document).ready(function() {

    if ($("#surveyOverlay").length) {
			var urlCorrente = new String(document.location);
	
        if ((urlCorrente.indexOf('http://www.fila.it') > -1) ||
            urlCorrente == 'http://fila.local/' ||
            urlCorrente == '~/') 
		{
		    var cookie = readCookie("SURVEY");
			if (cookie == null) 
			{
				$("#surveyOverlay").show();
			}
        }
    }
	
	
    //Check cookie
    var cookie = readCookie("SURVEY");
    if (cookie != null) {
        $("#surveyBanner").hide();
        $("#surveyOverlay").hide();
    }

    if (location.href.indexOf("/news.shtml") > 0) {
        var newsId = $(document).getUrlParam("newsId");
        if (newsId != null) {
            $("#news_" + newsId).show();
            var nextElement = $("#news_" + newsId).next();
            nextElement.addClass("prova");
            nextElement.html("<span>" + nextElement.attr('titleOpened') + "</span>");
        }
    }


    //SURVEY	

    /*$("#surveyBannerClose").click(function () {
    $(this).parent().remove()
    return false;
    });*/


    $("#surveyBannerClose").click(function() {
        $(this).parent().slideToggle('slow')
        return false;
    });


    $("#surveyOverlayClose").click(function() {
        $(this).parent().remove()
        return false;
    });

    $("#surveyOverlaySecondaryCTA").click(function() {
        $("#surveyOverlay").remove();
        createCookie("SURVEY", 1, "")
        return false;
    });






    //Mostra tutta la news

    $(".btn_action").click(function() {
        var previousElement = $(this).prev();
        if ($(this).attr("href") == "#a") {
            //Show
            if (previousElement.is(":hidden")) {
                previousElement.slideDown("normal");
                $(this).addClass("prova");
                $(this).html("<span>" + $(this).attr('titleOpened') + "</span>");
            }
            //Hide
            else {
                previousElement.slideUp("normal");
                $(this).removeClass("prova");
                $(this).html("<span>" + $(this).attr('titleClosed') + "</span>");
            }
        }
    });


    //Mostra il partner

    $(".partner_btn").click(function() {
        var nextElement = $(this).next();
        if ($(this).attr("href") == "#b") {
            //Show
            if (nextElement.is(":hidden")) {
                nextElement.slideDown("normal");
                $(this).addClass("prova");

            }
            //Hide
            else {
                nextElement.slideUp("normal");
                $(this).removeClass("prova");

            }
        }
    });




    /* Funzioni partner di Jquery PrettyPhoto  */

    $(".btnModal").click(function() {
        var objType = $(this).attr("type");

        //Type GALLERY
        if (objType == "pics") {
            var galleryName = $(this).attr("id");
            $.get('/eventi/gallery/getPictures.ashx', { folder: galleryName }, function(data) {
                if (data != "" || data.length != 0) {
                    $("#gallery").html(data);
                    $("a[rel^='prettyPhoto']").prettyPhoto();
                    $("#gallery a:first").click();
                }
                else
                    $("#gallery").html("No pictures found on requested gallery!").show();
            });
        }

        //Type VIDEO YOUTBE
        if (objType == "videoyoutube") {
            var videoName = $(this).attr("id");
            if (videoName != "") {
                var htmlContainer = "<a href=\"" + videoName + "\" rel=\"prettyPhoto[flash]\" title=\"\"></a>";
                $("#gallery").html(htmlContainer);
                $("a[rel^='prettyPhoto']").prettyPhoto();
                $("#gallery a:first").click();
            }
            else
                $("#gallery").html("No video specified!").show();
        }

        //Type VIDEO CUSTOM
        if (objType == "videocustom") {
            var videoName = $(this).attr("id");
            var htmlContainer = "<a href='flv_player_hp.swf?flv=\"+videoName+\"&width=580&height=326' rel=\"prettyPhoto[flash]\"></a>";
            $("#gallery").html(htmlContainer);
            $("a[rel^='prettyPhoto']").prettyPhoto();
            $("#gallery a:first").click();
        }

    });



    $('.aSanna_video .mediaList div').hover(function() {
        $(this).addClass('current');
    }, function() {
        $(this).removeClass('current');
    });



 
    if ($('#browsable').size() > 0) {
        $("#browsable").scrollable({ size: 1 }).navigator();
    }

  


    if ($(".cover").size() > 0) {
        //$('.jqtransform').jqTransform({imgPath:'gfx/jqtransformplugin'});
        $(".cover img").reflect({ height: 0.1, opacity: 0.5 });
        $(".reflect").reflect({ height: 0.1, opacity: 0.5 });
    }





    if ($('.jqtransform').size() > 0) {
        $('.jqtransform').jqTransform({ imgPath: 'gfx/jqtransformplugin' });
    }
    else {

    }
    if ($(".cover").size() > 0) {
        function coverImg() {
            $(".cover img").reflect({ height: 0.1, opacity: 0.5 });
        }
    }







    /* Pretty photo e pannello modifica sfondo */

    try {
        //$("a[rel^='prettyPhoto']").prettyPhoto();

        //test
        $(".btn_modificaSfondo").click(function() {
            $(this).animate({ top: "-50px", width: "118px" }, 500);

            $(".panel_modificaSfondo").animate({ opacity: 1.0 }, 500).animate({ top: "0", right: "0" }, 700);
        });

        $("#closeme").click(function() {
            $(".panel_modificaSfondo").animate({ top: "-276px", right: "0" }, 700);
            $(".btn_modificaSfondo").animate({ opacity: 1.0 }, 700).animate({ top: "0", width: "118px" }, 500);
        });
    }
    catch (e) {

    }



    /* A SCUOLA TAB */
    if ($('ul.tabs').size() > 0) {
        $("ul.tabs").tabs("div.panes > div");
    }

    if ($('a.thumb_scuola_concorso_dea_gallery').size() > 0) {
        $('a.thumb_scuola_concorso_dea_gallery').cluetip({
            activation: 'hover',
            clickThrough: true
        });
    }


    /* SCROLL PARTNER HP */
    if ($('.scrollablePartner').size() > 0) {
         $(".scrollablePartner").scrollable({ circular: true }).autoscroll({ autoplay: true });
    }


});


/* Eventi Archivio */
function hideNodes(element) 
{
	var n = element;
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	if (n.style.display=="none") n.style.display="block";
	else n.style.display = "none";
}



//Crea il cookie
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

//Legge il cookie
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

//Cancella il cookie
function eraseCookie(name) {
    createCookie(name, "", -1);
}


