
function calendarChangeMonths(url) {
    var url = 'index.php?r=Calendar&f=changeMonth&'+url;
    ajax.get(url, function(result) { calCallback(result); });
}

function calCallback(result) {
    var div = document.getElementById('calendar');
    div.innerHTML = result;
    bindCalendarClick();
    jQuery('a.tooltipTitleEvent').cluetip({local:true, cursor: 'pointer', cluetipClass:'jtip'});
}

//ajax call for calendar
jQuery(document).ready(function(){
    bindCalendarClick();

    //form vprasalnik JS to hide content
    jQuery("input[name='ogled_rep']").bind('click', function() {
        if (this.value == "ne"){
            jQuery(".canHide").hide();
        }else{
            jQuery(".canHide").show();
        }
    });
});

//this must be seperated becouse of ajax, after each callback we need to bind events
function bindCalendarClick(){
    jQuery("div#calendar a.nazaj,div#calendar a.naprej").bind('click', function() {
        var href = this.href.split('?');
        //split url by ? and second half of url are the params for ajax script - year and month
        calendarChangeMonths(href[1]);

        return false;
    });
}

jQuery(document).ready(function(){
    jQuery('#newsList ul li a').bind('mouseenter',function(){
        var id = jQuery(this).get(0).className;
        jQuery('#newsText'+id).fadeIn("normal");
        jQuery('#newsText'+id).removeClass("hidden");

        if (typeof jQuery('#videoNews'+id).get(0) != 'undefined') {
            jQuery('#videoNews'+id).addClass('hidden');
        }

        jQuery(".mainNews,.videoNews").each(function () {
            if (this.id != 'newsText'+id && this.id != 'videoNews'+id) {
                jQuery(this).fadeOut("normal");
                jQuery(this).addClass('hidden');
            }
        });
    });
});

// This is used at news page to show videos after we click play
jQuery(document).ready(function(){
    jQuery("a[rel='videoNews']").bind('click', function() {
        // Get news ID which we need for specific operations on our news structure
        var id = this+'';
        id=id.split('#')[1];

        // Hide main textual news
        jQuery('#newsText'+id).fadeOut("slow");
        jQuery('#newsText'+id).addClass('hidden');

        // Show video news
        //jQuery('#videoNews'+id).css("display", "block");
        jQuery('#videoNews'+id).fadeIn("normal");
        jQuery('#videoNews'+id).removeClass('hidden');

        // Get video, pic params
        var videoPic = jQuery('#videoPic'+id).val();
        var videoClip = jQuery('#videoClip'+id).val();
        var videoRatio = jQuery('#videoRatio'+id).val();

        //400 x 224 - 16:9
        if (videoRatio == 'wide'){
            var width = 400;
            var height = 224;
        }else{
            //340 x 256 - 4:3
            var width = 340;
            var height = 256;
        }

        // Engage flash
        loadVideoPlayer('newsVideoFlash'+id, videoClip, videoPic, width, height);

        // Dont use link
        return false;
    });
});

//this is used for all fake video players
jQuery(document).ready(function(){
    jQuery("a[rel='video']").bind('click', function() {
        var key = this.name;

        // Get video, pic params
        var videoPic = jQuery('#videoPic'+key).val();
        var videoClip = jQuery('#videoClip'+key).val();
        var videoRatio = jQuery('#videoRatio'+key).val();

        //hardcoded for popup video
        //400 x 224 - 16:9
        if (videoRatio == 'wide'){
            var definedWidth = 400;
            var definedHeight = 224;
        }else{
            //340 x 256 - 4:3
            var definedWidth = 340;
            var definedHeight = 256;
        }
        //clones player div for appending to body, becouse modalManual deletes the div
        var playerDiv = jQuery("#videoplayer").clone();

        //definedWidth=definedWidth+500;
        //definedHeight=definedHeight+500;
        // Engade flash
        loadVideoPlayer('videoplayer', videoClip, videoPic, definedWidth, definedHeight);

        //jQuery(this).nyroModal({minWidth: definedWidth, minHeight: definedHeight, autoSizable: false, galleryLinks: '',width: definedWidth,height: definedHeight});
        jQuery.nyroModalManual({content: jQuery("#videoplayer"),minWidth: definedWidth, minHeight: definedHeight, autoSizable: false, galleryLinks: '',width: definedWidth, height: definedHeight});

        //append it now - when original is deleted
        jQuery("#body").append(playerDiv);
        // Dont use link
        return false;
    });
});

function loadVideoPlayer(id, video_clip, video_pic, width,height) {
    var video = new SWFObject('resources/files/player.swf','ply',width,height,'8','#ffffff');
    video.addParam('allowfullscreen','true');
    video.addParam('allowscriptaccess','always');
    video.addParam('wmode','opaque');
    video.addParam('flashvars','file=../../'+video_clip+'&image='+video_pic+'&skin=resources/files/nacht-Source.swf');
    video.write(id);
}

// Tooltip
jQuery(document).ready(function() {
    jQuery('a.tooltipTitle').cluetip({local:true, cursor: 'pointer'});
    jQuery('a.tooltipTitleEvent').cluetip({local:true, cursor: 'pointer', cluetipClass:'jtip'});
});


function loadHimnaFlash() {
    if (jQuery('#preview').length != 0) {
        var s1 = new SWFObject('resources/files/player.swf','ply','280','20','9','#ffffff');
        s1.addParam('allowfullscreen','false');
        s1.addParam('allowscriptaccess','always');
        s1.addParam('wmode','opaque');
        s1.addParam('flashvars','file=resources/files/Dviga_Slovenija_zastave.mp3&duration=260&skin=resources/files/nacht-Source.swf');
        s1.write('preview');
    }
}

function loadFlash() {
    var so = new SWFObject("http://www.nzs.si/resources/files/srecno2010.swf", "Srecno 2010", "500", "500", "8");
    so.addParam("wmode", "transparent");
    so.write("voscilnica");
}

function loadFlashKoledar() {
    var so = new SWFObject("http://www.nzs.si/resources/files/banner_nzs.swf", "Srecno 2010", "275", "210", "8");
    so.addParam("wmode", "transparent");
    so.write("koledar");
}


jQuery(document).ready(function(){
    if (jQuery('#preview').get(0) != undefined) {
        loadHimnaFlash();
    }
    if (jQuery('#voscilnica').get(0) != undefined) {
        loadFlash();
    }
    if (jQuery('#koledar').get(0) != undefined) {
        loadFlashKoledar();
    }
});

jQuery(document).ready(function(){
    //select all links in ul with rel = lightbox
    jQuery("a[rel='lightbox'], .expandPicture").nyroModal({contentError:'',type:'image',errorClass:'',resizeable:false,debug:false,css:{content:{overflow: 'hidden'}}, minWidth: 1, minHeight: 1, gallery:'lightbox'});

    //here you can alter data before output!
    jQuery.fn.nyroModal.settings.endFillContent = function(elts, settings) {
        if (elts.content[0].lastChild.nodeName == 'DIV'){
            var descDiv = elts.content[0].lastChild;
            descDiv.className = "lightboxPicDescription";
        }

        if (typeof elts.contentWrapper[0].children[1].children[0] != 'undefined' && elts.contentWrapper[0].children[1].children[0].nodeName == 'DIV'){
            var descDiv = elts.contentWrapper[0].children[1].children[0];
            descDiv.style.overflow = "hidden";
        }
    }
});

jQuery(document).ready(function(){
    jQuery('#delegat').change(function(){
        jQuery(':input[name="_action"]').val('delegat');
        jQuery('#delegat').get(0).form.submit();
        return false;
    });

    jQuery('#sodnik').change(function(){
        jQuery(':input[name="_action"]').val('sodnik');
        jQuery('#sodnik').get(0).form.submit();
        return false;
    });
});

// Support for mp3 chunk
jQuery(document).ready(function(){
    if (jQuery('.preview input[type="hidden"]').length != 0) {
        jQuery('.preview input[type="hidden"]').each(function () {
            var s1 = new SWFObject('resources/files/player.swf','ply','280','20','9','#ffffff');
            s1.addParam('allowfullscreen','false');
            s1.addParam('allowscriptaccess','always');
            s1.addParam('wmode','opaque');
            s1.addParam('flashvars','file=resources/files/'+jQuery(this).val()+'&duration=260&skin=resources/files/nacht-Source.swf');
            s1.write(jQuery(this).parent().get(0));
        });
    }
});

// Support for linkable tr in table
jQuery(document).ready(function(){
    jQuery(".lestvicaLinks").each(function() {
        if (jQuery(this).attr('charOff')) {
            jQuery(this).addClass('lestvicaLinksClickable');
        }

        jQuery(this).bind('click', function(e) {
            if (jQuery(this).attr('charOff')) {
                location.href = jQuery(this).attr('charOff');
            }
        });
    });
});