jQuery(document).ready(function($) {
	
	//$('#homeNews .homeHighlight2ContentWrapperInside').jscroll({duration: 4000});
	//if(!checkIfIE("7")){
	var a = 1;
	if(!a){
		$('#homeNews .homeHighlight2ContentWrapperInside').totemticker({
			row_height	:	'110px',
			mousestop	:	true,
			speed       :   800,
			interval    :   5000
		});
		
		$('#homePR .homeHighlight2ContentWrapperInside').totemticker({
			row_height	:	'110px',
			mousestop	:	true,
			speed       :   800,
			interval    :   6000
		});
		
		$('#homeEvents .homeHighlight2ContentWrapperInside').totemticker({
			row_height	:	'110px',
			mousestop	:	true,
			speed       :   800,
			interval    :   7000
		});
	} else {
		$('.homeHighlight2ContentWrapperInside').addClass("scroll-pane");
	}
	
	$('.scroll-pane').jScrollPane({
        showArrows: true,
        verticalDragMinHeight: 36,
        verticalDragMaxHeight: 36
    });
	
	$('.tickerBlockWrapper').cycle({ 
		fx:     'fade',
		timeout:  4000,
    	pause: 1 
	});
	
	//modalLogin:
	loginModalTimer = "";
	//var loginButtonOffset = $(".loginBlock").offset();
	//$("#loginBox").css({left: loginButtonOffset.left + "px"});
    showLoginModal = true;
    loginModalClicked = false;
	
	$(".openLoginBox").click(function(event){
		event.preventDefault();
		//apagar o timeout:
		clearTimeout(loginModalTimer);
		loginModalTimer = null;
		
		$("#languageBox").hide();
		$("#loginBox").fadeIn();
	});
	
	$(".openLoginBox").hover(
    function () {
        
    },
    function () {
		showLoginModal = false;
        loginModalTimer = setTimeout("hideLoginModal()", 800);
    });
	
	$("#loginBox").hover(
    function () {
		clearTimeout(loginModalTimer);
		loginModalTimer = null;
        showLoginModal = true;
    },
    function () {
        if (!loginModalClicked) {
            showLoginModal = false;
        	loginModalTimer = setTimeout("hideLoginModal()", 800);
        }
    });
	
	$("#loginBox input").click(function () {
        loginModalClicked = true;
    });
	
	$(".loginCancel").click(function(event){
		event.preventDefault();
		//apagar o timeout:
		clearTimeout(loginModalTimer);
		loginModalTimer = null;
		
		showLoginModal = false;
		hideLoginModal();
	});
	
	//languageModal:
	
	languageModalTimer = "";
    showLanguageModal = true;
	
	$(".openLanguageBox").click(function(event){
		event.preventDefault();
		//apagar o timeout:
		clearTimeout(languageModalTimer);
		languageModalTimer = null;
		
		$("#loginBox").hide();
		$("#languageBox").fadeIn();
	});
	
	$(".openLanguageBox").hover(
    function () {
        
    },
    function () {
		showLanguageModal = false;
        languageModalTimer = setTimeout("hideLanguageModal()", 800);
    });
	
	$("#languageBox").hover(
    function () {
		clearTimeout(languageModalTimer);
		languageModalTimer = null;
        showLanguageModal = true;
    },
    function () {
		showLanguageModal = false;
		languageModalTimer = setTimeout("hideLanguageModal()", 800);
    });
	
	
	$("#languageBox a").click(function(event){
		//mudar a língua
	});
	
	
});

function hideLoginModal() {
	if (!showLoginModal) {
        loginModalClicked = false;
        $("#loginBox").fadeOut('slow', function (){
			showLoginModal = true;
		});
    }
}

function hideLanguageModal() {
	if (!showLanguageModal) {
        $("#languageBox").fadeOut('slow', function (){
			showLanguageModal = true;
		});
    }
}


//
// MM_reloadPage()
//
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}



//
// isValidEMail()
//
function isValidEMail( eMailField, errMsg )
{
   if ( !eMailField || !eMailField.value )
      return false;

   var isValid =
      eMailField.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

   if ( isValid )
      return true;
   else
   {
      alert( errMsg);

      eMailField.focus();

      return false;
   }
}

function checkIfIE(version){
	if (jQuery.browser.msie) {
  		if(parseInt(jQuery.browser.version) == version){
			return true;
		} else {
			return false;
		}
	}
}

(function($){
    $.fn.jscroll=function(options){
        var settings={
            duration:2000
        };
        return this.each(function(){
            var $this=$(this);
            var slides=$this.children();
            var current=0;
            var td;
            if(options){
                $.extend(settings,options);
            }
            var scrollIt=function(){
                if(slides!=undefined && slides.length>0){
                    $(slides[current]).fadeTo('slow',.01,function(){
                        $(this).slideUp('slow',function(){
                            $(this).remove();
                            $this.append($(this));
                            $(this).show(10);
                            $(this).fadeTo(10,1.0);
                            current++;
                            if(current>=slides.length){
                                current=0;
                            }
                            setTimeout(scrollIt,settings.duration);
                        });
                    });
                }
            };
            $this.hover(function(){
                if(td){
                    clearTimeout(td);
                    $(slides[current]).stop();
                }
            }, function(){
                start();
            });
            var start=function(){
                td=setTimeout(scrollIt,settings.duration);
            }
            start();
        });
    };
})(jQuery);
