var httpObject = null;
var src = null;
var dst = null;

$(document).ready(function () {
    $(".tab_content").hide(); 
    $("ul.tabs li:first").addClass("active").show(); 
    $("ul.tabs li:last").addClass("tabend");
    $(".tab_content:first").show(); 
    var pathname = $(location).attr('href');
    var index = pathname.lastIndexOf('#');
    var hashId = pathname.substring(index + 1, pathname.length);
    if($('#'+hashId).length)
    {
        $("ul.tabs li").removeClass("active");
        var founded=$('#'+hashId).parent().parent().find('.tab_controll').find('a[href="#'+hashId+'"]');
        if(founded.length){
            $(founded).parent().parent().addClass("active");
            $(".tab_content").hide(); 
            $('#'+hashId).show();
            $('html,body').animate({
                scrollTop: $("#tabholder").offset().top - 436
            },'slow');
        }

    }
        
        
    $("ul.tabs li").click(function() {
        $("ul.tabs li").removeClass("active");
        $(this).addClass("active"); 
        $(".tab_content").hide(); 
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).show();
        return false;
    });
        

    
    $('a.toggle').click(function() {
    
        $(this).parent().find('.contentDiv').slideDown(); 
        $(this).hide();
    });
    
    //Click event handler for any anchor that has an href that ends in top
    $('a.backToTop').click(function() {
       
        //Animates scroll to the top of the page...and take 1 second to do it.
        $('html, body').animate({
            scrollTop:0
        }, '1000');
   
        //return false to prevent the default action of the anchor tag when clicked.
        return false;
 
    });
      
    //Click event handler for any anchor that has an href that ends in top
    $('.tab_container a.style-button').click(function() {
       
        //Animates scroll to the top of the page...and take 1 second to do it.
        $('html, body').animate({
            scrollTop:0
        }, '1000');
        $("#firstname").focus();

        //return false to prevent the default action of the anchor tag when clicked.
        return false;
 
    });
      
    $('input').bind('focus blur', function () {
        $(this).toggleClass('highlight');
    });

    $('textarea').bind('focus blur', function () {
        $(this).toggleClass('highlight');
    });

});


function mycarousel_initCallback(carousel)
{

    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function() {
    $('.mycarousel').jcarousel({
        auto: 0,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

$(document).ready(function () {
    $('.search-box input[name=chkboxName]').live('click',function(e) {
        
        var names = [];
        var keyword='';
        $('.search-box input:checked').each(function() {
            names.push(this.value);
        }); 
        keyword=$("#keywords").attr('value');

        $.ajax({
            url: strURL,
            type:'POST',
            data: ({
                options: names,
                keywords: keyword
            }),
            beforeSend: function() {
                $.blockUI({
                    css: { 
                        border: 'none', 
                        padding: '15px', 
                        backgroundColor: '#000', 
                        '-webkit-border-radius': '10px', 
                        '-moz-border-radius': '10px', 
                        opacity: .5, 
                        color: '#fff' 
                    }
                }); 
            },
            success: function(data){
                $.unblockUI();
                $('.main').html(data)
                $("html, body").animate({
                    scrollTop: 0
                }, 600);                     
            }
        });
          
        return true;
         
            
    });
});
$('#display-map').live('click', function(){

               
    $(".content-det-map").slideToggle();
    if($(this).hasClass('display-map-hover'))
    {
        $(this).removeClass('display-map-hover');
    }else{
        $(this).addClass('display-map-hover');
        getreadymaps()
    }
                
});


(function (b){  
    b.fn.codamap = function(valorX,valorY,customDiv) {  
        // $('#trigger').each(function () {
        var distance = 10;
        var time = 250;
        var hideDelay = 250;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        //var trigger = $('#trigger');
        var trigger =b(this);
        var info = b(customDiv).css('opacity', 0);
        //var position = $("#peru").position();
        // alert('X: ' + position.left + ", Y: " + position.top );

        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;
                    
                // var offset = $(this).offset();
                // var xPos = offset.left;
                // var yPos = offset.top;
                   
                    
                info.css({
                    top: valorY ,
                    left: valorX ,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    //}); 
    };  
   
})(jQuery);  
    
function getreadymaps(){
    $("#codaperu").codamap(65,49,'.peru');
    $("#codaargentina").codamap(130,163,'.argentina');
    $("#codabrazil").codamap(196,88,'.brazil');
    $("#codachile").codamap(93,96,'.chile');
}
$(document).ready( function(){
    getreadymaps()
});


function getHTTPObject(){
    if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
    else if (window.XMLHttpRequest) return new XMLHttpRequest();
    else {
        alert("Your browser does not support AJAX.");
        return null;
    }
}
 
// Change the value of the outputText field
function setOutput(){
    return true;
}
 
function setAnchor(element)
{
    var query = element.href.split('#');
    Set_Cookie('anchor', query[1],10);  
}
 
// Implement business logic
function doWork(element){
    try{
        httpObject = getHTTPObject();
        if (httpObject != null) {
            dst = escape(element.href);
     
            httpObject.open("GET", "/clickTrack.php?dst="+dst, true);
            httpObject.send(null);
        //httpObject.onreadystatechange = setOutput;
        }
    }catch(err)
    {
        txt="There was an error on this page.\n\n";
        txt+="Error description: " + err.description + "\n\n";
        txt+="Click OK to continue.\n\n";
        alert(txt);
    }
}
 

$(document).ready(function() {
    $("a.anchorLink").anchorAnimate()
});

jQuery.fn.anchorAnimate = function(settings) {

    settings = jQuery.extend({
        speed : 1100
    }, settings);	
	
    return this.each(function(){
        var caller = this
        $(caller).click(function (event) {	
            event.preventDefault()
            var locationHref = window.location.href
            var elementClick = $(caller).attr("href")
			
            var destination = $(elementClick).offset().top;
            $("html:not(:animated),body:not(:animated)").animate({
                scrollTop: destination
            }, settings.speed, function() {
                window.location.hash = elementClick
            });
            return false;
        })
    })
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
    if ( expires )
    {
        expires = expires * 1000;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}
