// JavaScript Document
//////// tip /////////////////

var tip_tribur_fundo = '#FFFBEA';
var tip_tribur_borda = '#8F5E01';


function test_browser_version(){
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
function corrigepng(){
	if ((test_browser_version() >= 5.5) && (document.body.filters)){
	   for(var i=0; i<document.images.length; i++)   {
		  var img = document.images[i];
		  var imgName = img.src.toUpperCase();
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
			 var imgID = (img.id) ? "id='" + img.id + "' " : "";
			 var imgClass = (img.className) ? "class='" + img.className + "' " : "";
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
			 var imgStyle = "display:inline-block;" + img.style.cssText;
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";

			 img.outerHTML = strNewHTML;
			 i = i-1;
		  }
	   }
	}
}

/// funcao Popin


function popin_create(){
	if($('#tb_popin').length == 0){
		var html = '<div id="tb_popin" style="display:none;" > \
		<div id="tb_black" ></div>\
		  <div class="popup"> \
			<table align="center"> \
			  <tbody> \
				<tr> \
				  <td class="tl"/><td class="b"/><td class="tr"/> \
				</tr> \
				<tr> \
				  <td class="b"/> \
				  <td class="body"> \
						<div id="tb_loading"></div>\
						<div id="tb_content"></div> \
						<div id="tb_footer"></div>\
				  </td> \
				  <td class="b"/> \
				</tr> \
				<tr> \
				  <td class="bl"/><td class="b"/><td class="br"/> \
				</tr> \
			  </tbody> \
			</table> \
		  </div> \
		</div>';
		
	$('body').append(html);
	}
}
function tb_show(){
	popin_create();
	//tb_scrollon();
	tb_scrollpopin();
	$('#tb_black').height($(document).height() - 23);
	$('#tb_popin').fadeIn('normal');
	var size = $(window).height()/6 + $(document).scrollTop();
	$("#tb_popin").find('.popup').css({top: size});
	$('#tb_black').click(function() {
    tb_remove();
	});	
	if(jQuery.browser.msie && jQuery.browser.version < 7) {
		$("#tb_popin").css({width: $(document).width()});
	}
}
function tb_remove(){
	tb_scrolloff();
	$('#tb_popin').fadeOut('normal');
	$('#tb_content').html('');
	$('#tb_footer').html('');
	
}
function tb_footer(arra){
	if(arra == '1' || arra == '' || arra == undefined){
		 buttons = '<input onclick="tb_remove()" value="X" type="button">';
	}else{
		var buttons = '';
		for (var i in arra){
			if(arra[i] == 'close'){
				arra[i] = 'tb_remove()';
			}
			if(i.substring(0,1) == '*'){
				nome = i.substring(1);
				myclass = 'class="focus"';
			 }else{
				myclass = '';
				nome = i;
		    }
			
		 buttons += '<input '+myclass+' onclick="'+arra[i]+'" value="'+nome+'" type="button">';
		}
	}
   $('#tb_popin').find('#tb_footer').html(buttons);
}
function tb_scrollon(){
	if (window.addEventListener){
		window.addEventListener('scroll',tb_scrollpopin, false);
	}else{
		window.attachEvent('onscroll',tb_scrollpopin);
	}
} // scrollon 
function tb_scrolloff(){
	if (window.removeEventListener){
		window.removeEventListener('scroll',tb_scrollpopin, false);
	}else{
		window.detachEvent('onscroll',tb_scrollpopin);
	}
}
function tb_scrollpopin(){
	$("#tb_black").css({top: 0});
     $("#tb_black").css({left: $(document).scrollLeft()});
	}
function tb_realocate(){
		var  size = ($(window).height() - $("#tb_popin").find('.popup').height())/2;
		if(size < 0){ size = 0; }
		var newsize =  $(document).scrollTop() + size;
		$("#tb_popin").find('.popup').css({'top': newsize});
	}


function popin(obj){
	 tb_show();
	 if(obj.html != ''){
		$('#tb_popin').find('#tb_content').html(obj.html);	
		tb_realocate();
	 }
	 if(obj.buttons != ''){
		 tb_footer(obj.buttons);
	 }else{
		 $('#tb_popin').find('#tb_footer').css({'display':'none'}); 
	 }
	 if(obj.remove == 0){
		 $('#tb_black').unbind('click');
		 $("#tb_black").css({ opacity: 0.5 });
	 }else{
		 $("#tb_black").css({ opacity: 0 });
	}
	
	
}

/// funcao Popin

(function ($)
{
    $.fn.tinycarousel = function (options)
    {
        var defaults = 
        {
            start : 1, display : 1, axis : 'x', controls : true, pager : false, interval : false, intervaltime : 10000, 
            animation : true, duration : 3000, callback : null
        };
        var options = $.extend(defaults, options);
        var oSlider = $(this);
        var oViewport = $('.viewport', oSlider);
        var oContent = $('.overview', oSlider);
        var oPages = oContent.children();
        var oBtnNext = $('.next', oSlider);
        var oBtnPrev = $('.prev', oSlider);
        var oPager = $('.pager', oSlider);
        var iPageSize, totalSize, iSteps, iCurrent, oTimer, bForward = true, bAxis = options.axis == 'x';
        return this.each(function ()
        {
            initialize();
        });
		
		
        function initialize()
        {
          // iPageSize = bAxis ? $(oPages[0]).outerWidth(true) : $(oPages[0]).outerHeight(true);
		   //alert(oPages.length)
		   totalSize = 0;
		   for(x=0;x<oPages.length;x++){
			   totalSize = totalSize + ($(oPages[x]).find('img').attr("width"));
		   }
		    iPageSize = totalSize/oPages.length;
            var iLeftover = Math.ceil(((bAxis ? oViewport.outerWidth() : oViewport.outerHeight()) / (iPageSize * options.display)) - 1);
            iSteps = Math.max(1, Math.ceil(oPages.length / options.display) - iLeftover);
            iCurrent = Math.min(iSteps, Math.max(1, options.start)) - 2;
            oContent.css(bAxis ? 'width' : 'height', (iPageSize * oPages.length));
            move(1);
            setEvents();
        }
        function setEvents()
        {
            if (options.controls && oBtnPrev.length > 0 && oBtnNext.length > 0)
            {
                oBtnPrev.click(function ()
                {
                    move(-1);
                    return false;
                });
                oBtnNext.click(function ()
                {
                    move(1);
                    return false;
                });
            }
            if (options.pager && oPager.length > 0) {
                oPager.click(setPager);
            }
        }
        function setButtons()
        {
            if (options.controls)
            {
                oBtnPrev.toggleClass('disable', !(iCurrent > 0));
                oBtnNext.toggleClass('disable', !(iCurrent + 1 < iSteps));
            }
            if (options.pager)
            {
                var oNumbers = $('.pagenum', oPager);
                oNumbers.removeClass('active');
                $(oNumbers[iCurrent]).addClass('active');
            }
        }
        function setPager(oEvent)
        {
	
            var oTarget = oEvent.target;
            if ($(oTarget).hasClass('pagenum')) {
                iCurrent = parseInt(oTarget.rel) - 1;
                move(1);
            }
            return false;
        }
        function setTimer(bReset)
        {
            if (options.interval && !bReset)
            {
                clearInterval(oTimer);
                oTimer = window.setInterval(function ()
                {
                    bForward = iCurrent + 1 == iSteps ? false : iCurrent == 0 ? true : bForward;
                    move(1, true);
                },
                options.intervaltime);
            }
        }
        function move(iDirection, bTimerReset)
        {
			//alert(iDirection);
            if (iCurrent + iDirection > -1 && iCurrent + iDirection < iSteps - 1)
            {
                iCurrent += iDirection;
				
				
				var mycsize = 0;
				 for(x=0;x<=iCurrent;x++){
			  		 mycsize = mycsize + ($(oPages[x]).find('img').attr("width"));
		  		 }
				 
				 
                var oPosition = {};
				
				oPosition[bAxis ? 'left' : 'top'] =- mycsize + oViewport.width()/2;
                //oPosition[bAxis ? 'left' : 'top'] =- (iCurrent * (iPageSize * options.display));
				
				
                oContent.animate(oPosition, 
                {
                    queue : false, duration : options.animation ? options.duration : 0,
                    complete : function ()
                    {
                        if (typeof options.callback == 'function')
                        {
                            options.callback.call(this, oPages[iCurrent], iCurrent);
                        }
                    }
                });
                setTimer(bTimerReset);

            }else{
				iCurrent = 0;
				var mycsize = 0;
				 for(x=0;x<=iCurrent;x++){
			  		 mycsize = mycsize + ($(oPages[x]).find('img').attr("width"));
		  		 }
				 mycsize =  mycsize - oViewport.width()/2;
				 oContent.css({"left":-mycsize});
				 move(1);
				
				
			}
        }
    };
})(jQuery);



function gallery(folder, i){
	var fotos = '';
	for(x=0;x<=i;x++){			fotos = fotos + '<li><img src="img/'+folder+'/'+x+'.jpg" /></li>';	}
	 var galery = '<div id="slider-code-pop">\
	<div class="viewport">\
		<ul class="overview">'+fotos+'</ul>\
	</div>\
	 <a class="button prev" href="#"></a>\
	<a class="button next" href="#"></a>\
</div>';
return galery;
	}
	
	
	function panoview(i){
	 
	 var locatior = "img%2F360%2Fpano"+i+".jpg"; var locall = "local=1&";
	 //var locatior = "dreamhost%2Fsites%2Faltodobau_novo.com.br%2Fimg%2F360%2Fpano"+i+".jpg";  var locall = "";
	 var ariel = '<object width="800" height="400"><param name="movie" value="pano.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="flashvars" value="'+locall+'src='+locatior+'"><param name="wmode" value="transparent" /></param><embed src="pano.swf" width="800" height="400" flashvars="'+locall+'src='+locatior+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" movie="pano.swf" wmode="transparent"></embed></object>';
	 
	 return ariel;
	
	 
 }
