﻿var max;
/*guerystring*/
$.urlParam = function(name){var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (!results) { return 0; }return results[1] || 0;} 

var pid= $.urlParam('PageID');
var nid= $.urlParam('NewsID');

(function($)
{ 
// plugin definition
	$.fn.SetHeight = function ()
	{
			var docHeight;
			var headerHeight, footerHeight, containerHeight, contentHeight ;	
			docHeight = parseInt($(document).height());
			headerHeight = parseInt($("#header").height());
			containerHeight = parseInt($(".container").height());
			footerHeight = parseInt($("#footer").height());
			//	alert("window: " + docHeight + " head:" + headerHeight + " foot:" + footerHeight + "  container:" + containerHeight  );
			var razlikaHeight = docHeight - headerHeight - footerHeight-20;
			$(".container").height(razlikaHeight );
			//http://www.johnchapman.name/using-simple-jquery-to-set-the-height-of-a-div-to-the-page-height/	
	}

})(jQuery);

(function($)
{
		//100%
	$(window).resize(function() {
			$('body').SetHeight();		
		});

	$.fn.FixMe = function ()
	{
		
		//red letters
		$(".hpc span").each(function () {
		 var el = $(this),
		 text = el.html(),
		 first = text.slice(0, 1),
		 rest = text.slice(1);
		 el.html("<span class='firstletter'>" + first + "</span>" + rest + "&nbsp;");
		});
		
		//gl meni
		$(".navlist li").each(function () {
			var mainmenuID = $(this).attr("id");
		 	if (pid == mainmenuID)
		 	{	 	
		 	$(this).children("a").attr("class","current");
		 	}	 
		});
		
		// submenu - active
		$(".SubMenu li").each(function () {
			var submenuID = $(this).attr("id");
			var parentID = $(this).attr("parent");
		 	if (pid == submenuID )
		 	{	 	
			 	$(this).attr("class","current");		
				$('body').CheckParent(parentID);
		 	}
		});

		//switch to books 
		if (pid==33)
		{
			$("#booklist").show();
			$(".container").attr("id","bgBook")			
		}else
		{
			$("#newslist").show();
		}

	}
	
	$.fn.CheckParent= function (parent)
	{
		$(".SubMenu li").each(function () {
		 	if (parent != $(this).attr("id") )
		 	{	 	
				if (parent != $(this).attr("parent") )
				{//$(this).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;}
});
