$j(document).ready(function(){
    $j('.ajax_pager').bind('click',function() {
        var me = $j(this);
        url = me.data('url');
        category_id = me.data('category');
        getAjaxPage(url,category_id);
    });
});

function StartOnLoad(funct) {
    //setup onload function
    if(typeof window.addEventListener != 'undefined')    {
        //.. gecko, safari, konqueror and standard
        window.addEventListener('load', funct, false);
    } else if(typeof document.addEventListener != 'undefined')    {
        //.. opera 
        document.addEventListener('load', funct, false);
    } else if(typeof window.attachEvent != 'undefined')    {
        //.. win/ie
        window.attachEvent('onload', funct);
    }    
    //** remove this condition to degrade older browsers
    else{
        //.. mac/ie5 and anything else that gets this far
        
        //if there's an existing onload function
        if(typeof window.onload == 'function')        {
            //store it
            var existing = onload;            
            //add new onload handler
            window.onload = function()            {
                //call existing onload function
                existing();                
                //call generic onload function
                funct();
            };
        } else{
            //setup onload function
            window.onload = funct;
        }
    }
}

function showImageGallery(imageid,galleryid,title) {
    if (!galleryid) galleryid='';
    if (!imageid) imageid='';
    var newwin=window.open('/galeria/'+title+'-'+galleryid,'_blank');
    newwin.focus();
}

function tabs_slideshow_show(event, ui){
    var lastOpenedPanel = $j(this).data("lastOpenedPanel");
    if (!$j(this).data("topPositionTab")) {
        $j(this).data("topPositionTab", $j(ui.panel).position().top)
    }         
    $j(ui.panel).hide().fadeIn(1000);

    if (lastOpenedPanel) {
        lastOpenedPanel
        .toggleClass("ui-tabs-hide")
        .css("position", "absolute")
        .fadeOut(1000, function() {
            });
    }
    $j(this).data("lastOpenedPanel", $j(ui.panel)); 
    $j("#slideshow").find('.arrow').css('marginTop',((ui.index*70)+12) + 'px');						
}

function tabs_slideshow_instantly(event, ui){
    var lastOpenedPanel = $j(this).data("lastOpenedPanel");
    if (!$j(this).data("topPositionTab")) {
        $j(this).data("topPositionTab", $j(ui.panel).position().top)
    }         
    $j(ui.panel).hide().fadeIn(0);

    if (lastOpenedPanel) {
        lastOpenedPanel
        .toggleClass("ui-tabs-hide")
        .css("position", "absolute")
        .fadeOut(0, function() {
            });
    }
    $j(this).data("lastOpenedPanel", $j(ui.panel)); 
}

function openRadio() {
    var url = "/radio";
    window.open(url, "", "width=382,height=270,left=" + ((screen.width - 270) / 2 + ",top=" + (screen.height - 270) / 2)+',resizable=0');
}

function fontSize(type) {
    
    var font = parseInt(jQuery('.text_container').css('font-size'));
    var line = parseInt(jQuery('.text_container').css('line-height'));
    
    if(type == 1) { //növelés
        if(font <= 16) {
            var new_font = font+2;
            var new_line = line+2;
            jQuery('.text_container').css('font-size',new_font+'px');
            jQuery('.text_container').css('line-height',new_line+'px');
        }
    }
    if(type == 2) { //csökkentés
        if(font >= 12) {
            var new_font = font-2;
            var new_line = line-2;
            jQuery('.text_container').css('font-size',new_font+'px');
            jQuery('.text_container').css('line-height',new_line+'px');
        }
    }
}

function search() {
    var search_text = $j.trim($j('#search_text').val());
    if(search_text.length < 4) alert('Legalább 4 karaktert meg kell adni');
    else {
        search_text = search_text.replace(' ','+');
        location.href='/kereses/'+search_text
    }
}

function getAjaxPage(url, category_id) {
    if(!ajax) {
        ajax = true;
        $j('#ajax_loader').html('<img src="/images/ajax-loader.gif"/>');
        $j.ajax({
            type: 'POST',
            url: url,
            data: {
                start: ajax_page,
                end: 30,
                category_id: category_id
            },
            success: function(ret) {
                if(typeof ret.end != 'undefined') $j('.ajax_pager').hide();
                $j('#ajax_loader').html('további friss hírek');
                $j('#list').append(ret.html);
                ajax_page = ajax_page+30;
                ajax = false;
            }
        });
    }
}

function openSideUrl(url,id) {
    $j.ajax({
        type: 'POST',
        url: '/SideBox/inc_stat',
        data: {
            id: id
        }
    });
    location.href=url;
}

function supports_html5_storage() {
    try {
        return 'localStorage' in window && window['localStorage'] !== null;
    } catch (e) {
        return false;
    }
}

function displayPage(record) {
    $j.ajax({
        type: 'POST',
        url: '/Imagegallery/list_page',
        data: 'record='+record,
        success: function(ret) {
            $j('#imagegallery_list').html(ret);
        }
    })
}
