﻿
/*guerystring*/
$.urlParam = function(name){
//name = name.toLowerCase();
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (!results) { return 0; } return results[1] || 0;} 

var pid= $.urlParam("PageID"); //if (pid=="0"){pid= $.urlParam("pageID")}; 
var nid= $.urlParam("NewsID");
var page= $.urlParam("page");

(function($)
{
	$.fn.PrintMe = function ()
	{
		$("#printme").click(function(){
			$(this).hide();
			window.print();
			window.close();
		});
	}


	$.fn.FixDocuments = function ()
	{
		$("#docarhivDocList a").each(function(){
			//ext koji ćemo nadodat na dokument koji ispisuje containter.description
			if ( $(this).text() == ""){
				$(this).text($(this).attr("filename"))
			}else{
				$(this).text($(this).text()+"."+$(this).attr("filename").split(".")[1]);
			}
		});
	}



	$.fn.LightBoxMe = function ()
	{
		$('#txt-content img').each(function() 
			{ 
				$(this).wrap($('<a/>').attr('href', this.src));
				//resize		
  				if ( $(this).width() > "500"){
	  				$(this).removeAttr("width"); 
	  				$(this).removeAttr("height");   				
  				$(this).width("450px")}
			});
	
		$('#txt a[name!="doc"]:has("img")').lightBox({
				fixedNavigation:true,
				imageLoading:			'templates/AZOP_hr/img/lightbox/lightbox-ico-loading.gif',
				imageBtnPrev:			'templates/AZOP_hr/img/lightbox/lightbox-btn-prev.gif',	
				imageBtnNext:			'templates/AZOP_hr/img/lightbox/lightbox-btn-next.gif',	
				imageBtnClose:			'templates/AZOP_hr/img/lightbox/lightbox-btn-close.gif',
				imageBlank:				'templates/AZOP_hr/img/lightbox/lightbox-blank.gif',
				containerBorderSize:	10,
				containerResizeSpeed:	400,
				txtImage:				'',
				txtOf:					'/'
			});
	}
		
	$.fn.FixMe = function ()
	{
			//eng dodaci
			if ( $("#top").attr("lang")=="en"){
				$(".header-main").addClass("header-main-en");
			}
	
	
			//gl meni
			$("#lmeni ul li").each(function () {
				var mainmenuID = $(this).attr("id");
			 	if (pid == mainmenuID)
				 {	$(this).children("a").addClass("sub-selected"); }
			});			
			$("#lmeni ul div").each(function () {
				var mainmenuID = $(this).attr("id");
			 	if (pid == mainmenuID)
				 {	$(this).children("a").addClass("sub-selected"); }
			});			
			
			
			//lang
			$("#lang span:first-child").remove();
			$("#rssimg").mouseover(function() {
				$(this).attr("src","templates/AZOP_hr/img/rss-1.png");
			}).mouseout(function(){
				$(this).attr("src","templates/AZOP_hr/img/rss.png");
			});
			
			//breadcrumbs
			var drugitab="drugitab";
			if ( $("#top").attr("lang")=="en"){
				$("#breadcrumbs-hold a").first().text("home").attr("href","cpage.aspx?page=default.aspx&PageID=47");
				$("#breadcrumbs-hold .listtxt").text("You are here");
				drugitab = "drugitab-en";
			}else
			{
				$("#breadcrumbs-hold a").first().text("početna").attr("href","default.aspx");
			}			
			
			//set main tabs (default)
			$("#mainTabs li:even").children("a").addClass("prvitab");
			$("#mainTabs li:odd").children("a").addClass(drugitab);
			$("#mainTabs").css("visibility","visible");
			
			//set rootNav
			var myRoot;
			if ($("#breadcrumbs-main").children().length > 0)
			{
				myRoot = $("#breadcrumbs-main a").next().attr("href");
				if (typeof(myRoot)!='undefined'){myRoot=myRoot.match(/[\d]+$/)[0]}
				else
				{myRoot=pid;}
			}else{
				myRoot=pid;
			}
			if (myRoot=="0"){myRoot=$('body').attr("rootNav");}				
			$('body').attr("rootNav",myRoot);

			switch (myRoot){
				case '1':
				break;
				case '3':	
					$("#mainTabs li a[root='"+myRoot+"']").addClass("prvitab-sel");
					$("*[rootNav='"+myRoot+"']").show();
				break;
				case '4':
					$("#mainTabs li a[root='"+myRoot+"']").addClass(drugitab+"-sel");
					$("*[rootNav='"+myRoot+"']").show();
				break
				
				/*engl*/
				case '47':
				//if (page!='default.aspx')
			//	{
					$("#mainTabs li a[root="+myRoot+"]").addClass("prvitab-sel");
				//}
					//myRoot = parseInt(myRoot)+1;//makni podmeni
					//$("ul[rootNav='"+myRoot+"']").remove();
					$("*[rootNav='"+myRoot+"']").show();
				break;
				case '48':	
					$("#mainTabs li a[root="+myRoot+"]").addClass(drugitab+"-sel");
					//myRoot = parseInt(myRoot)-1; //makni podmeni
					//$("ul[rootNav='"+myRoot+"']").remove();
					$("*[rootNav='"+myRoot+"']").show();
				break;
			}	
	
	
			//doclinks - dodaj padding:6 ako nema
			/*if ($("#newslistIzdvojeniLinkovi").css("display")=="none")
				{$("#rightBannerOne").css("padding-bottom","6px")
				}
			*/
								
			// sitemap remove			
			if ($("#txt-content").html() != "") { $("#txt-sitemap").remove() }
			
			
			//linkovi dodaj _blank
			$("#vanjskilinkovi a").each(function(){
				$(this).attr("target","_blank");
			});
		
			//rightBannerHighlight
			if ($("#rightBannerHighlight[rootNav='"+myRoot+"'] a").size()==0){$("#rightBannerHighlight[rootNav='"+myRoot+"']").remove()}
				$("#rightBannerHighlight HR").last().remove();
			
			//baneri makni link ako nema
			$("#bannerList a").each(function() {
				if ($(this).attr("href")=='' ){$(this).children("img").unwrap()}
			})
			$("#rightBannerOne a").each(function() {
				if ($(this).attr("href")=='' ){$(this).children("img").unwrap()}
			})
			
			//kalendar
		 	if ( $("#cal[rootNav='"+myRoot+"'] #cal-item").size()==0) {$("#cal[rootNav='"+myRoot+"']").css("display","none").remove()}
			
			//doclinks	
		 	if ( $("#IzdvojeniLinkovi[rootNav='"+myRoot+"'] a").size()==0) {$("#IzdvojeniLinkovi[rootNav='"+myRoot+"']").remove()}
		 	
			//topnews
			if( $(".topnews").size()== "1"){$(".introNews").remove();}
			
	}
	

	
})(jQuery);


$.extend(
{URLEncode:function(c){var o='';var x=0;c=c.toString();var r=/(^[a-zA-Z0-9_.]*)/;
  while(x<c.length){var m=r.exec(c.substr(x));
    if(m!=null && m.length>1 && m[1]!=''){o+=m[1];x+=m[1].length;
    }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);
    o+='%'+(h.length<2?'0':'')+h.toUpperCase();}x++;}}return o;},
URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;
  while((m=r.exec(o))!=null && m.length>1 && m[1]!=''){b=parseInt(m[1].substr(1),16);
  t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}
});
