$(document).ready(function() {
    $("div.links a").hover(
    function() {

        var elid = $(this).attr('id');

        $('div.links a').removeClass('active');
        $(this).addClass('active');
        $("div.display div").hide();
        $("div.display div#" + elid + "").fadeIn("fast");

    },
    function() {

        var elid = $(this).attr('id');

        $('div.links a').removeClass('active');

        $("div.display div").hide();
        setBackActive();
        
    }

    );

    setToolTip('li.btn a');

});


function setToolTip(selector) {
    $(selector).cluetip({ cluetipClass: 'rounded', dropShadow: false,
        sticky: true,
        closePosition: 'bottom',
        closeText: '&nbsp;&nbsp;&nbsp;',
        showtitle: false, positionBy: 'bottomTop', topOffset: 10
    });

}
function SetActive(args) {

  //  alert(args.value);

    $('.links > a[folderID=\'' + args.value + '\' ]').addClass('active');
    var elid = $('.links > a[folderID=\'' + args.value + '\' ]').attr('id');
    $("div.display div").hide();
    $("div.display div#" + elid + "").show();
}


$(document).ready(function() {
    $().piroBox({
        my_speed: 600, //animation speed
        bg_alpha: 0.5, //background opacity
        radius: 4, //caption rounded corner
        scrollImage: false, // true == image follows the page, false == image remains in the same open position
        pirobox_next: 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
        pirobox_prev: 'piro_prev', // Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
        close_all: '.piro_close', // add class .piro_overlay(with comma)if you want overlay click close piroBox
        slideShow: 'slideshow', // just delete slideshow between '' if you don't want it.
        slideSpeed: 6 //slideshow duration in seconds(3 to 6 Recommended)
    });
});



//show loading
var tb_pathToImage = "/html/default/library/images/loading.gif";
//on page load call tb_init

function ClearLoading()
{
$("#modalContainer").fadeOut("slow");
$("#LoadingBox").fadeOut("slow");
$("#modalContainer").remove();
$("#LoadingBox").remove();
}

function ShowLoading()

{
	arrayPageSize =  getPageSize();
	var d = document

	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));

	mObj.id = "modalContainer";

	mObj.style.display = 'none';

	mObj.style.height = arrayPageSize[1] +'px';//  + getPageScroll()[1] + 'px' //+ getPageScroll()[1];

	alertObj =  d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));

	alertObj.id = "LoadingBox";

	alertObj.style.top = arrayPageSize[3] /2 - 20 + getPageScroll()[1]  + 'px';


	alertObj.style.left = ((bx()/2) - (50))+'px';//bt();		

	msg1 = alertObj.appendChild(d.createElement("p"));


	msg1.innerHTML ='<img align="center" vspace="10" hspace="10" src="/html/default/library/images/loading.gif">';

	msg1.style.textAlign='center';	
	
	
	$("#modalContainer").fadeIn("slow");
    
    
}


function getPageSize(){

	

	var xScroll, yScroll;

	

	if (window.innerHeight && window.scrollMaxY) {	

		xScroll = window.innerWidth + window.scrollMaxX;

		yScroll = window.innerHeight + window.scrollMaxY;

	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac

		xScroll = document.body.scrollWidth;

		yScroll = document.body.scrollHeight;

	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari

		xScroll = document.body.offsetWidth;

		yScroll = document.body.offsetHeight;

	}

	

	var windowWidth, windowHeight;

	

//	console.log(self.innerWidth);

//	console.log(document.documentElement.clientWidth);



	if (self.innerHeight) {	// all except Explorer

		if(document.documentElement.clientWidth){

			windowWidth = document.documentElement.clientWidth; 

		} else {

			windowWidth = self.innerWidth;

		}

		windowHeight = self.innerHeight;

	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode

		windowWidth = document.documentElement.clientWidth;

		windowHeight = document.documentElement.clientHeight;

	} else if (document.body) { // other Explorers

		windowWidth = document.body.clientWidth;

		windowHeight = document.body.clientHeight;

	}	

	

	// for small pages with total height less then height of the viewport

	if(yScroll < windowHeight){

		pageHeight = windowHeight;

	} else { 

		pageHeight = yScroll;

	}



//	console.log("xScroll " + xScroll)

//	console.log("windowWidth " + windowWidth)



	// for small pages with total width less then width of the viewport

	if(xScroll < windowWidth){	

		pageWidth = xScroll;		

	} else {

		pageWidth = windowWidth;

	}

//	console.log("pageWidth " + pageWidth)



	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;

}

function getPageScroll(){



	var xScroll, yScroll;



	if (self.pageYOffset) {

		yScroll = self.pageYOffset;

		xScroll = self.pageXOffset;

	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict

		yScroll = document.documentElement.scrollTop;

		xScroll = document.documentElement.scrollLeft;

	} else if (document.body) {// all other Explorers

		yScroll = document.body.scrollTop;

		xScroll = document.body.scrollLeft;	

	}



	arrayPageScroll = new Array(xScroll,yScroll) 

	return arrayPageScroll;

}



function GetForm()
{
	var theForm;
	theForm = document.forms[0];
	if (!theForm)		
		theForm = document.forms['aspnetForm'];
	if (!theForm) {
    theForm = document.aspnetForm;
   }   	
  GetForm = theForm;
}

function SetAction(action, args) {
 	SetFieldValue("__HiddenAction", action);
 	SetFieldValue("__HiddenArgs", args); 	 	
}

function SetActionSubmit(action, args) {
	SetAction(action, args);
	var form = document.forms[0];
	if (form)
		form.submit();	
}

function SetActionSubmitVal(action, args) {
  var valid = true;
  if (typeof(Page_ClientValidate) == 'function')
    valid = Page_ClientValidate();
     
  if (valid)
     SetActionSubmit(action, args);
}

function SetFieldValue(fieldName, value) {
 	var item = GetField(fieldName);
	if (item != null) {
		item.value = value;		
	}
}

function GetFieldValue(fieldName) 
{
 	var item = GetField(fieldName);
	if (item != null) 
		return item.value;		
  else
    return '';	
}


function GetField(fieldName)
{
  var items;
	items = window.document.getElementsByName(fieldName);
  if (items.length == 1) 
		return items.item(0);
	else
	  return window.document.getElementById(fieldName);;			
}


var t = 0; var Width; var height; var title; var Slika = new Image(); function ShowFullImage(strUrl,width,height,title)
{ Slika.src = strUrl; var aLink = document.createElement('a'); aLink.href = strUrl; aLink.rel='lightbox'; aLink.innerHTML = '<img src="'+strUrl+'">'; myLightbox.start(aLink);}
function resizeWindow(Slika, title,width,height)
{ var ScreenH = screen.height; var ScreenW = screen.width; if(window.innerWidth)
{ LeftPosition =(window.innerWidth-width)/4; TopPosition =((window.innerHeight-height)/4)-50;}
else
{ LeftPosition =(parseInt(window.screen.width)- width)/4; TopPosition=((parseInt(window.screen.height)-height)/4)-50;}
attr = 'resizable=no,scrollbars=no,width=' + width + ',height=' + height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' + TopPosition + ''; popWin=window.open('#', 'new_window', attr); popWin.document.write('<html><head><title>Slika</title></head>'); popWin.document.write('<body id="body" style="margin:0px; padding:0px; background:#ffffff URL(/library/images/loading.gif) 100px 100px no-repeat;" >'); popWin.document.write('<table id="mainTbl" style="visibility: hidden"><tr><td valign="center" align="center" ><img id="Slikca" src="'+Slika.src+'" title="'+Slika.alt+'" alt="'+title+'" onClick="self.close();"></td></tr>'); popWin.document.write('<tr><td height="20" align="right"><input style="border:none;" type="button"  value="Zapri"  onClick="self.close();" name="close" value="Zapri okno" ></td></tr></table>'); popWin.document.writeln('<script>'); popWin.document.writeln('function ResizeMe()'); popWin.document.writeln('{'); popWin.document.write('var ScreenH = document.height;'); popWin.document.write('var ScreenW = document.width;'); popWin.document.writeln('var Width = document.getElementById(\'Slikca\').width;'); popWin.document.writeln('var Height = document.getElementById(\'Slikca\').height;'); popWin.document.write('if(document.getElementById(\'Slikca\').complete)'); popWin.document.write('{ clearTimeout(t); '); popWin.document.writeln('window.resizeTo(Width +20 ,Height + 120);'); popWin.document.write('document.getElementById(\'mainTbl\').style.visibility=\'visible\';'); popWin.document.write('document.getElementById(\'body\').style.background=\'none\';'); popWin.document.write('}'); popWin.document.write('else'); popWin.document.write('{ t=setTimeout(\"ResizeMe()\",300); }'); popWin.document.write(''); popWin.document.writeln('}'); popWin.document.write(''); popWin.document.write(''); popWin.document.write(''); popWin.document.write(''); popWin.document.write(''); popWin.document.writeln('t=setTimeout(\"ResizeMe()\",300);'); popWin.document.writeln('</script>'); popWin.document.writeln('</body></html>');}
function ShowPopUp(url,title, width, height)
{ 

		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(title===null){title="";}
		$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		


	   var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   

			TB_WIDTH = (width*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (height*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
				
tb_position();
            $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+title+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>Zapri</a> ali Esc</div></div><iframe frameborder='0' hspace='0' src='"+url+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
						$("#TB_load").remove();
						$("#TB_window").css({display:"block"});	
	
			$("#TB_closeWindowButton").click(tb_remove);

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				} 	
			};			
			

/**/


}


function DrawAlert(header)
{ var d = document
mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div")); mObj.id = "modalContainer"; mObj.style.height = document.body.scrollHeight+'px'; alertObj = mObj.appendChild(d.createElement("div")); alertObj.id = "alertBox"; alertObj.style.top = bo()+by()/2-200; alertObj.style.left = ((bx()/2) - (250)); msg1 = alertObj.appendChild(d.createElement("p")); msg1.id="btnCont"; msg1.appendChild(d.createTextNode(header)); mObj.onclick = function() { d.getElementsByTagName("body")[0].removeChild(d.getElementById("modalContainer"));}
}
function by()
{ var moz=(document.getElementById&&!document.all)?1:0; return (moz) ? self.innerHeight : document.body.clientHeight;}
function bx()
{ var moz=(document.getElementById&&!document.all)?1:0; return (moz) ? self.innerWidth : document.body.offsetWidth;}
function bo()
{ return (moz) ? window.pageYOffset : document.body.scrollTop;}
function bt()
{ with(document.getElementById('alertBox').style)
{ top = bo()+by()/2-100;}
b = setTimeout('bt()',10);}
function CheckInput(element)
{ if(element.type != undefined || element.type != null)
{ if(element.type == "text")
ShowTextAlert(element); if(element.type == "radio")
ShowRadioAlert(element); if(element.type == "checkbox")
ShowCheckBoxAlert(element); if(element.type == "textarea")
ShowTextAlert(element);}
}






