
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();
    initTooltipTitleEvent();
}

function initTooltipTitleEvent() {
    jQuery('a.tooltipTitleEvent').cluetip({
        local:true,
        cursor: 'pointer',
        cluetipClass:'jtip'
    });
}

//ajax call for calendar
jQuery(document).ready(function(){
    bindCalendarClick();

    initTooltipTitleEvent();

    //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;
    });
}

var prevTitle = null;
jQuery(document).ready(function(){
    jQuery('#newsCycle').cycle({
        timeout: 6500,
        speed:   600,
        startingSlide: 0,
        //fx: 'turnLeft',
        before: function() {
            //added selected class to navigation li on change
            var title = this.lang;
            jQuery("li[lang="+title+"]").addClass("selected");
            jQuery("li[lang="+prevTitle+"]").removeClass("selected");
            prevTitle = title;
        }
    });

    jQuery('#goto1').hover(function() {
        jQuery('#newsCycle').cycle(0);
        return false;
    });
    jQuery('#goto2').hover(function() {
        jQuery('#newsCycle').cycle(1);
        return false;
    });
    jQuery('#goto3').hover(function() {
        jQuery('#newsCycle').cycle(2);
        return false;
    });
    jQuery('#goto4').hover(function() {
        jQuery('#newsCycle').cycle(3);
        return false;
    });

    jQuery("#explore").click(function (){
        if (jQuery("#exploreDiv").css("display") == "block"){
            jQuery("#exploreDiv").fadeOut(500);
        }
        else{
            jQuery("#exploreDiv").fadeIn(500);
        }
        return false;
    });
	jQuery("#exploreDiv").hover(function (){
		jQuery(this).show();
	}, function(){
		jQuery(this).hide();
	});
});

// 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();

        var videoSmallRatio = jQuery('#smallvideo'+id).val();

        if (videoSmallRatio == 1){
            //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;
            }
        }else{
             if (videoRatio == 'wide'){
                var width = 640;
                var height = 360;
            }else{
                //340 x 256 - 4:3
                var width = 640;
                var height = 480;
            }
        }

        // 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();
        var videoSmallRatio = jQuery('#smallvideo'+key).val();

        //hardcoded for popup video
        if (videoSmallRatio == 1){
            //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;
            }
        }else{
             if (videoRatio == 'wide'){
                var definedWidth = 640;
                var definedHeight = 360;
            }else{
                //340 x 256 - 4:3
                var definedWidth = 640;
                var definedHeight = 480;
            }
        }
        //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");
}

function loadFlashTrigiShop() {
    var so = new SWFObject("http://www.nzs.si/resources/files/trigi-shop.swf", "Trigi shop", "275", "210", "8");
    so.addParam("wmode", "transparent");
    so.write("trigishop");
}

function loadFlashTrigiShopEn() {
    var so = new SWFObject("http://www.nzs.si/resources/files/trigi-shop-en.swf", "Trigi shop", "275", "210", "8");
    so.addParam("wmode", "transparent");
    so.write("trigishopen");
}

function loadFlashBigTrigi() {
    var so = new SWFObject("http://www.nzs.si/resources/files/big-trigi.swf", "Trigi shop", "275", "600", "8");
    so.addParam("wmode", "transparent");
    so.write("bigTrigiBanner");
}

function loadFlashUSP() {
    var so = new SWFObject("resources/files/uzivajmo_sponzorje.swf", "Uzivajmo sponzorje", "275", "137", "8");
    so.addParam("wmode", "transparent");
    so.write("uzivSponzorje");
}

jQuery(document).ready(function(){
    //označi vse checkbox
    jQuery("#usersAll").bind('click', function() {
            jQuery("input[type=checkbox]").attr('checked', jQuery(this).attr("checked"));
    });


    if (jQuery('#preview').get(0) != undefined) {
        loadHimnaFlash();
    }
    if (jQuery('#voscilnica').get(0) != undefined) {
        loadFlash();
    }
    if (jQuery('#koledar').get(0) != undefined) {
        loadFlashKoledar();
    }
	if (jQuery('#trigishop').get(0) != undefined) {
        loadFlashTrigiShop();
    }
	if (jQuery('#trigishopen').get(0) != undefined) {
        loadFlashTrigiShopEn();
    }
	if (jQuery('#bigTrigiBanner').get(0) != undefined) {
        loadFlashBigTrigi();
    }
	if (jQuery('#uzivSponzorje').get(0) != undefined) {
        loadFlashUSP();
    }
});

jQuery(document).ready(function(){
    //select all links in ul with rel = lightbox
    jQuery("a[rel='lightbox'], a[rel='nyromodal'], .expandPicture").nyroModal({
        contentError:'',
        type:'image',
        errorClass:'',
        resizeable:false,
        debug:false,
        css:{
            content:{
                overflow: 'hidden'
            }
        },
        minWidth: 1,
        minHeight: 1,
        gallery:'lightbox'
    });
    
    //Gallery big
    jQuery("a[class='lightboxNyro']").nyroModal({
            contentError:'',
            type:'image',
            errorClass:'',
            resizeable:true,
            autoSizable:false,
            debug:false,
            css:{content:{overflow: 'hidden'}},
            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');
            }
        });
    });
});

// LIKE IT CODE
jQuery(document).ready(function(){
    jQuery("#rateDown").bind("click", function(e){
        jQuery.get("index.php?r=likeItVote", {url: jQuery(this).attr('href'), type: 'minus'}, function(data){
            jQuery('.rateDownCount').html(data);
        });

        jQuery("#rateUpLi").toggleClass("hidden");
        jQuery("#rateDownLi").toggleClass("hidden");

        jQuery("#rateUpNoClickLi").removeClass("hidden");
        jQuery("#rateDownNoClickLi").removeClass("hidden");

        return false;
    });

    jQuery("#rateUp").bind("click", function(e){
        jQuery.get("index.php?r=likeItVote", {url: jQuery(this).attr('href'), type: 'plus'}, function(data){
            jQuery('.rateUpCount').html(data);
        });

        jQuery("#rateUpLi").toggleClass("hidden");
        jQuery("#rateDownLi").toggleClass("hidden");

        jQuery("#rateUpNoClickLi").removeClass("hidden");
        jQuery("#rateDownNoClickLi").removeClass("hidden");

        return false;
    });

	jQuery.nyroModalSettings({
    processHandler: function(settings) {
                
        var from = settings.from;
        
        var key = from.name;
        
        // Get video, pic params
        var videoRatio = jQuery('#videoRatio'+key).val();
        
        var definedWidth = 640;
        var definedHeight = 360;        
        
        if (videoRatio != null) {
            if (videoRatio == 'wide'){
                var definedWidth = 640;
                var definedHeight = 360;
            }else{
                var definedWidth = 480;
                var definedHeight = 360;
            }
        }
        
        if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
            from.href += '&autoplay=1&rel=0&showsearch=0&hd=1';
            jQuery.nyroModalSettings({
                type: 'swf',
                height: definedHeight,
                width: definedWidth,
                url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
            });
        }
    }
  });


});

//CAPTIFY - image captions
jQuery(document).ready(function(){

	var metaImgPath = jQuery("#content img").first().attr("src");
	jQuery("#fbImage").attr("content",metaImgPath);
})
