NS = (navigator.appName=="Netscape")?true:false;
IEE = (navigator.appName=="Microsoft Internet Explorer")?true:false;
OP = (navigator.appName=="Opera")?true:false;
SupeIE = (navigator.appName=="Microsoft Internet Explorer"&&navigator.appVersion.substr(22,1)==6)?true:false;
version = navigator.appVersion.substr(22,1);
NetScapeBrow = (navigator.appName=="Netscape")?true:false;
ExplorerBrow = (navigator.appName=="Microsoft Internet Explorer")?true:false;

function objOverlay(O) {
	var oL = O.length, c = [];
	for(var i=0; i<oL; i++) {
		if(i%2==0) {
			c.push(O[i+1])
			$(O[i]).mouseenter(function(e){
				var $this = $(this), classN = new String(this.className), num = Number(classN.match(/\d{1,}/))-1, C = c, bgc = C[num];
				this.storeBGC = $this.css('background-color');
				$this.css({'background-color': bgc,'cursor': 'pointer'})
			}).mouseleave(function(){
				var $this = $(this);
				$this.css('background-color',this.storeBGC)
			});	
		}
	}
}
dcAjaxResize = function() {
	if(!$('.shadow')) return;
	var resMe = $('.shadow'), readMe = $('#ajaxC0nt3nt'), resH = resMe.height(), readH = readMe.height(), resW = resMe.width(), readW = readMe.width();
	var $this = document.getElementById('ajaxC0nt3nt')
	
	var incH = ($this.befH)?(readH-$this.befH):false;
	var newH = (incH)?(Number(incH)+Number(resH)):false;
	
	if(newH) {
		resMe.height(newH)
		resMe.dcResize().dcResize(false);
		
	}
	
	$this.befH = readH;
}

function resizeFF() {
	var Height = window.innerHeight;
	var Width = window.innerWidth;
	var eHeight =document.documentElement.offsetHeight;
	var eWidth =document.documentElement.offsetWidth;

	/**************************************/
	/***   Resize Main Index						***/
	/**************************************/
	
	var header = document.getElementById('readMeHeader').offsetHeight;
	var navLine = document.getElementById('readMeNavLine').offsetHeight;
	var footer = document.getElementById('readMeFooter').offsetHeight;
	var loc = document.getElementById('resizeMeMainWindow');
	
	
	var mainFrameDeduct = Number(header+navLine+footer);
	var allHei = Number(loc.offsetHeight+mainFrameDeduct)
	var tmpMainFrameIE_Height = eHeight-mainFrameDeduct;
	var tmpMainFrameNS_Height = Height-mainFrameDeduct;
	var mainFrameIE_Height = (tmpMainFrameIE_Height<200)?200:tmpMainFrameIE_Height;
	var mainFrameNS_Height = (tmpMainFrameNS_Height<200)?200:tmpMainFrameNS_Height;
		
	if(NS) {
		loc.style.height = mainFrameNS_Height+"px"; 
	} else if(IEE && version<=6) {
		loc.style.height = mainFrameIE_Height-4+"px"; 
	} else if(IEE && version == 7) {
		loc.style.height = mainFrameIE_Height+"px";
	} else if(IEE && version >= 8) {
		loc.style.height = mainFrameIE_Height-4+"px";
	} else if(OP) {
		loc.style.height = mainFrameNS_Height+"px"; 
	} else {
		loc.style.height = mainFrameNS_Height+"px";
	} 
	
}


function getHtmlContent(path) {
	if (typeof XMLHttpRequest != 'undefined') {
		var httpRequest = new XMLHttpRequest();
		httpRequest.open('GET', path, false);
		httpRequest.send(null);
		return httpRequest.responseText;
	}
		
}

function trace(add,text) {
	if(!document.getElementById("traceTheError")) {
		$("<div class='traceMe' id='traceTheError'></div>").appendTo("body");
		//return trace(add,text);
	}
	var obj = document.getElementById("traceTheError");
	
	if(obj) {
		if(add==1)
		obj.innerHTML += text+"<br>";
		else
		obj.innerHTML = text;
	}
}



function posAddWin() {
	var win = document.getElementById("infoAdd");
	var obj = document.getElementById('infoAddBack');
	
	if(ExplorerBrow) {
		var winW =document.documentElement.offsetWidth;
		var winH =document.documentElement.offsetHeight;
	} else {
		var winW = window.innerWidth;
		var winH = window.innerHeight;
	}
	var wW =win.offsetWidth;
	var wH =win.offsetHeight;
	
	var mL = Number(winW-wW)/2;
	var mT = Number(winH-wH)/2;
	win.style.top = mT+"px";
	win.style.left = mL+"px";
}
function infoAddNav(what) {
	var win = document.getElementById("infoAdd");
	var obj = document.getElementById('infoAddBack');
	var time = 2000;
	if(what) {
		win.style.display="block";
		obj.style.display="block";
		posAddWin();
		$(win).fadeTo(time, 1);
		$(obj).fadeTo(time, .9);
	} else {
		$(win).fadeTo(time, 0, function(){
															win.style.display="none";
													 });
		$(obj).fadeTo(time, 0, function(){
															obj.style.display="none";
													 });
	}
}
function fadeObj(ele, num) {
	try {
		$(ele).fadeTo(2000, num);
	} catch(taNapakaSePojavAndraz) { }
}





function pre_00(d_) {
	if (d_.length==1){ d_="0"+d_};
	return d_
}

function svetlost(col,proc,proc2) {
	proc=200-proc;
	x=proc*1.275;
	
	proc2=100-proc2;
	y=proc2*2.55;
	
	colo_r=parseInt(col.substr(1,2),16)
	colo_g=parseInt(col.substr(3,2),16)
	colo_b=parseInt(col.substr(5,2),16)
	
	if(x>127.5) {
		x=x-127.5
		colo_r=colo_r-x*(colo_r-0)/127.5
		colo_g=colo_g-x*(colo_g-0)/127.5
		colo_b=colo_b-x*(colo_b-0)/127.5
	} else {
		x=127.5-x
		colo_r=colo_r-x*(colo_r-255)/127.5
		colo_g=colo_g-x*(colo_g-255)/127.5
		colo_b=colo_b-x*(colo_b-255)/127.5
	}
	if(proc2) {
		k_r=127.5
		k_g=127.5
		k_b=127.5
		if(colo_r<127.5){k_r=127.5}
		if(colo_g<127.5){k_g=127.5}
		if(colo_b<127.5){k_b=127.5}
		colo_r=colo_r-y*(colo_r-k_r)/255
		colo_g=colo_g-y*(colo_g-k_g)/255
		colo_b=colo_b-y*(colo_b-k_b)/255
	}
	
	colo_r=pre_00((Math.floor(colo_r).toString(16)))
	colo_g=pre_00((Math.floor(colo_g).toString(16)))
	colo_b=pre_00((Math.floor(colo_b).toString(16)))
	
	return "#"+colo_r+colo_g+colo_b
}




function zapriDiv(divID) {
	var obj= document.getElementById(divID);
	obj.style.visibility = "hidden";
}

function odpriDiv(divID) {
	var obj= document.getElementById(divID);
	obj.style.visibility = "visible";
}

function makesure(msg) {
	
	if(msg == null) {
		msg = 'Ali ste prepričani, da želite zbrisati?';
	}
	
	if(confirm(msg)) {
		return true;
	} else {
		return false;
	}
}



function sleep(miliseconds) {
    // http://kevin.vanzonneveld.net
    // +   original by: Christian Doebler
    // %          note: For study purposes. Current implementation could lock up the user's browser. 
    // %          note: Consider using setTimeout() instead.
    // *     example 1: sleep(1);
    // *     returns 1: 0

    var start = new Date().getTime();
    while (new Date().getTime() < start + miliseconds);
    
    return 0;
}




function isValidEmail(str) {

return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

}

function isValidWWW(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("//") > 0);
 
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= ".";
var minYear=1800;
var maxYear=2200;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}

// end date validation
// LOGIN//

$(document).ready(function(){

	$(".buttonSlide").click(function(){
	  $("#panel").slideToggle("slow");
	  $(this).toggleClass("active");
	});

});

// DROP DOWN MENU//
var timeout         = 200;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#popUpButton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
