Shadowbox.init();
jQuery.noConflict();
(function($) { 
	$(function() {
		$(document).ready(function(){
			
			//detecção de página ativa e aplicação de jQuery em cada uma
			var pagina = window.location.pathname;
			pagina = pagina.substring(pagina.lastIndexOf("/")+1, pagina.length).replace(".aspx", "").toLocaleLowerCase();
			switch (pagina)
			{
				case "":
					numMenu = 1;					
				break;
				
				default:
					numMenu = 0;					
				break;
			}
		});
		
		//$("ul.menu li a#menu"+numMenu).addClass("selecionado");

        //ativa scroll do navegador se necessário
        var telaH = $(window).height();
        if (telaH > 735) {
            //alert(telaH);
            $('body').css("overflow", "hidden");
        }
        if (telaH < 735) {
            $('div.header h1').css("margin-left", "20px");
            $('div.header ul').css("margin-right", "20px");
            $('.fp_thumbtoggle').css("padding-left", "40px");
        }

        //scroll thumbs
        $(window).load(function() {
            sliderLeft = $('#thumbScroller .container').position().left;
            padding = $('#outer_container').css('paddingRight').replace("px", "");
            sliderWidth = $(window).width() - padding;
            $('#thumbScroller').css('width', sliderWidth);
            var totalContent = 0;
            $('#thumbScroller .content').each(function() {
                totalContent += $(this).innerWidth();
                $('#thumbScroller .container').css('width', totalContent);
            });
            $('#thumbScroller').mousemove(function(e) {
                if ($('#thumbScroller  .container').width() > sliderWidth) {
                    var mouseCoords = (e.pageX - this.offsetLeft);
                    var mousePercentX = mouseCoords / sliderWidth;
                    var destX = -(((totalContent - (sliderWidth)) - sliderWidth) * (mousePercentX));
                    var thePosA = mouseCoords - destX;
                    var thePosB = destX - mouseCoords;
                    var animSpeed = 600; //ease amount
                    var easeType = 'easeOutCirc';
                    if (mouseCoords == destX) {
                        $('#thumbScroller .container').stop();
                    }
                    else if (mouseCoords > destX) {
                        //$('#thumbScroller .container').css('left',-thePosA); //without easing
                        $('#thumbScroller .container').stop().animate({ left: -thePosA }, animSpeed, easeType); //with easing
                    }
                    else if (mouseCoords < destX) {
                        //$('#thumbScroller .container').css('left',thePosB); //without easing
                        $('#thumbScroller .container').stop().animate({ left: thePosB }, animSpeed, easeType); //with easing
                    }
                }
            });
            $('#thumbScroller  .thumb').each(function() {
                $(this).fadeTo(fadeSpeed, 0.6);
            });
            var fadeSpeed = 200;
            $('#thumbScroller .thumb').hover(
		        function() { //mouse over
		            $(this).fadeTo(fadeSpeed, 1);
		        },
		        function() { //mouse out
		            $(this).fadeTo(fadeSpeed, 0.6);
		        }
		    );
        });
        $(window).resize(function() {
            //$('#thumbScroller .container').css('left',sliderLeft); //without easing
            $('#thumbScroller .container').stop().animate({ left: sliderLeft }, 400, 'easeOutCirc'); //with easing
            $('#thumbScroller').css('width', $(window).width() - padding);
            sliderWidth = $(window).width() - padding;
        });

        //galeria
        $(function() {
            //current thumb's index being viewed
            var current = -1;
            //cache some elements
            var $btn_thumbs = $('#fp_thumbtoggle');
            var $btn_thumbs2 = $('#fp_thumbtoggle2');
            var $loader = $('#fp_loading');
            var $btn_next = $('#fp_next');
            var $btn_prev = $('#fp_prev');
            var $thumbScroller = $('#thumbScroller');

            //total number of thumbs
            var nmb_thumbs = $thumbScroller.find('.content').length;

            //preload thumbs
            var cnt_thumbs = 0;
            for (var i = 0; i < nmb_thumbs; ++i) {
                var $thumb = $thumbScroller.find('.content:nth-child(' + parseInt(i + 1) + ')');
                $('<img/>').load(function() {
                    ++cnt_thumbs;
                    if (cnt_thumbs == nmb_thumbs)
                    //display the thumbs on the bottom of the page
                    showThumbs(2000);
                        $btn_thumbs.stop().animate({ 'bottom': '0px' }, 500);
                }).attr('src', $thumb.find('img').attr('src'));
            }

            //make the document scrollable
            //when the the mouse is moved up/down
            //the user will be able to see the full image
            //makeScrollable();

            //clicking on a thumb...
            $thumbScroller.find('.content').bind('click', function(e) {
                var $content = $(this);
                var $elem = $content.find('img');
                //keep track of the current clicked thumb
                //it will be used for the navigation arrows
                current = $content.index() + 1;
                //get the positions of the clicked thumb
                var pos_left = $elem.offset().left;
                var pos_top = $elem.offset().top;
                //clone the thumb and place
                //the clone on the top of it
                var $clone = $elem.clone()
				    .addClass('clone')
				    .css({
				        'position': 'fixed',
				        'left': pos_left + 'px',
				        'top': pos_top + 'px'
				    }).insertAfter($('BODY'));

                var windowW = $(window).width();
                var windowH = $(window).height();
                
                //animate the clone to the center of the page
                $clone.stop()
				    .animate({
				        'left': windowW / 2 + 'px',
				        'top': windowH / 2 + 'px',
				        'margin-left': -$clone.width() / 2 - 5 + 'px',
				        'margin-top': -$clone.height() / 2 - 5 + 'px'
				    }, 500,
				    function() {
				        var $theClone = $(this);
				        var ratio = $clone.width() / 120;
				        var final_w = 400 * ratio;

				        $loader.show();
                        $('#fp_thumbtoggle2').addClass('lkACT');
                        $('#carregaBG').fadeIn(100);
				        //expand the clone when large image is loaded
				        $('<img class="fp_preview"/>').load(function() {
				            var $newimg = $(this);
				            var $currImage = $('#fp_gallery').children('img:first');
				            $newimg.insertBefore($currImage);
				            $loader.hide();
				            //expand clone
				            $theClone.animate({
				                'opacity': 0,
				                'top': windowH / 2 + 'px',
				                'left': windowW / 2 + 'px',
				                'margin-top': '-200px',
				                'margin-left': -final_w / 2 + 'px',
				                'width': final_w + 'px',
				                'height': '400px'
				            }, 1000, function() { $(this).remove(); });
				            //now we have two large images on the page
				            //fadeOut the old one so that the new one gets shown
				            $currImage.fadeOut(1000, function() {
				                $(this).remove();
				            });
                            //show the navigation arrows
				            showNav();
				        }).attr('src', $elem.attr('alt'));

				    });

                //hide the content	
                $('.mainContent').fadeOut(200);
                //hide the thumbs container
                hideThumbs();
                e.preventDefault();
            });

            //clicking on the "show thumbs"
            //displays the thumbs container and hides
            //the navigation arrows
            $btn_thumbs.bind('click', function() {
                showThumbs(500);
                hideNav();
            });
            $('.btFecharThumbs').bind('click', function() {
                hideThumbs(500);
                hideNav();
            });
            $btn_thumbs2.bind('click', function() {
                showThumbs(500);
                hideNav();
            });
            //$('.container').mouseleave(function() {
            //hideThumbs(500);
            //hideNav();
            //});

            function hideThumbs() {
                $('#outer_container').stop().animate({ 'bottom': '-193px' }, 500);
                showThumbsBtn();
            }

            function showThumbs(speed) {
                $('#outer_container').stop().animate({ 'bottom': '0px' }, speed);
                hideThumbsBtn();
            }

            function hideThumbsBtn() {
                $btn_thumbs.stop().animate({ 'bottom': '-40px' }, 500);
            }

            function showThumbsBtn() {
                $btn_thumbs.stop().animate({ 'bottom': '0px' }, 500);
            }

            function hideNav() {
                //$btn_next.stop().animate({ 'right': '-89px' }, 500);
                //$btn_prev.stop().animate({ 'left': '-89px' }, 500);
            }

            function showNav() {
                //$btn_next.stop().animate({ 'right': '0px' }, 500);
                //$btn_prev.stop().animate({ 'left': '0px' }, 500);
            }

            //mostra conteudo
            $('#lkHome, #lkServicos, #lkClientes, #lkContato').click(function() {
                $('img.fp_preview').hide();
                $('.descricao').hide();
                $('.tela').hide();
                $('.mainContent').fadeIn(1000);
                $('.header ul a').removeClass('lkACT');
                $(this).addClass('lkACT');
                $('#carregaBG').fadeOut(300);
                hideThumbs(500);
            });
            //$('.banner, .home, .servicos, .clientes, .contato').mouseover(function() {
                //hideThumbs(500);
            //});
            $('input').focus(function() {
                hideThumbs(500);
            });

            //events for navigating through the set of images
            //$btn_next.bind('click', showNext);
            //$btn_prev.bind('click', showPrev);

            //the aim is to load the new image,
            //place it before the old one and fadeOut the old one
            //we use the current variable to keep track which
            //image comes next / before
            //        function showNext() {
            //            ++current;
            //            var $e_next = $thumbScroller.find('.content:nth-child(' + current + ')');
            //            if ($e_next.length == 0) {
            //                current = 1;
            //                $e_next = $thumbScroller.find('.content:nth-child(' + current + ')');
            //            }
            //            $loader.show();
            //            $('<img class="fp_preview"/>').load(function() {
            //                var $newimg = $(this);
            //                var $currImage = $('#fp_gallery').children('img:first');
            //                $newimg.insertBefore($currImage);
            //                $loader.hide();
            //                $currImage.fadeOut(2000, function() { $(this).remove(); });
            //            }).attr('src', $e_next.find('img').attr('alt'));
            //        }

            //        function showPrev() {
            //            --current;
            //            var $e_next = $thumbScroller.find('.content:nth-child(' + current + ')');
            //            if ($e_next.length == 0) {
            //                current = nmb_thumbs;
            //                $e_next = $thumbScroller.find('.content:nth-child(' + current + ')');
            //            }
            //            $loader.show();
            //            $('<img class="fp_preview"/>').load(function() {
            //                var $newimg = $(this);
            //                var $currImage = $('#fp_gallery').children('img:first');
            //                $newimg.insertBefore($currImage);
            //                $loader.hide();
            //                $currImage.fadeOut(2000, function() { $(this).remove(); });
            //            }).attr('src', $e_next.find('img').attr('alt'));
            //        }

            function makeScrollable() {
                $(document).bind('mousemove', function(e) {
                    var top = (e.pageY - $(document).scrollTop() / 2);
                    $(document).scrollTop(top);
                });
            }
        });

        //banner tooltip
        $("ul.toolTips li").mouseover(function() {
            var posL = $(this).children("div").width() / 2;
            $(this).children("div").css({ 'left': '50%', 'margin-left': -(posL + 15) }).fadeIn(200);
        });
        $("ul.toolTips li").mouseleave(function() {
            $(this).children("div").fadeOut(200);
        });

        //home tooltip
        $("ul.steps li").mouseover(function() {
            $(this).children(".balao").fadeIn(200);
        });
        $("ul.steps li").mouseleave(function() {
            $(this).children(".balao").fadeOut(200);
        });

        //mostra descricao
        $('.content').bind('click', function() {
            var id = $(this).attr('id');
            var bg =  "url(App_Themes/Default/Imagens/bgs/" + $(this).attr('name') + ".jpg)";
            if (telaH < 750) {
                var name = "url(App_Themes/Default/Imagens/ampliacao/" + $(this).attr('name') + ".png)";
            } else {
                var name = "url(App_Themes/Default/Imagens/ampliacao/" + $(this).attr('name') + "-2.png)";
            }
            $('#carregaBG').css({"background-image": bg, "background-repeat":"repeat", "height": telaH}).fadeIn(100);
            $('.header ul a').removeClass('lkACT');
            $('.descricao').hide();
            $('.tela').hide();
            $('#descricao_' + id).fadeIn(1000, function() {
                $('#tela_' + id).css({"background-image": name, "background-position":"center 106px", "background-repeat":"no-repeat"}).fadeIn(2000);
            });
            //alert(bg);
        });

        //descricao de clientes
        $('.listaClientes li').mouseover(function(){
            $(this).children('div').animate({top:'0px'}, 200);
        });
        $('.listaClientes li').mouseleave(function(){
            $(this).children('div').animate({top:'122px'}, 500);
        });

        //limpa campos
        $("input,textarea").focus(function(){
            if($(this).val()==$(this).attr("valor")){
                $(this).val("");
            }
        });
        $("input,textarea").blur(function(){
            if($(this).val()==""){
                $(this).val($(this).attr("valor"));
            }
        });

        //scroll
        $(function() {
            function filterPath(string) {
                return string
                .replace(/^\//,'')
                .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
                .replace(/\/$/,'');
            }
            var locationPath = filterPath(location.pathname);
            var scrollElem = scrollableElement('html', 'body');
    
            // Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
            $('a[href*=#]').each(function() {
                // Ensure it's a same-page link
                var thisPath = filterPath(this.pathname) || locationPath;
                if (locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,'') ) {
                    // Ensure target exists
                    var $target = $(this.hash), target = this.hash;
                    if (target) {
                        // Find location of target
                        var targetOffset = $target.offset().top;
                        $(this).click(function(event) {
                            // Prevent jump-down
                            event.preventDefault();
                            // Animate to target
                            $(scrollElem).animate({scrollTop: targetOffset}, 800, function() {
                                // Set hash in URL after animation successful
                                location.hash = target;
                            });
                        });
                    }
                }
            });
            // Use the first element that is "scrollable"  (cross-browser fix?)
            function scrollableElement(els) {
                for (var i = 0, argLength = arguments.length; i <argLength; i++) {
                    var el = arguments[i],
                        $scrollElement = $(el);
                        if ($scrollElement.scrollTop()> 0) {
                            return el;
                        } else {
                            $scrollElement.scrollTop(1);
                            var isScrollable = $scrollElement.scrollTop()> 0;
                            $scrollElement.scrollTop(0);
                            if (isScrollable) {
                                return el;
                            }
                        }
                    }
                    return [];
                }
        });

	});
})(jQuery);

function initialize() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(-25.441327, -49.285002), 16);

        var myIcon = new GIcon(G_DEFAULT_ICON);
        myIcon.image = "App_Themes/Default/Imagens/map_icon.png";
        myIcon.iconSize = new GSize(40, 46);
        myIcon.iconAnchor = new GPoint(35, 43);
        myIcon.infoWindowAnchor = new GPoint(32, 4);
        myIcon.imageMap = [19,45, 7,35, 0,26, 0,15, 6,4, 16,0, 26,0, 35,7, 39,14, 39,25, 34,34, 20,45];

        var markerOptions = { icon: myIcon };

        var marker = new GMarker(map.getCenter(), markerOptions);
        GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml("<span class=infoMap><strong>Avenida do Batel, 1230</strong><br/> Ed. Batel Trade Center, Bloco B, sl. 07<br/>80420-907</span>");
        });
        map.addOverlay(marker);
    }
}



