﻿var num = 1;
var img = 1;
var imageNumber = 0;
var highlightSources = new Array();
var highlightLinks = new Array();
var highlightLocks = new Array();
var highlightNumberLocks = new Array(false,false,false);

function setCookie(c_name,value,exdays){
	
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString() +"; path=/");
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name)
		{
			return unescape(y);
		}
	}
}

function deleteCookie(c_name)
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = c_name += "=; expires=" + cookie_date.toGMTString();
}

var volumeMuted = getCookie("volumeMuted");
if( volumeMuted == undefined || volumeMuted == null || volumeMuted == "false"){
	volumeMuted = false;
	setCookie("volumeMuted", volumeMuted, 1);
}
else if(volumeMuted == "true")
{
	volumeMuted = true;
	setCookie("volumeMuted", volumeMuted, 1);
}
	
function changeHighlights() {
    if (!highlightNumberLocks[num - 1]) {
        if ($.browser.msie && $.browser.version <= 8) {
            $("#destaque" + num + "_link").attr("href", highlightLinks[img - 1]);
            $("#destaque" + num).hide(0, function () {
                $(this).attr("src", highlightSources[img - 1]);
                $(this).show();
                num++;
                img++;
                if (num > 3)
                    num = 1;
                if (img > highlightSources.length)
                    img = 1;

                setTimeout("changeHighlights()", 5000);
            });
        }
        else {
            $("#destaque" + num + "_link").attr("href", highlightLinks[img - 1]);
            $("#destaque" + num).fadeOut(500, function () {
                $(this).attr("src", highlightSources[img - 1]);
                $(this).fadeIn(500);
                num++;
                img++;
                if (num > 3)
                    num = 1;
                if (img > highlightSources.length)
                    img = 1;

                setTimeout("changeHighlights()", 5000);
            });
        }
    }
    else {
        num++;
        if (num > 3)
            num = 1;
        if (highlightSources.length > 0 && (!highlightNumberLocks[0] || !highlightNumberLocks[1] || !highlightNumberLocks[2]))
            changeHighlights();
    }
}

$(document).ready(function () {
	
    /* images mouse over & out */
    $(".hover").mouseover(function () {
        var name = $(this).attr("src");
		var getExt = name.split(".");
		var ext = getExt[getExt.length -1];
        name = name.replace("_on."+ext, "."+ext);
        name = name.replace("."+ext, "_on."+ext);
        $(this).attr("src", name);
    }).mouseout(function () {
        var name = $(this).attr("src");
		var getExt = name.split(".");
		var ext = getExt[getExt.length -1];
        name = name.replace("_on."+ext, "."+ext);
        $(this).attr("src", name);
    });

    $('#TxtUsername').focus(function () {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
        }
    }).blur(function () {
        if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
        }
    });

    $('#TextPass').focus(function () {
        if ($(this).val() == $(this).attr("title")) {
            $(this).css("display", "none");
        }
    })
    $('#TxtPassword').blur(function () {
        if ($(this).val() == "") {
            $('#TextPass').css("display", "block");
        }
    });

    if ($(".ItemA") != null) {
        $(".ItemA").mouseover(function () {
            $(this).addClass("ItemAOver");
        }).mouseout(function () {
            $(this).removeClass("ItemAOver");
        });
    }


    $(".menuItem").mouseover(function () {
        $(this).stop();
        $(this).css("line-height", "50px");
        if ($(this).hasClass('over1'))
            $(this).addClass("blue");
        if ($(this).hasClass('over2'))
            $(this).addClass("lblue");
        if ($(this).hasClass('over3'))
            $(this).addClass("green");
        if ($(this).hasClass('over4'))
            $(this).addClass("gray");
        $(this).animate({
            fontSize: "14px",
            lineHeight: "42px",
            color: "#ffffff"
        }, 300);
    });

    $(".menuItem").mouseout(function () {
        $(this).stop();
        $(this).css("line-height", "36px");
        if ($(this).hasClass('over1'))
            $(this).removeClass("blue");
        if ($(this).hasClass('over2'))
            $(this).removeClass("lblue");
        if ($(this).hasClass('over3'))
            $(this).removeClass("green");
        if ($(this).hasClass('over4'))
            $(this).removeClass("gray");
        $(this).animate({
            fontSize: "12px",
            lineHeight: "42px",
            color: "#bdbdbd"
        }, 300);
    });


    // Homepage

    if (highlightSources != null && highlightSources.length > 0) {
        imageNumber = highlightSources.length;
        for (var i = 0; i < highlightSources.length; i++) {
            if (highlightLocks[i] == "Esquerda" && !highlightNumberLocks[0]) {
                $("#destaque1").attr("src", highlightSources[i]);
                $("#destaque1_link").attr("href", highlightLinks[i]);
                highlightNumberLocks[0] = true;

                highlightLinks.splice(i, 1);
                highlightLocks.splice(i, 1);
                highlightSources.splice(i, 1);
                i--;
            }
            else if (highlightLocks[i] == "Centro" && !highlightNumberLocks[1]) {
                $("#destaque2").attr("src", highlightSources[i]);
                $("#destaque2_link").attr("href", highlightLinks[i]);
                highlightNumberLocks[1] = true;

                highlightLinks.splice(i, 1);
                highlightLocks.splice(i, 1);
                highlightSources.splice(i, 1);
                i--;
            }
            else if (highlightLocks[i] == "Direita" && !highlightNumberLocks[2]) {
                $("#destaque3").attr("src", highlightSources[i]);
                $("#destaque3_link").attr("href", highlightLinks[i]);
                highlightNumberLocks[2] = true;

                highlightLinks.splice(i, 1);
                highlightLocks.splice(i, 1);
                highlightSources.splice(i, 1);
                i--;
            }

        }

        for (var i = 0; i < 3; i++) {
            if (!highlightNumberLocks[i]) {
                var elementNumber = i + 1;
                if (highlightSources.length > i) {
                    $("#destaque" + elementNumber).attr("src", highlightSources[img - 1]);
                    $("#destaque" + elementNumber + "_link").attr("href", highlightLinks[img - 1]);
                    img++;
                }
                else
                    $("#destaque1").css("visibility", "hidden");
            }
        }

        $(".destaqueIMG").mouseover(function () {
            $(this).addClass("opacity");
        });

        $(".destaqueIMG").mouseout(function () {
            $(this).removeClass("opacity");
        });

        if (imageNumber > 3) {
            setTimeout("changeHighlights()", 5000);
        }
    }
    else {
        $("#destaque1").hide();
        $("#destaque2").hide();
        $("#destaque3").hide();
    }

    if ($("#BannerSlideshow") != null) {
        ResetSlideShow();
    }
});





/********************************************************************************
** Slideshow Controls START
********************************************************************************/
var currentSlide = null;
var timeoutSlideshow = null;
var slideshowItems = null;
function ResetSlideShow() {
	slideshowItems = new Array();
    $("img,.swfSlideshow" , "#BannerSlideshow").each(function (i, element) {
		if($(this).html() == null || $(this).html() == "")
			slideshowItems.push($(this).parent().html());
		else
		{
			var dataTime = ($(this).attr("data-time") == undefined || $(this).attr("data-time") == null || $(this).attr("data-time") == "") ? "00:05" : $(this).attr("data-time");
			slideshowItems.push("<div class='swfSlideshow' data-time="+dataTime+">"+$(this).html()+"</div>");
		}	
		$(this).remove();
		if($("#BannerSlideshow").children().length == 0)
			SlideShow();
	});
}
function SlideShow() {
    var maxChildren = slideshowItems.length;
	
	if(currentSlide == null)
		currentSlide = 0;
	else
		currentSlide = (currentSlide + 1 >= maxChildren) ? 0 : currentSlide + 1;
	
	$("#BannerSlideshow").html(slideshowItems[currentSlide]);


    $("#BannerSlideshowBullets").children().each(function (i, element) {
        if (i == currentSlide)
            $(this).attr("src", "/images/bullet_over.png");
        else
            $(this).attr("src", "/images/bullet.png");
    });
	var currentElement = $("#BannerSlideshow").children(":first");
	var time = (currentElement != undefined && currentElement != null && $(currentElement).attr("data-time") != null) ? $(currentElement).attr("data-time") : 5000;
	if(time != 5000)
	{
		time = time.split(":");
		time = (parseInt(time[0])*60 + parseInt(time[1]))*1000;
	}
    if (maxChildren > 0)
        timeoutSlideshow = setTimeout("SlideShow()", time);
}
function GoToSlide(i) {
    if (i != currentSlide) {
        currentSlide = i;
        clearTimeout(timeoutSlideshow);
        var maxChildren = slideshowItems.length;
		currentSlide = i;
		
		$("#BannerSlideshow").html(slideshowItems[currentSlide]);
		
        $("#BannerSlideshowBullets").children().each(function (i, element) {
            if (i == currentSlide)
                $(this).attr("src", "/images/bullet_over.png");
            else
                $(this).attr("src", "/images/bullet.png");
        });
		var currentElement = $("#BannerSlideshow").children(":first");
		var time = (currentElement != undefined && currentElement != null && $(currentElement).attr("data-time") != null) ? $(currentElement).attr("data-time") : 5000;
		if(time != 5000)
		{
			time = time.split(":");
			time = (parseInt(time[0])*60 + parseInt(time[1]))*1000;
		}
		if (maxChildren > 0)
			timeoutSlideshow = setTimeout("SlideShow()", time);
    }
}
/********************************************************************************
** Slideshow Controls END
********************************************************************************/

/********************************************************************************
** Slideshow Volume START
********************************************************************************/

function setVolume( status ){
	volumeMuted = status;
	setCookie("volumeMuted", status , 1);
}

function getVolume(){
	return volumeMuted;
}

/********************************************************************************
** Slideshow Volume END
********************************************************************************/
