
(function($){ 
  $.fn.fullscreenr = function(options) {
    if(options.height === undefined) alert('Please supply the background image height, default values will now be used. These may be very inaccurate.');
    if(options.width === undefined) alert('Please supply the background image width, default values will now be used. These may be very inaccurate.');
    if(options.bgID === undefined) alert('Please supply the background image ID, default #bgimg will now be used.');
    var defaults = { width: 1024,  height: 660, bgID: '.imagecache-slide-full' };
    var options = $.extend({}, defaults, options); 
    $(document).ready(function() { $(options.bgID).fullscreenrResizer(options); });
    $(window).bind("resize", function() { $(options.bgID).fullscreenrResizer(options); });    
    return this;    
  };  
  $.fn.fullscreenrResizer = function(options) {
    // Set bg size
    var ratio = options.height / options.width; 
    // Get browser window size
    var browserwidth = $(window).width();
    var browserheight = $(window).height();
    // Scale the image
    if ((browserheight/browserwidth) > ratio){
        $(this).height(browserheight);
        $(this).width(browserheight / ratio);
    } else {
        $(this).width(browserwidth);
        $(this).height(browserwidth * ratio);
    }
    // Center the image
    $(this).css('left', (browserwidth - $(this).width())/2);
    $(this).css('top', (browserheight - $(this).height())/2);
    return this;    
  };
})(jQuery);

function carregarZoom(urlImagem) {
	$("#zoom-container").css('display', 'block');
	$(".zoom-preloader").css('display', 'block');
	var img = new Image();
	$(img).load(function () {
		$('#zoom-container').removeClass('loading');
		$(this).hide();
		$(".zoom-preloader").css('display', 'none');
		$('#zoom-container #imagePan .container').append(this);
		$(this).fadeIn();
		$('#zoom-container #imagePan .container img').addClass('panning');
		funPanning();
	}).error(function () {
	}).attr('src', urlImagem);      
}

function funPanning() {
	$outer_container=$("#zoom-container");
	$imagePan_panning=$("#imagePan .panning");
	$imagePan=$("#imagePan");
	$imagePan_container=$("#imagePan .container");

	$outer_container.css("top", ($(window).height()-($outer_container.outerHeight()))/2);
	$imagePan_panning.css("margin-top",($imagePan.height()-$imagePan_panning.height())/2+"px");
	containerWidth=$imagePan.width();
	containerHeight=$imagePan.height();
	totalContentW=$imagePan_panning.width();
	totalContentH=$imagePan_panning.height();
	$imagePan_container.css("width",totalContentW).css("height",totalContentH);
	
	$imagePan_panning.css("margin-left",($imagePan.width()-$imagePan_panning.width())/2).css("margin-top",($imagePan.height()-$imagePan_panning.height())/2);
	
	$imagePan.bind("mousemove", function(event){
			MouseMove(event);									  
	});
};

function MouseMove(e){
if($imagePan_panning.css("marginLeft")!=null && $imagePan_panning.css("marginTop")!=null)
{
	var mouseCoordsX=(e.pageX - $imagePan.offset().left);
	var mouseCoordsY=(e.pageY - $imagePan.offset().top);
	var mousePercentX=mouseCoordsX/containerWidth;
	var mousePercentY=mouseCoordsY/containerHeight;
	var destX=-(((totalContentW-(containerWidth))-containerWidth)*(mousePercentX));
	var destY=-(((totalContentH-(containerHeight))-containerHeight)*(mousePercentY));
	var thePosA=mouseCoordsX-destX;
	var thePosB=destX-mouseCoordsX;
	var thePosC=mouseCoordsY-destY;
	var thePosD=destY-mouseCoordsY;
	var marginL=$imagePan_panning.css("marginLeft").replace("px", "");
	var marginT=$imagePan_panning.css("marginTop").replace("px", "");
	var animSpeed=500; //ease amount
	var easeType="easeOutCirc";
	if(mouseCoordsX>destX || mouseCoordsY>destY){
		//$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
		$imagePan_container.stop().animate({left: -thePosA-marginL, top: -thePosC-marginT}, animSpeed,easeType); //with easing
	} else if(mouseCoordsX<destX || mouseCoordsY<destY){
		//$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
		$imagePan_container.stop().animate({left: thePosB-marginL, top: thePosD-marginT}, animSpeed,easeType); //with easing
	} else {
		$imagePan_container.stop();
	}
}
}

function CenterItem(theItem){
	var winWidth=$(window).width();
	var winHeight=$(window).height();
	var windowCenter=winWidth/2;
	var itemCenter=$(theItem).width()/2;
	var theCenter=windowCenter-itemCenter;
	var windowMiddle=winHeight/2;
	var itemMiddle=$(theItem).height()/2 + 50;
	var theMiddle=windowMiddle-itemMiddle;
	if(winWidth>$(theItem).width()){ //horizontal
		$(theItem).css('left',theCenter);
	} else {
		$(theItem).css('left','0');
	}
	if(winHeight>$(theItem).height()){ //vertical
		$(theItem).css('top',theMiddle);
	} else {
		$(theItem).css('top','0');
	}
};

$(function(){
$menu = $('#sw-nav-products ul');
//
$menu.width(
   // $('#').outerWidth() +
   //$menu.outerWidth() - $menu.width() + 5
);
   
//
$(window).trigger('resize');
});


// JavaScript Document

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("navlist");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   }
   }
  }
 }
}
window.onload=startList;



$('.voltar').click(function() {
    history.go(-1);
});

