/*function updating top cart*/
function updateTopCart(){
    $.ajax({
        type: 'GET',
        url: baseUrl + 'ajax/cart.php',
        async: true,
        cache: false,
        dataType : "json",
        data: 'refresh',
        success: function(jsonData)
        {
            $.each(jsonData, function(i, item){
                if(item.totalqty>0){
                    $('#topcart_qty').html(item.totalqty);
                    $('#topcart_price').html(item.totalprice);
                }
                else{
                    $('#topcart_qty').html('0');
                    $('#topcart_price').html('0');
                }
            });
        },
        error: function(request, error, errThrown) {
            //alert("Error: " + request + "\n" + "Desc.: " + error + "Thrown: " + errThrown);
        }
    });
}
//info diag
function infoDiag(title,text,c)
{
    if (c == null){
        c = language.cancel;
    }
    var dialogDiv = $( document.createElement('div') );
    var innerDiv = $( document.createElement('div') );
    innerDiv.html(text);
    dialogDiv.append(innerDiv);
    $("body").append(dialogDiv);
    var dialog_buttons = {}; 
    dialog_buttons[c] = function(){ 
        $(this).dialog('close'); 
        dialogDiv.remove();
    }
    $(dialogDiv).dialog({
        buttons: dialog_buttons,
        title: title,
        autoOpen: false,
        bgiframe: true,
        resizable: false,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        }
    });
    $(dialogDiv).dialog('open');    
}
function confirmDiag(url,title,text,confirm,formname)
{
    var dialogDiv = $( document.createElement('div') );
    var innerDiv = $( document.createElement('div') );
    innerDiv.html(text);
    dialogDiv.append(innerDiv);
    $("body").append(dialogDiv);
    var dialog_buttons = {}; 
    dialog_buttons[confirm] = function(){ 
        $(this).dialog('close');
        dialogDiv.remove();
        if ( formname === undefined ) {
            document.location = url;  
        }
        else{
            document.forms[formname].submit();           
        }
        return false;
    }
    dialog_buttons[language.cancel] = function(){ 
        $(this).dialog('close'); 
        dialogDiv.remove();
    }
    $(dialogDiv).dialog({
        buttons: dialog_buttons,
        title: title,
        autoOpen: false,
        bgiframe: true,
        resizable: false,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        }
    });
    $(dialogDiv).dialog('open');    
}
function promtDiag(title,text,confirm,w,text2){
    var dialogDiv = $( document.createElement('div') );
    var f = $ ( document.createElement('form') );
    if(w=='url'){
        var dl2 = $ ( document.createElement('dl') );
        dl2.addClass('horizontal');
        var dt2 = $ ( document.createElement('dt') );
        dt2.addClass('part_300');
        dt2.html(text2);
        dl2.append(dt2)
        var dd2 = $ (document.createElement('dd'));
        dd2.addClass('part_700');
        var i2 = $("<input>", {type: "text",val: "",width:"98%"});
        dd2.append(i2);
        dl2.append(dd2);    
        f.append(dl2);
    }
    var dl = $ ( document.createElement('dl') );
    dl.addClass('horizontal');
    var dt = $ ( document.createElement('dt') );
    dt.addClass('part_300');
    dt.html(text);
    dl.append(dt)
    var dd = $ (document.createElement('dd'));
    dd.addClass('part_700');
    var i = $("<input>", {type: "text",val: "",width:"98%"});
    dd.append(i);
    dl.append(dd);
    f.append(dl);
    dialogDiv.append(f);
    $("body").append(dialogDiv);
    var dialog_buttons = {}; 
    dialog_buttons[confirm] = function(){ 
        var val = i.val();
        if(w=='urlimg'){
            insertTag('[urlimg]'+ val +"[/urlimg]","");  
        }
        else if(w=='url'){
            var val2 = i2.val();
            insertTag('[url=' + val + ']'+ val2 +"[/url]","");  
        }
        else if(w=='yt'){
            insertTag('[yt]'+ val +"[/yt]","");  
        }
        else{
            insertTag( val , "");  
        }
        $(this).dialog('close');
        dialogDiv.remove();
        return false;
    }
    dialog_buttons[language.cancel] = function(){ 
        $(this).dialog('close'); 
        dialogDiv.remove();
    }
    $(dialogDiv).dialog({
        buttons: dialog_buttons,
        title: title,
        width: 500,
        autoOpen: false,
        bgiframe: true,
        resizable: false,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        }
    });
    $(dialogDiv).dialog('open');    
}
function progressDiag(title,text){
    var dialogDiv = $( document.createElement('div') );
    var p = $ (document.createElement('p'));
    p.html(text);
    dialogDiv.append(p);
    var i = $("<img>", {src: '../img/progress.gif' , alt: 'progress....'});
    dialogDiv.append(i);
    $("body").append(dialogDiv);
    $(dialogDiv).dialog({
        title: title,
        autoOpen: false,
        bgiframe: true,
        resizable: false,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        }
    });
    $(dialogDiv).dialog('open');    
}
//language for ui
jQuery(function($){
    $.datepicker.regional['sk'] = {
        closeText: 'Zavrieť',
        prevText: '&#x3c;Predchádzajúci',
        nextText: 'Nasledujúci&#x3e;',
        currentText: 'Dnes',
        monthNames: ['Január','Február','Marec','Apríl','Máj','Jún',
        'Júl','August','September','Október','November','December'],
        monthNamesShort: ['Jan','Feb','Mar','Apr','Máj','Jún',
        'Júl','Aug','Sep','Okt','Nov','Dec'],
        dayNames: ['Nedel\'a','Pondelok','Utorok','Streda','Štvrtok','Piatok','Sobota'],
        dayNamesShort: ['Ned','Pon','Uto','Str','Štv','Pia','Sob'],
        dayNamesMin: ['Ne','Po','Ut','St','Št','Pia','So'],
        weekHeader: 'Ty',
        dateFormat: 'dd.mm.yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
    $.datepicker.regional['es'] = {
        closeText: 'Cerrar',
        prevText: '&#x3c;Ant',
        nextText: 'Sig&#x3e;',
        currentText: 'Hoy',
        monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
        'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
        monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
        'Jul','Ago','Sep','Oct','Nov','Dic'],
        dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
        dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
        dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/yy',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
    };
});
//onload function have to be last need functions before
$(document).ready(function(){  
    // gmenu
    $("#gmenu li").hover(function(){
        $(this).addClass("gmenuactiv");
        $('ul:first',this).css('visibility', 'visible');
    }, function(){
        $(this).removeClass("gmenuactiv");
        $('ul:first',this).css('visibility', 'hidden');
    });
    $('input').checkBox();  //jquery.ui.checkbox replacement
    $(".jfwtip").jfwtip();  // jfw tip -> tooltip modification
    $("a[rel^='prettyPhoto']").prettyPhoto();   //prettyPhoto initialization
    updateTopCart();  //refresh top cart
    $(".eObscure").jfwEobscure(); //email obscure
    $(".rate").jfwRate();         //rating  
});
