$(document).ready(function()
{
	//SCROLL PANE
	var horizontal = $(".scrollableBanner").scrollable({ circular: true }).navigator(".navi").autoscroll(5000);

	$(window).load(function ()
	{
		$("#backGround").fullBg();
	});
	/* DEFININDO Z-INDEX DE TUDO
	====================================== */
	
	/* animacao Menus
	================================ */
	$("#menuUL > li a").each(function ()
	{
		if($(this).attr("title") == $("body").attr("id"))
		{
			$(this).addClass("ativo");
		}
	});
	
	$("#menuUL > li a").css({backgroundPositionY:"0px"})
	.mouseover(function ()
	{
		var _width = $(this).offset().left - $(this).width();
		$("#line-menu").stop().animate({width:_width-180+"px"},{duration:500});
		$(this).stop().animate({backgroundPositionY:'-25px'},{duration:500})
	});
	$("#menuUL > li a").mouseout(function ()
	{
		if($(this).attr("class") != "ativo")
		{
			var _width = $(".ativo").offset().left - $(this).width();
			$("#line-menu").stop().animate({width:_width-180+"px"},{duration:500});
			$(this).stop().animate({backgroundPositionY: '0px'},{duration:300 ,onComplete:function (){}});
		}
	})
	
	$("#menuUL > li a").trigger("mouseout");
	
	/* MENU CASTING
	=================================================== */
	$(".menuCasting > ul li").hover
	(
		function ()
		{
			$(this).find("ul:first").fadeIn();
		},
		function ()
		{
			$(this).find("ul:first").fadeOut();
		}
	);
	
	if($("body").attr("id") == "Cases")
	{
		var flashvars = {
		};
		var params = {
			menu: "false",
			scale: "noScale",
			allowFullscreen: "true",
			allowScriptAccess: "always",
			wmode: "transparent"
		};
		var attributes = {
			id:"Cases"
		};
		swfobject.embedSWF("cases/bin/Cases.swf", "altContent", "100%", "100%", "10.0.0", "expressInstall.swf", flashvars, params, attributes);
	}
	
});

/* CARREGADOR DE IMAGENS
==================================================================== */
function carregaImagem(url,div)
{
	var imagen = new Image();
	
	var	elemento = document.getElementById(div);
	
	$(elemento).empty().append("<img class='loading' src='imgs/ajax-loader.gif'/>");
	
	$(imagen).load(function ()
	{
		$(this).css("display","none").hide();
		$(elemento).empty().append($(this));
		$(this).fadeIn();
	}).error(function ()
	{
		alert("ERRO AO CARREGAR IMAGEM");
	}).attr("src",url);
}

/* funcao para deixar imagem de fundo proporcional e fullscreen
====================================================================== */
(function($) {
  $.fn.fullBg = function(){
    var bgImg = $(this);		
 
    function resizeImg() {
      var imgwidth = bgImg.width();
      var imgheight = bgImg.height();
 
      var winwidth = $(window).width();
      var winheight = $(window).height();
 
      var widthratio = winwidth / imgwidth;
      var heightratio = winheight / imgheight;
 
      var widthdiff = heightratio * imgwidth;
      var heightdiff = widthratio * imgheight;
 
      if(heightdiff>winheight) {
        bgImg.css({
          width: winwidth+'px',
          height: heightdiff+'px'
        });
      } else {
        bgImg.css({
          width: widthdiff+'px',
          height: winheight+'px'
        });		
      }
    } 
    resizeImg();
    $(window).resize(function() {
      resizeImg();
    }); 
  };
})(jQuery)

