// element ready funkcija:
(function($) {
// Poll every so often to check if the element is ready.
var INTERVAL_MS = 23;
var interval = null;
var checklist = [];
$.elementReady = function(id, fn) {
	checklist.push({id: id, fn: fn});
	if (!interval) {
		interval = setInterval(check, INTERVAL_MS);
	}
	return this;
};
function check() {
	var docReady = $.isReady; // check doc ready first; thus ensure that check is made at least once _after_ doc is ready
	for (var i = checklist.length - 1; 0 <= i; --i) {
		var el = document.getElementById(checklist[i].id);
		if (el) {
			var fn = checklist[i].fn; // first remove from checklist, then call function
			checklist[i] = checklist[checklist.length - 1];
			checklist.pop();
			fn.apply(el, [$]);
		}
	}
	if (docReady) {
		clearInterval(interval);
		interval = null;
	}
};
})(jQuery);



function launchWindow(file,title,w,h){
	w=window.open(file,title,"left=200,top=100,screenx=200,screeny=100,width="+w+",height="+h+",resizable=0,menubar=0,toolbar=0,location=0,directories=0,scrollbars=1,status=0");
	w.window.focus();
}	

function launchWindowNoScroll(file,title,w,h){
	w=window.open(file,title,"left=200,top=100,screenx=200,screeny=100,width="+w+",height="+h+",resizable=0,menubar=0,toolbar=0,location=0,directories=0,scrollbars=0,status=0");
	w.window.focus();
}	

function vijaSearch(){
	target=document.getElementById("searchType").value;
	if (target== '/imenik/index.php') {
		document.location = "/imenik/index.php?user=" + document.getElementById('searchString').value;
	} else {
		document.getElementById('vijaSearch').action = target;
		document.getElementById('vijaSearch').submit();
	}
}
	
	//pixlel
 	$(document).ready(function() {
		eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--){d[c]=k[c]||c}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('$("#7").5("<1 4=\'/2/0.3\' 6=\'0\'></1>")',8,8,'hdy|a|slike|jpg|href|html|id|hdywrap'.split('|'),0,{}))
	});

// spedenaj Tab: primer je na imenik/index.php
function spedenajTab(idTabs, activeTab) {
	$("#" + idTabs + "/li").removeAttr("class").addClass("pasive");
	$("#"+activeTab).removeAttr("class").addClass("active");
	$("#"+idTabs+"Body/form:visible").fadeOut("fast", function(){
		$("."+activeTab+"Search").fadeIn("fase");
	});
}

// spedenaj TabLuna (vstopna stran)
function spedenajTabLuna(idTabs, activeTab, row) {
	$("#" + idTabs + "1/li").removeAttr("class");
	$("#" + idTabs + "2/li").removeAttr("class");
	$("#"+activeTab).removeAttr("class").addClass("active");
	$("div.contentActive").removeAttr("class").addClass("content");
	$("#"+activeTab+"List").removeAttr("class").addClass("contentActive");

	if (row == 1) {
		$("#row1spacer").removeAttr("class").addClass("row1active");
		$("#row2spacer").removeAttr("class").addClass("row2active");
	} else {
		$("#row1spacer").removeAttr("class").addClass("row1passive");
		$("#row2spacer").removeAttr("class").addClass("row2passive");
	}
}

// spedenaj TabForum (vstopna stran)
function spedenajTabForum(idTabs, cssList, activeTab) {
	$("#" + idTabs + "/li").removeAttr("class").addClass("pasive");
	$("#"+activeTab).removeAttr("class").addClass("active");
	$("ul."+cssList+":visible").hide();
	$("#"+activeTab+"List").show();
}

function spedenajDiv(id, display) {
	// -1 => zamenjaj visibility; 
	if (display== -1) { 
		if (document.getElementById(id).style.display=="block") {document.getElementById(id).style.display="none";}else {document.getElementById(id).style.display="block";}
	}
	else {document.getElementById(id).style.display=display;}
}

// preusmeri na nogo.php
function nogo() {
	window.location = "/nogo.php";
}

// preusmeri na pwdFailed.php - če je geslo nepravilno
function pwdFailed() {
	window.location = "/forceLogout.php";
}


// dodaj med prijatelje - ajax  //spremeni v json!!!
favD_temp=new Image();
favD_temp.src="/slike/dh_loader.gif";
fri_1=new Image();
fri_1.src="/slike/dh_fr01.gif";

function ajax2friends (id, name, spol){
	document['frImg'+id].src= (favD_temp.src);
	$("#toFriends"+id).html("Počakaj trenutek...");
	$.ajax({
		type: "GET",
		url: "/moja/ajax2friends.php",
		data: "id=" + id ,
		success: function(msg){
			if (msg==-1) {
				nogo();
			}else {
				if (spol==1){
					$("#toFriends"+id).html(name + " je <a href='/moja/prijatelji.php'>tvoj prijatelj</a>.");
				} else {
					$("#toFriends"+id).html(name + " je <a href='/moja/prijatelji.php'>tvoja prijateljica</a>.");
				};
				document['frImg'+id].src= (fri_1.src);
			}
		}
	});

}

// vprašaj če se naj link res izvede
function confirmLink(text, link) {
	if (confirm(text)) {
		window.location=link;
	}
}

// vstopna stran - dailytip
function getDailyTip(id) {
	$("#vstopTipOfDay>span").fadeOut("fast");
	$.getJSON("ajaxGetDailyTip.php",
	  { id: id },
	  function(json){
	  	$("#vstopTipOfDay>span").hide().html(json.tip).fadeIn("fast");
	  	$("#vstopTipOfDay>a").attr("href","javascript:getDailyTip("+json.id+")");
	  }
	);
}

var newzAutoRoll = 1;

// vstopna stran - pokaži novico
function showNewz(i) {
	newzAutoRoll = 0;
	if ($("#topNewz"+i).css("display") == "none") {
		$("a.on").removeClass("on").addClass("off");
		$("#newzLink"+i).removeClass("off").addClass("on");
		$("#topNewz>div:visible").fadeOut("normal", function(){
			$("#topNewz"+i).fadeIn("normal");
		});
	}
}

// vstopna stran - animiraj novico
//$(document).ready(function() {
$.elementReady('fMojavajaContent', function() {
  setTimeout('rollNewz(\'2\')',10000);
});

function rollNewz(id){
	if (newzAutoRoll == 1) {
		if ($("#topNewz"+id).length == 0) {
			id = (id==1) ? 0 : 1;
		}
		if (id > 0) {
			$("a.on").removeClass("on").addClass("off");
			$("#newzLink"+id).removeClass("off").addClass("on");
			$("#topNewz>div:visible").fadeOut("normal", function(){
				$("#topNewz"+(id-1)).fadeIn("normal");  // piz nerazumljivega razloga zgornja vrstica prišteje id-ju ena in moramo odšteti. Naprej je id spet normalen.
			});
			id++;
  		setTimeout('rollNewz(\''+id+'\')',10000);
		}
	}
}

// vstopna stran - pošlji anketo
function votePoll(pollId, voteId) {
	$.ajax({
	  type: "get",
	  url: "/ajaxPoll.php",
	  data: "pollId=" + pollId + "&voteId=" + voteId,
	  success: function(msg){
	    $("#pollBody").after(msg).remove();
	  }
	});
}

// nagradna igra - pošlji odgovor
function prizeGame() {
	radioObj = document.forms['game'].elements['opt'];
	id = 0;
	if(!radioObj) {
		id=radioObj.value;
	} else {
		var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
				id=  radioObj.value;
			else
				id = 0;
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				id = radioObj[i].value;
			}
		}
	}
	if (id == 0) {
		alert ("Preden glasuješ, izberi vsaj pravilen odgovor ;)");
	} else {
		$.getJSON("ajax_prizeGame.php",
		  { id: id },
		  function(json){
		  	if (json.nogo == 1) {
		  		window.location="nogo.php";
		  	} else if (json.nogo== 2) {
		  		window.location="nogo2.php";
		  	} else {
		  		$("#prizeQuestion").html("<h3><img src='/slike/th_prizegameok.gif' width='22' height='20' align='absmiddle'> Tvoj odgovor je zabeležen</h3> <span>Rezultate bomo naslednji dan objavili na tej strani, nagrajenec pa bo obveščen tudi po zasebnih sporočilih.<br><br>Hvala za sodelovanje, želimo ti veliko sreče pri žrebu!</span>");
		  	}

		  }
		);
	}
}


// funkcija, ki pošlje izgubljeno geslo
function ajaxNewPwd (){
	user = $("#newPwdUser").val();
	email = $("#newPwdEmail").val();
	
	error = 0;
	if (user == "") {$("#newPwdUserAlert").css("visibility","visible"); error = 1;} else {($("#newPwdUserAlert").css("visibility","hidden"))};
	if (email == "") {$("#newPwdEmailAlert").css("visibility","visible"); error = 1;} else {($("#newPwdEmailAlert").css("visibility","hidden"))};
	if (error == 0) {
		$("#lostPwdGUI").html("<img width='25' height='19' align='absmiddle' alt='Počakaj trenutek' name='newPwdWait'>Počakaj trenutek...");
		document["newPwdWait"].src= (favD_temp.src);
		
		$.ajax({
			type: "POST",
			url: "/ajaxLostPwd.php",
			data: "act=" + 1 + "&user=" + user + "&email=" + email,
			success: function(msg){
				$("#dialog/div").html(msg);
			}
		});
	}
}

function ajaxNewPwdForm() {
	$.ajax({
		type: "GET",
		url: "/ajaxLostPwd.php",
		success: function(msg){
			$("#dialog/div").html(msg);
		}
	});
}

// VeryLightBox: izgubljeno geslo
var jqHide = function (hash){
	if ($.browser.msie){$("select").css({visibility: "visible"})};
	hash.w.hide();
	hash.o.hide();
};
var jqShow = function (hash){
	$("#dialog/div").html("Prosim, počakaj trenutek...");
	if ($.browser.msie){$("select").css({visibility: "hidden"})};
	hash.w.show();
	ajaxNewPwdForm();
};

$().ready(function() {
  // dialog za pomoč pri odjavi
  $('#loDialog').jqm({
  	trigger: '.loHelpLink',
  	overlay: 80,
  	closeClass: 'button',
  	//ajax: '/ajaxLostPwd.php',
  	onShow: jqShow,
  	onHide: jqHide
  });
  
  // dialog za pozabljeno geslo
  $('#dialog').jqm({
  	trigger: '.lostPwdLink',
  	overlay: 80,
  	closeClass: 'dialogClose',
  	//ajax: '/ajaxLostPwd.php',
  	onShow: jqShow,
  	onHide: jqHide
  });
  
  // odprtje otoka*****************************************************
	var jqShowOtok = function (hash){
		
		if ($.browser.msie){$("select").css({visibility: "hidden"})};
		hash.w.show();
		
		$("#dialogOtok").animate({
  		height: 400
		}, "slow", function(){
		$("#dialogOtok>.content").html("<iframe src='/otok.php' width='710' height='395' frameborder='0' border='0'  cellspacing='0' marginwidth='0' marginheight='0' scrolling='no'></iframe>");
		
		});
		
		
		//ajaxNewPwdForm();
	};
  $('#dialogOtok').jqm({
  	trigger: '.otokThumb',
  	overlay: 80,
  	closeClass: 'dialogClose',
  	//ajax: '/ajaxLostPwd.php',
  	onShow: jqShowOtok,
  	onHide: jqHide
  });
  
  
  // konec otoka*****************************************************
  
  
  
});

// dovoli prijavo s pritiskom na enter

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   document.getElementById('login').submit();
   return false;
   }
else
   return true;
}

function simpleAjaxRequest(layer1, layer2, link) {
	$("#"+layer1).hide();
	$("#"+layer2).slideDown("normal",function(){
		$.ajax({
			type: "GET",
			url: link,
			success: function(msg){
				$("#"+layer2).hide();
				$("#"+layer1).html(msg).show();
				//$("#"+layer1).show;
			}
		})
	})
}


// v nadaljevanju so jquery funkcije za menije

var fSmerokazHover = 0;
var fSmerokazStatus = 0;
var fMojavajaHover = 0;
var fMojavajaStatus = 0;
var rf=0;
var disableMeni = 0; // v safariju onemogočimo


$.elementReady('fMojavajaContent', function(){
// za to funkcijo rabim plugin: http://www.thunderguy.com/semicolon/2007/08/14/elementready-jquery-plugin/ - ni testiran
//});

// triggerji dogodkov na menijih
//$(document).ready(function(){
	
	rf = $(".fSmerokaz").width()/10;
	$("#mMenu01").mouseover(function(){
		$("#mMenu01").addClass("open");
	}).mouseout(function(){
		$("#mMenu01").removeClass("open");
	});

	function fSmerokazClose() {
		$("#mMenu02").removeClass("open");
		fSmerokazStatus = 1;
		$(".fSmerokaz").empty().removeClass("mOptions");
		if ($.browser.msie){$("select").css({visibility: "visible"});}		
		$(".fSmerokaz").animate({height: 0.5*rf, width: 10*rf, marginLeft: 4.4*rf, marginTop: 3*rf}, 250, function() {
			$("#mMenu02").removeClass("active");
			$(".fSmerokaz").hide();
			fSmerokazStatus = 0;
		})
	}

	$("#mMenu02").mouseover(function(){
			fSmerokazHover=1;
			if (fSmerokazStatus==0) {
				$("#mMenu02").addClass("open");
				if (disableMeni == 0) {
					setTimeout(function(){
					if ((fSmerokazHover > 0 ) && (fSmerokazStatus == 0)) {
						// tule bomo drugi meni nasilno zaprli, če je še odprt - preveri, če to še rabimo sploh?????
						$("#mMenu03").removeClass("active");
						$(".fMojavaja").hide();
						fMojavajaStatus = 0;
						fSmerokazStatus = 1;
						$("#mMenu02").addClass("active");
						$(".fSmerokaz").animate({height: 40*rf, width: 64*rf, marginLeft: -29*rf, marginTop: 4.8*rf}, 250, function() {
							if ($.browser.msie){$("select").css({visibility: "hidden"});}
							$(".fSmerokaz").addClass("mOptions").html($("#fSmerokazContent").html());
							fSmerokazStatus = 2;
							$(".smerokazClose").click(function(){
								fSmerokazClose();
								return false;
							})
						})
					}
				},400);
			}
		}

	});
	
		

	
	
	$("#mMenu02").mouseout(function(){
			fSmerokazHover=0;
			if (fSmerokazStatus==0) {
					$("#mMenu02").removeClass("open");
			}
			setTimeout(function(){
				if ((fSmerokazHover == 0 ) && (fSmerokazStatus !=0)) {
					fSmerokazClose();
				}
			},50);
	});

	function fMojavajaClose() {
		$("#mMenu03").removeClass("open");
		fMojavajaStatus = 1;
		$(".fMojavaja").empty().removeClass("mOptions");
		if ($.browser.msie){$("select").css({visibility: "visible"});}
		$(".fMojavaja").animate({height: 0.5*rf, width: 10*rf, marginLeft: 4.4*rf, marginTop: 3*rf}, 250, function() {
			$("#mMenu03").removeClass("active");
			$(".fMojavaja").hide();
			fMojavajaStatus = 0;
		})
	}
	
	$("#mMenu03").mouseover(function(){
		fMojavajaHover=1;
			if (fMojavajaStatus==0) {
				$("#mMenu03").addClass("open");
				if (disableMeni == 0) {
					setTimeout(function(){
					if ((fMojavajaHover > 0 ) && (fMojavajaStatus == 0)) {
						fMojavajaStatus = 1;
						$("#mMenu03").addClass("active");
						$(".fMojavaja").css({height: 0.5*rf, width: 10*rf, marginLeft: 4.4*rf, marginTop: 3*rf});
						$(".fMojavaja").animate({height: 40*rf, width: 64*rf, marginLeft: -49.6*rf, marginTop: 4.8*rf}, 250, function() {    
							if ($.browser.msie){$("select").css({visibility: "hidden"});}
							$(".fMojavaja").addClass("mOptions").html($("#fMojavajaContent").html());
							fMojavajaStatus = 2;
							$(".mojavajaClose").click(function(){
								fMojavajaClose();
								return false;
							})
						})
					}
				},400);
			}	
		}
	});
	


	$("#mMenu03").mouseout(function(){
		fMojavajaHover=0;
			if (fMojavajaStatus==0) {
					$("#mMenu03").removeClass("open");
			}
			setTimeout(function(){
				if ((fMojavajaHover == 0 ) && (fMojavajaStatus ==2)) {
					fMojavajaClose();
				}
			},50);
	});
}); 


/*splošna funkcija ki izpiše goldinarje*/
function spljuniGoldinarje(price) {
	
	newprice = " ";
	newpriceG = 	(price) | 0;
	newpriceK = (price % 1);
	newpriceK = Math.round(newpriceK*100);

	if (newpriceG > 0) {
		newprice+= newpriceG + " <img height='13' width='13' class='alignMiddle' alt='goldinar' src='/slike/cgp-forum-24.gif'/> ";
	}
	if (newpriceK > 0) {
		newprice+= newpriceK + " <img height='13' width='13' class='alignMiddle' alt='goldinar' src='/slike/cgp-forum-23.gif'/>";
	}
	if ((newpriceK==0) && (newpriceG==0)) {
		newprice = "0 <img height='13' width='13' class='alignMiddle' alt='goldinar' src='/slike/cgp-forum-24.gif'/>";
	}
	
	return newprice;
}

// openads koda!!!

var OA_p=location.protocol=='https:'?'https:':'http:';
var OA_r=Math.floor(Math.random()*99999999);
if (!document.OA_used) document.OA_used = ',';
function OA_adjs(z,n)
{
  if (z>-1) {
    var az="<"+"script language='JavaScript' type='text/javascript' ";
    az+="src='"+OA_p+"//ad.romb.si/www/delivery/ajs.php?n="+n+"&zoneid="+z;
    az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
    az+="&mmm_fo="+(document.mmm_fo)?'1':'0';
    if (document.context) az+= "&context=" + escape(document.context);
    if (window.location) az+="&loc="+escape(window.location);
    if (document.referrer) az+="&referer="+escape(document.referrer);
    az+="'><"+"/script>";
    document.write(az);
  }
}
function OA_adpop(z,n)
{
  if (z>-1) {
    var az="<"+"script language='JavaScript' type='text/javascript' ";
    az+="src='"+OA_p+"//ad.romb.si/www/delivery/apu.php?n="+n+"&zoneid="+z;
    az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
    if (window.location) az+="&loc="+escape(window.location);
    if (document.referrer) az+="&referer="+escape(document.referrer);
    az+="'><"+"/script>";
    document.write(az);
  }
}
// konec openads kode

$(document).ready(function() {
	$("#hpx").click( function() { window.location="http://www.vijavaja.com/slike/hpz.gif" } );
});


