﻿$(document).ready(function(){

	/*---------- Dynamic Lead ----------*/
    if($('.dynamic .dl').length > 0){
        $('.dynamic .dl').cycle({
    		fx:     'fade',
            pager:  '.dl-nav',
    		speed:   500,
    		timeout: 6000
    	});
    };
    $('.dl-nav a').click(function(){
        $('.infoBlock ul').cycle( $(this).index() );
    });

    var ww = $(window).width();
    var wh = $(window).height();
    $('.dl li img').css({ width:ww+'px', height:wh+'px' });


    /*---------- Main Menu ----------*/
    $('.nav li a.current').append('<span class="icon dwnArrow-green"><!-- v --></span>');

    /*---------- Slide products ----------*/
    if($('.slideProducts').length > 0){
        $('.slideProducts ul').cycle({
    		fx:     'fade',
            prev:	'.slideProducts a.leftArrow-white',
    		next:	'.slideProducts a.rightArrow-white',
    		speed:   1200,
    		timeout: 4000
    	});
    };

    /*---------- Inner Nav ----------*/
    $('.innerNav .active').append('<span class="icon dwnArrow-grey"><!-- v --></span>');

    $('.innerNav a').click(function(){
        if($(this).parent().hasClass('active')){
        }else{
            $('.innerNav li').removeClass('active');
            $('.dwnArrow-grey').detach();
            $(this).parent().addClass('active').append('<span class="icon dwnArrow-grey"><!-- v --></span>');
            var loadContent = $(this).attr('ld');
            $('.ajaxBox').fadeOut(100,function(){
               $(this).load(loadContent, function(){
                   $('.ajaxBox').fadeIn(300);
               });
            });
        }
    });
    /*---------- EMPRESA content ----------*/
    $('.ajaxBox').load('empresa/nosotros.html');

    /*---------- Slider Prensas ----------*/
    if($('.biocombustibles .prensas .slider').length > 0){
        $('.biocombustibles .prensas .slider').cycle({
    		fx:     'scrollHorz',
            pager:	'.biocombustibles .prensas .sliderNav',
    		speed:   500,
    		timeout: 0
    	});
    };
    $('.biocombustibles .prensas .sliderNav a:gt(2)').detach();
    $('.biocombustibles .prensas .sliderNav a').click(function(){
       $('.biocombustibles .prensas .slider').cycle($(this).index());
    });

    /*---------- Slider Arroz ----------*/
    if($('.arroz .riceSlide').length > 0){
        $('.arroz .riceSlide ul').cycle({
    		fx:     'fade',
    		speed:   400,
    		timeout: 4500
    	});
    };

    /*---------- GALLERY ----------*/
    if($('.galleryThumbs').length > 0){
        $('.galleryThumbs #gal0').cycle({
    		fx:         'fadeZoom',
            pager:      '.gal0',
    		speed:      500,
    		timeout:    0,
            after:      function(){
                            var d = $(this).find('#gal0').length-1;
                            $('.gal0 a:gt(' + d +')').detach();
                        }
    	});

        $('.galleryThumbs #gal1').cycle({
    		fx:         'fadeZoom',
            pager:      '.gal1',
    		speed:      500,
    		timeout:    0,
            after:      function(){
                            var d = $(this).find('#gal1').length-1;
                            $('.gal1 a:gt(' + d +')').detach();
                        }
    	});


        $('#vertNav a').click(function(){
            $('.dynamicGal, .galleryNav').hide();
            $('#' + $(this).attr('rel')).fadeIn(400);
            $('.' + $(this).attr('rel')).fadeIn(400);
        });

        $('.galleryThumbs .item a').lightBox();
    };



    /*---------- Contact Form ----------*/
    $('input, textarea').focus(function(){
        if($(this).val() == $(this).attr('value')){
          $(this).val('');
        };

        $(this).blur(function(){
            if(($(this).val() == '') || ($(this).val() == $(this).attr('value'))){
              $(this).val( $(this).attr('value') );
            }
        });
    });


});//end

$(window).load(function(){

    $('.loader').fadeOut(300, function(){
        $('.header').slideDown(300, function(){
            // All Pages
            $('.dynamic').fadeIn(500);
            $('.langSelector').fadeIn(300);
            $('.footer').slideDown(500);
            $('.tweetNewsticker').fadeIn(100, function(){
                /*---------- tweetNewsticker ----------*/
                $('.tweetNewsticker .tweets span').fadeIn(200);
                if($('.tweetNewsticker .tweets').length > 0){
                    $('.tweetNewsticker .tweets').cycle({
                		fx:     'scrollHorz',
                        prev:	'.ntNav a.leftArrow-white',
                		next:	'.ntNav a.rightArrow-white',
                		speed:   900,
                		timeout: 8000
                	});
                };
            });
            $('.main').fadeIn(600, function(){ $('.col').fadeIn(400); cargarMapa(); });

            //Landing Page
            $('.tweetBlock, .dl-nav').fadeIn(300);
            $('.infoBlock').fadeIn(300, function(){
                if($('.infoBlock').length > 0){
                    $('.infoBlock ul').cycle({
    		            fx:     'scrollDown',
    		            speed:   500,
    		            timeout: 6000
        	        });
                };
            });
            //Other Pages


            });
            /*---------- Back to Top Button ----------*/
            $('.toTop').click(function(){
                $('body,html').animate({scrollTop:0},800);
            });

            /*---------- Vertical navigation for downloads and gallery page ----------*/
            $('#vertNav a').mouseover(function(){
                $(this).stop(true, true).animate({left:'7px'},200)
            }).mouseout(function(){
                $(this).stop(true, true).animate({left:'0'},200)
            }).click(function(){
                var asignTitle = $(this).text();
                $('.subtitle').text(asignTitle);
                $('#vertNav a').removeClass('active');
                $(this).addClass('active');
            });

    });

});

var cargarMapa = function() {
    if ($('#mapa-ubicacion').length > 0) {
		var punto = new google.maps.LatLng(-26.374424, -54.970783);
		var options = {
		    zoom: 16,
		    center: punto,
		    mapTypeId: google.maps.MapTypeId.HYBRID
		}
		var mapa = new google.maps.Map($('#mapa-ubicacion')[0], {
			zoom: 16,
			center: punto,
			mapTypeId: google.maps.MapTypeId.HYBRID,
			mapTypeControl: true,
			mapTypeControlOptions: {
				style: google.maps.MapTypeControlStyle.DEFAULT
			},
			panControl: false,
			zoomControl: true,
			zoomControlOptions: {
				style: google.maps.ZoomControlStyle.SMALL,
				position: google.maps.ControlPosition.RIGHT_CENTER
			},
			scaleControl: false,
			streetViewControl: false,
			navigationControl: false,
			scrollwheel: false
		});
		var marcador = new google.maps.Marker({
			clickable: false,
			draggable: false,
			map: mapa,
			position: punto,
			title: 'Tiroleo',
			visible: true
        });
	}
};
