/* Cookie plugin Copyright (c) 2006 Klaus Hartl (stilbuero.de) Dual licensed under the MIT and GPL licenses: http://www.opensource.org/licenses/mit-license.php http://www.gnu.org/licenses/gpl.html */
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};

 $(document).ready(function(){

/************************************** promjena standardnih funkcija **************************************/
    //promjena funkcije openImagePopup  
    $("img").filter(function(){return $(this).attr('onclick'); }).each(function() {   
        var attrValue = $(this).attr("onclick");
	    if($.browser.mozilla) { var re = new RegExp("\"(.*?)\""); } else { var re = new RegExp("'(.*?)'"); }
	    var attrUri = re.exec(attrValue);  
	    if (attrUri != null) {
	        $(this).removeAttr("onclick").wrap("<a class='zoom' href='" + URL_prefix + attrUri[1] + "' title='Narodno uciliste Rijeka'></a>");
	    }
    });
    //promjena funkcije otvori_prozor
    $("a[href^='javascript:otvori_prozor']").each(function() {
        var hrefVal = $(this).attr("href");
        var reL = new RegExp("[0-9]+");
        var hrefUri = reL.exec(hrefVal);
        if (hrefUri != null) {
            $(this).removeAttr("href").attr("href",URL_prefix + "Home.aspx?PageID=" + hrefUri).addClass("colorbox");
        }
    });
    function openImagePopup() {
        return false;
    }
    //target:_top kao modalni link
    $("a[target^='_top']").each(function() {
        $(this).removeAttr("target").addClass("colorbox");
    });
    //detekcija print preview-a
//    var url = window.location.href;
//    var urlDetectParam = window.location.href.indexOf('?')+1;
//    if (urlDetectParam == '0') {
//        $(".print a").attr("href", url + "?style=print");
//    } else {
//        $(".print a").attr("href", url + "&style=print");
//    } 
//    var printMode = document.location.toString();
//    if (printMode.match('style=print')) { 
//       $('body').append("<div id=\"cboxPrint\">Print</div>");
//       $("#cboxPrint").click(function(){ self.print(); return false; });
//       $("#wrapper, #header, #contentTop, #breadAccessBox, #social, #footer").remove(); //brisemo ono sto ne ukljucujemo u print
//       $('a').attr({'href':'javascript:void(0)'}).removeAttr('onclick').removeClass('colorbox') //disable my links, remove my js events and disable modal thingie
//       $('select, input, textarea').attr({"disabled":"disabled"})//disable my selects
//    }

//disable linkova u print modu
    var printMode = document.location.toString();
    if (printMode.match('q=print')) { 
       $('a').attr({'href':'javascript:void(0)'}).removeAttr('onclick').removeClass('colorbox') //disable my links, remove my js events and disable modal thingie
       $('select, input, textarea').attr({"disabled":"disabled"})//disable my selects
    }
        
/************************************** incijalizacija plugin funkcija **************************************/
    $(".zoom").colorbox(); 
    $(".colorbox").colorbox({width:"70%", height:"70%", iframe:true}); 
    if ($.browser.msie && $.browser.version == "6"){
        $('.login').colorbox({width:"940px",height:"480px",inline:true,opacity:"0.8",href:function(){return $(this).attr("href")}});
    } else {
        $('.login').colorbox({width:"940px",height:"380px",inline:true,opacity:"0.8",href:function(){return $(this).attr("href")}});
    }
    
/***************************************** custom dom manipulations *****************************************/ 
    //addClass - ie6 nav hover issue
    if($.browser.msie && $.browser.version.substr(0,1)<7) {
        $("#menu ul li").hover(function(){ $(this).addClass("over");}, function(){$(this).removeClass("over"); }); //ie6 hover
    }    
    //addClass - form required fields are empty
	if ($('.info-label span').hasClass('error') ) {
        $('.required').each(function(){
            if ($(this).children('input, textarea').val() == '') {
                $(this).children('input, textarea').addClass('error');
            }
        });  
    }
    //addDiv - text box top and bottom
    $('#contentTop, #contentTopDefault').before('<div id="contentTopImg"></div>');
    $('#contentText').before('<div id="textTop"></div>');
    $('#contentText').after('<div id="textBottom"></div>');
    $('#page #wrapper, #page3rd #wrapper').after('<div id="contentBottomPage"></div>');
    $('#menu ul ul li.last').after('<div id="menuLast"></div>');
    
    //Resizable text
    if ($.cookie('fontSize')) $('#contentText, #newsDefautl').css('font-size', $.cookie('fontSize')+'px');
    $.fn.extend({
	    setFontSize: function(offset, target) {
		    return this.click(function() {
			    var size = parseInt($(target).css('font-size')) + offset;
			    if (size <= 10) size = 10;
			    $(target).animate({fontSize: size+'px'}, 1);
			    var date = new Date();
			    date.setTime(date.getTime()+(30*24*60*60*1000)); //month from now
			    var expires = '; expires='+date.toGMTString();
			    document.cookie = 'fontSize='+size+expires+'; path=/';
			    return false;
		    });
	    }
    });
    $('#accessMax').setFontSize(+1, '#contentText, #newsDefault');
    $('#accessMin').setFontSize(-1, '#contentText, #newsDefault');
    
    // home news default
    $('.scroller').jScrollPane({showArrows:true, scrollbarWidth: 20});
        
});
