// JavaScript Document

fb_sharer='http://www.facebook.com/sharer.php?u=';

function initSlikaTjedna() {
	if (slikaTjednaVoteing == "on") {  ;
	
		$("#votelink5").bind("mouseenter",function(e){$("#vote_big_img").attr({src: gVoteImg[5]});gVoteId = 5;rBrdrVt("#votelink5");});
		$("#votelink1").bind("mouseenter",function(e){$("#vote_big_img").attr({src: gVoteImg[1]});gVoteId = 1;rBrdrVt("#votelink1");});
		$("#votelink2").bind("mouseenter",function(e){$("#vote_big_img").attr({src: gVoteImg[2]});gVoteId = 2;rBrdrVt("#votelink2");});
		$("#votelink3").bind("mouseenter",function(e){$("#vote_big_img").attr({src: gVoteImg[3]});gVoteId = 3;rBrdrVt("#votelink3");});
		$("#votelink4").bind("mouseenter",function(e){$("#vote_big_img").attr({src: gVoteImg[4]});gVoteId = 4;rBrdrVt("#votelink4");});
		
	}else {
		rBrdrVt("#votelink"+mosthits);
	}
}
function rBrdrVt(newer){
	
	if ($("#votelink5").hasClass("vote_link_hover")) $("#votelink5").removeClass("vote_link_hover");
	if ($("#votelink1").hasClass("vote_link_hover")) $("#votelink1").removeClass("vote_link_hover");
	if ($("#votelink2").hasClass("vote_link_hover")) $("#votelink2").removeClass("vote_link_hover");
	if ($("#votelink3").hasClass("vote_link_hover")) $("#votelink3").removeClass("vote_link_hover");
	if ($("#votelink4").hasClass("vote_link_hover")) $("#votelink4").removeClass("vote_link_hover");
	
	$(newer).addClass("vote_link_hover");
}



function emptyIfDefault(obj, val){
	var v = $("#"+obj).val();
	if(v==val) $("#"+obj).val("");
}

function fotogalerijaForma(id){
	var fime = $("#fgf_ime").val();
	var fupit = $("#fgf_com").val();
	
	fime = toMyEni(fime);
	fupit = toMyEni(fupit);
	
	if (fime != "" && fupit != "" && fime != "ime" && fupit != "komentiraj..."){
		$("#fgf_exit").html('<span style="color:#666;">Komentar se šalje...</span>');
		
	$.ajax({
					type: "POST",
					url: "http://www.nightlife.hr/zds/commentsubmit.php" ,
					data:{par_ime:fime, par_upit:fupit, par_img:id},
					error: function(){
							  $("#fgf_exit").html('<span style="color:#E22;">Greška kod slanja.</span>');
						   },
	  				success: function(data){
							//alert(data);
							if (data == "fail"){$("#fgf_exit").html('<span style="color:#E22;">Greška kod slanja.</span>');}
							else if (data == "win"){$("#fgf_exit").html('<span style="color:#2E2;">Komentar uspješno poslan.</span>');}
							else $("#fgf_exit").html('');
							$("#fgf_com").val('');
						}
			});
		
	}
	else{
		$("#fgf_exit").html('<span style="color:#E22;">Sva polja obavezno ispuniti.</span>');
	}
}

function toMyEni(str){
	var k = str.length;
	var ext = "";
	
	for (var l=0; l<k; l++){
			 if (str.charCodeAt(l) == 262) {ext += "|C|";}
		else if (str.charCodeAt(l) == 263) {ext += "|c|";}
		else if (str.charCodeAt(l) == 268) {ext += "|C.|";}
		else if (str.charCodeAt(l) == 269) {ext += "|c.|";}
		else if (str.charCodeAt(l) == 272) {ext += "|D|";}
		else if (str.charCodeAt(l) == 273) {ext += "|d|";}
		else if (str.charCodeAt(l) == 352) {ext += "|S|";}
		else if (str.charCodeAt(l) == 353) {ext += "|s|";}
		else if (str.charCodeAt(l) == 381) {ext += "|Z|";}
		else if (str.charCodeAt(l) == 382) {ext += "|z|";}
		else {ext += str.charAt(l);}
	}

	return ext;
}




function fg_scrollNajavaWin(str) {
	$("#nm-scroll-window").scrollTo(str, 600,{axis:'x'});
}

function fg_scrollGalerijaWin(str) {
	$("#g-scroll-window").scrollTo(str, 600,{axis:'x'});
}



function g_setNextImage() {
	next=g_active+1;
	if(next>=g_total)next=0;
	g_setActiveImage(next);
	return false;
}

function g_setPrevImage() {
	next=g_active-1;
	if(next<0)next=g_total-1;
	g_setActiveImage(next);
	return false;
}

function g_setActiveImage(id,firstTime) {
	firstTime = typeof(firstTime) != 'undefined' ? firstTime : false;
	
	if(!firstTime) {
		var oldcmtbox=document.getElementById("cmtbox"+g_imgid[g_active]);
		if(oldcmtbox!=null) oldcmtbox.style.display="none";
	}
	if(firstTime||id!=g_active) {
		var cmtbox=document.getElementById("cmtbox"+g_imgid[id]);
		if(cmtbox!=null) cmtbox.style.display="";
		
		var imgbox=document.getElementById("gallery-image");
		if(imgbox!=null) imgbox.src=g_path+g_images[id];
		if(imgbox!=null) imgbox.className="show-20";
		
		var fb_btn=document.getElementById("g-image-facebook");
		if(fb_btn!=null) fb_btn.href=fb_sharer+g_path_origs+g_images[id];
		
		var imgloader=document.getElementById("imgloader");
		if(imgloader!=null) imgloader.style.display="";
		
		var zoom=document.getElementById("g-image-zoom");
		if(zoom!=null) zoom.href=g_path_origs+g_images[id];
		
		var imgcounter=document.getElementById("imgcounter");
		if(imgcounter!=null) imgcounter.innerHTML=(id+1)+"/"+g_total;
		
		fg_scrollGalerijaWin(document.getElementById("gthumb"+id));
		
		g_active=id;
		
	}
	
	return false;
}

function g_imageLoaded() {
	var imgbox=document.getElementById("gallery-image");
	if(imgbox!=null) imgbox.className="";;
		
	var imgloader=document.getElementById("imgloader");
	
	if(imgloader!=null) imgloader.style.display="none";
}

function a_dsbl(obj) {
	obj.href="";
}
