LANGUAGE_TEMP = LANGUAGE;
if (LANGUAGE_TEMP == "cz") {
    LANGUAGE_TEMP = "cs";
}

var addthis_config = {
    ui_language: LANGUAGE_TEMP
};

//THIS IS REQUIRED TO FIX AJAX CALLS ON JQUERY 1.4.2 UNDER IE 7,8
$(function(){
    $.ajaxSetup({
        xhr: function(){
            if ($.browser.msie) {
                return new ActiveXObject("Microsoft.XMLHTTP");
            }
            else {
                return new XMLHttpRequest();
            }
        }
    });
});


function showMessage(message){
    $("#message > p").html(message);
    $("#message").dialog({
        buttons: {
            "Ok": function(){
                $("#message").dialog("close");
            }
        },
        modal: true,
        title: "Informacja"
    });
}

$(function(){
    $('.btn_link').button({
        text: true,
        icons: {
            'primary': 'ui-icon-circle-arrow-e'
        }
    }).click(function(event, ui){
        window.location = $(this).attr('rel');
    });
    $('#btn_favour').button({
        text: true,
        icons: {}
    }).click(function(event, ui){
        $("<div id='dialog' title='Informacja'><p>Nie jesteś zalogowany!</p></div>").dialog({
            bgiframe: true,
            height: 140,
            modal: true
        });
    });
    
    
    $("#banners").flash({
        src: APP_URL + 'store/banners/2011.swf',
        width: 750,
        height: 100,
		'wmode': 'opaque'
    });
    
});


//Rozwijanie i zwijanie drzewka kategorii kategorii w formularzach
$("#selectCategories li.mainCategory strong, #selectCategories li.mainCategory .collapse").live("click", function(){
    $("ul", $(this).parent()).toggle();
});

$(document).ready(function(){
    $(".fancybox").fancybox({
        'zoomSpeedIn': 300,
        'zoomSpeedOut': 300
    });
});

$(document).ready(function(){
    if ($("#messages").html()) 
        $("#messages_container").slideDown();
});

function showMessageMessage(message){
    $("#messages").html("<input type='button' value='Zchowaj' id='messagesHide' />")
    $("#messages").hide().prepend("<p>" + message + "</p>").show();
}

$(function(){

    // INITIALIZING SCROLLBAR ON VISIBLE ELEMENTS
    
    $(".fancybox").fancybox({
        'overlayShow': true,
        'overlayOpacity': 0.8,
        'overlayColor': '#EEE',
    });
    
    
    $('.scrollbar').jScrollPane({
        showArrows: true,
        scrollbarWidth: 18,
        arrowSize: 16
    });
    
    $(".accordion").accordion();
    
    $(".tooltip").qtip(template_qtip01);
    
    $(".vtour_link").click(function(){
        open_tour($(this).attr('rel'));
        return false;
    });
    
    $(".vtour_full_link").fancybox({
        'width': 800,
        'height': 500,
        'centerOnScroll': true,
        'overlayShow': true,
        'overlayOpacity': 0.8,
        'overlayColor': '#EEE',
        'titleShow': false,
        'margin': 20,
        'padding': 7
    });
    
    $(".promoMovie_link").click(function(){
        open_movie();
        return false;
    });
    
});

function open_movie(){
    $('<a href="' + APP_URL + 'pl/common/promoMovie" class="iframe"></a> ').fancybox({
        'overlayShow': true,
        'overlayOpacity': 0.8,
        'overlayColor': '#EEE',
        'width': 850,
        'height': 485
    }).trigger('click');
    return false;
}

function open_tour(id){
    $('<a href="' + 'http://mediadigital.pl/tour_viewer/view_tour/visitopolskie.pl/' + id + '" class="iframe"></a> ').fancybox({
        'width': 800,
        'height': 500,
        'centerOnScroll': true,
        'overlayShow': true,
        'overlayOpacity': 0.8,
        'overlayColor': '#EEE',
        'titleShow': false,
        'margin': 20,
        'padding': 7
    }).trigger('click');
}



template_qtip01 = {
    content: {
        text: false,
        title: false
    },
    position: {
        target: 'mouse',
        adjust: {
            x: 5,
            y: 5,
            screen: true
        }
    },
    show: {
        delay: 100,
        solo: true,
        effect: {
            type: 'fade',
            length: 0
        }
    },
    hide: {
        delay: 0,
        effect: {
            type: 'fade',
            length: 0
        }
    },
    style: {
        border: {
            width: 3,
            radius: 3,
            color: '#00548D',
            tip: true
        },
        width: {
            max: 500,
            min: 0
        },
        tip: { // Now an object instead of a string
            corner: 'topLeft', // We declare our corner within the object using
            // the corner sub-option
            color: false,
            size: {
                x: 15, // Be careful that the x and y values refer to
                // coordinates on screen, not height or width.
                y: 20
                // Depending on which corner your tooltip is at, x and y could mean
                // either height or width!
            }
        },
        classes: {
            content: 'tooltip_content'
        }
    }
};

template_fancybox01 = {
    'transitionIn': 'none',
    'transitionOut': 'none',
    'overlayShow': true,
    'autoScale': false,
    'titlePosition': 'inside'
};

// =========================================================================
// GENERAL HELPER FUNCTIONS
// =========================================================================

// returns the first single object from an array of objects with maching
// property value
function searchObjectArrayForProperty(the_array, property, value){
    for (x in the_array) {
        if (the_array[x][property] == value) {
            return the_array[x];
        }
    }
    return 0;
}

function urlencode(str){
    // URL-encodes string  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/urlencode
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: travc
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Lars Fischer
    // +      input by: Ratheous
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Joris
    // +      reimplemented by: Brett Zamir (http://brett-zamir.me)
    // %          note 1: This reflects PHP 5.3/6.0+ behavior
    // %        note 2: Please be aware that this function expects to encode into UTF-8 encoded strings, as found on
    // %        note 2: pages served as UTF-8
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
    str = (str + '').toString();
    
    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

