
$.extend({
    getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlVar: function(name){
        return $.getUrlVars()[name];
    }
});

$(document).ready(function() {
    
    $('.slideshow').cycle({
        fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
    });


    //jgueryui error box setup

    $( "#errors" ).dialog({
        autoOpen: false,
        show: {effect: "fade", duration: 300},
        hide: {effect: "explode", duration: 250},
        width: 700,
        height: 210,
        resizable: false

    });

    $('.lang_block .lang_bar img').click(function(){
        $('.lang_item').hide();
        $('#lang_' + $(this).attr('id')).show();
    })

    $('.gallery_thumb_holder a').lightBox( 
    {
        imageBtnClose: '/scripts/jquery/jquery_lightbox/images/lightbox-btn-close.gif',
        imageBtnPrev: '/scripts/jquery/jquery_lightbox/images/lightbox-btn-prev.gif',
        imageBtnNext: '/scripts/jquery/jquery_lightbox/images/lightbox-btn-next.gif'    
    } 

    );
    
    $('#contact_us').submit(function(e){
        e.preventDefault();
        $.post('/ajax/contact_us_process_json.php', $(this).serialize(), function(data){
            if (data.errors) {
               alert(data.errors); 
            } else {
                $('#contact_form_container').html('<p>Thank you. Your message has been sent and we will be in touch shortly.</p>')
            }
            
        },'json');       
    });
    
    $('#newsletter_signup_form').submit(function(e){
        e.preventDefault();
        $.post('/ajax/newsletter_signup_process_json.php', $(this).serialize(), function(data){
            if (data.errors) {
               alert(data.errors); 
            } else {
                $('#contact_form_container').html('<p>Thank you. You are now subscribed to our newsletter.</p>')
            }
            
        },'json');       
    });





});


function replaceURLWithHTMLLinks(text) {
    var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
    return text.replace(exp,"<a href='$1' target='_blank'>$1</a>"); 
}



function Stringify(jsonData) {
    var strJsonData = '{';
    var itemCount = 0;
    for (var item in jsonData) {
        if (itemCount > 0) {
            strJsonData += ', ';
        }
        temp = jsonData[item];
        if (typeof(temp) == 'object') {
            s =  Stringify(temp);   
        } else {
            s = '"' + temp + '"';
        }   
        strJsonData += '"' + item + '":' + s;
        itemCount++;
    }
    strJsonData += '}';
    return strJsonData;
}

