var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){
	var autoEraseText = null;
	var erased = false;
	var pfPage = 2;
	
	
	
	$(".showComment").click(function(){
		
		var cid="ul_"+$(this).attr("id");
		
		//alert(document.getElementById(cid).clientHeight);
		
		$("#"+$(this).attr("id")+"_show").slideUp();
		$("#"+$(this).attr("id")+"_hide").slideDown();
		
		$("#"+cid).css("height","");
		var height=document.getElementById(cid).clientHeight;
		
		$("#"+cid).css("height","38px");
		
		$("#"+cid).animate({height: height+'px'}, "slow");
		
	});
	
	$(".hideComment").click(function(){
		
		var cid="ul_"+$(this).attr("id");
		
		$("#"+$(this).attr("id")+"_hide").slideUp();
		$("#"+$(this).attr("id")+"_show").slideDown();
		
		
		//alert(cid);
		
		$("#"+cid).animate({height: '38px'}, "slow");
		
	});

	
	
	
	$("#kajjeinSubmit").click(function(){ 

		var msg="";
		
		if($("[name=category]").val()=="0") {
			msg += "Izberite kategorijo vnosa.<br />";
		}
		
		if($("[name=title]").attr("value").length<1) {
			msg += "Vnesite naslov vnosa.<br />";
		}
		
		if($("[name=summary]").attr("value").length<1) {
			msg += "Vnesite povzetek vnosa.<br />";
		}
		
		if(msg!=""){
			$("#dialog").html(msg)
			$('#dialog').dialog({ 
				bgiframe: true,
				resizable: false,
				width: 400,
				modal: true,
				title: "Manjkajo naslednji podatki:",
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5	
				},
	
				buttons: { 
					"Vredu": function(){ 
						$(this).dialog("destroy")
					}
				} 
			});
			return false;
		}

	});
	
	
	
	$("#borzaDodajSobo").click(function(){ 

		var msg="";
		
		if($("[name=lokacija]").val()=="0") {
			msg += "Izberite lokacijo nastanitve.<br />";
		}
		
		if($("[name=imepriimek]").attr("value").length<1) {
			msg += "Vnesite ime in priimek prodajalca.<br />";
		}
		
		if($("[name=telefon]").attr("value").length<1){
			msg +="Vnesite telefonsko številko prodajalca.<br />";		
		}
		
		if($("[name=email]").attr("value").length<1){
			msg +="Vnesite naslov elektronske pošte prodajalca.<br />";		
		}
		
		if(!$("[name=opis]:checked").attr("value")){
			msg +="Izberite opis nastanitve.<br />";		
		}
		
		if(!$("[name=tip]:checked").attr("value")){
			msg +="Izberite tip nastanitve.<br />";		
		}
	
		if($("[name=stSob]").attr("value").length<1){
			msg +="Vnesite število sob.<br />";		
		}
		
		if($("[name=povrsina]").attr("value").length<1){
			msg +="Vnesite površino nastanitve.<br />";		
		}
		
		if($("[name=stStud]").attr("value").length<1){
			msg +="Vnesite število iskanih najemnikov.<br />";		
		}
		
		if($("[name=spol]").val()=="0") {
			msg += "Izberite spol iskanih najemnikov.<br />";
		}
		
		if(!$("[name=Vhod]:checked").attr("value")){
			msg +="Izberite če ima nastanitev zasebni vhod.<br />";		
		}
		
		if(!$("[name=kuhinja]:checked").attr("value")){
			msg +="Izberite če ima nastanitev kuhinjo.<br />";		
		}
		
		if(!$("[name=sanitarije]:checked").attr("value")){
			msg +="Izberite če so sanitarije samostojne.<br />";		
		}
		
		if(!$("[name=centralna]:checked").attr("value")){
			msg +="Izberite če ima nastanitev centralno kurjavo.<br />";		
		}
		
		if(!$("[name=tel]:checked").attr("value")){
			msg +="Izberite če ima nastanitev telefon.<br />";		
		}
		
		if(!$("[name=catv]:checked").attr("value")){
			msg +="Izberite če ima nastanitev kabelsko televizijo.<br />";		
		}
		
		if(!$("[name=internet]:checked").attr("value")){
			msg +="Izberite če ima nastanitev internet.<br />";		
		}
		
		if($("[name=najemnina]").attr("value").length<1){
			msg +="Vnesite ceno najemnine.<br />";		
		}
		
		if($("[name=stroski]").attr("value").length<1){
			msg +="Vnesite ceno stroškov.<br />";		
		}
		
		
		if(msg!=""){
			$("#dialog").html(msg)
			$('#dialog').dialog({ 
				bgiframe: true,
				resizable: false,
				width: 400,
				modal: true,
				title: "Manjkajo naslednji podatki:",
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5	
				},
	
				buttons: { 
					"Vredu": function(){ 
						$(this).dialog("destroy")
					}
				} 
			});
			return false;
		}
		
		document.form1.submit();
		return true;

	});
	
	
	
	$("#borzaDodajKnjigo").click(function(){ 

		var msg="";
		
		if($("[name=imepriimek]").attr("value").length<1) {
			msg += "Vnesite ime in priimek prodajalca.<br />";
		}
		
		if($("[name=telefon]").attr("value").length<1){
			msg +="Vnesite telefonsko številko prodajalca.<br />";		
		}
		
		if($("[name=email]").attr("value").length<1){
			msg +="Vnesite naslov elektronske pošte prodajalca.<br />";		
		}
		
		if($("[name=naslov_ucb]").attr("value").length<1){
			msg +="Vnesite naslov gradiva.<br />";		
		}
		
		if($("[name=avtorji]").attr("value").length<1){
			msg +="Vnesite avtorje gradiva.<br />";		
		}
		
		if($("[name=predmet]").attr("value").length<1){
			msg +="Vnesite predmet, za keterega je gradivo namenjeno.<br />";		
		}
		
		if($("[name=cena]").attr("value").length<1){
			msg +="Vnesite ceno gradiva.<br />";		
		}
		
		
		if(msg!=""){
			$("#dialog").html(msg)
			$('#dialog').dialog({ 
				bgiframe: true,
				resizable: false,
				width: 400,
				modal: true,
				title: "Manjkajo naslednji podatki:",
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5	
				},
	
				buttons: { 
					"Vredu": function(){ 
						$(this).dialog("destroy")
					}
				} 
			});
			return false;
		}

		document.form1.submit();
		return true;
		
	});
	
	
	
	
	$("#submitAd").click(function(){ 
		
		var msg="x";
		
	
		if($("[name=adDescription]").attr("value").length<1) {
			msg = "Vnesite opis artikla.";
		}
		
		if($("[name=adTitle]").attr("value").length<1){
			msg ="Vnesite ime artikla.";		
		}
		
		if($("[name=adType]").attr("value")=="0"){
			msg ="Izberite vrsto oglasa.";		
		}
		
		
		if(msg!="x"){
			
			$("#dialog").html(msg)
			$('#dialog').dialog({ 
				bgiframe: true,
				resizable: false,
				height:140,
				modal: true,
				title: "Nepopolni podatki",
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5	
				},
	
				buttons: { 
					"Vredu": function(){ 
						$(this).dialog("destroy")
					}
				} 
			});
			return false;
		}
		document.dodajOglas.submit();
	});
	
	
	
	$("#btn_submitTopic").click(function(){ 
		
		var msg="x";
		
		if($("[name=forumId]").attr("value").length<1){
			msg ="Izbrati morate področje teme.";		
		}
		
		if(FCKeditorAPI.GetInstance('vsebina').GetHTML(true).length<1){
			msg = "Vnesite vsebino.";
		}
		
		if($("[name=tema]").attr("value").length<1) {
			msg = "Vnesite ime teme.";
		}
		
		if(msg!="x"){
			$("#dialog").html(msg)
			$('#dialog').dialog({ 
				bgiframe: true,
				resizable: false,
				height:140,
				modal: true,
				title: "Nepopolni podatki",
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5	
				},
	
				buttons: { 
					"Vredu": function(){ 
						$(this).dialog("destroy")
					}
				} 
			});
			return false;
		}
		
	});
	
	
	$(".nagradneIzbrisi").click(function(){
		var href=$(this).attr("href");
		$('#dialog').dialog({ 
			bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
			title: "Brisanje nagradne igre",
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},

			buttons: { 
				"Izbriši": function() { 
					document.location=href;
					$(this).dialog("destroy")
				}, 
				"Prekliči": function(){ 
					$(this).dialog("destroy")
				}
			} 
		});
		
		return false;
	}); 
	
	$(".izbrisiTemo").click(function(){
		var href=$(this).attr("href");
		
		$('#dialog').dialog({ 
			bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
			title: "Brisanje teme",
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},

			buttons: { 
				"Izbriši": function() { 
					document.location=href;
					$(this).dialog("destroy")
				}, 
				"Prekliči": function(){ 
					$(this).dialog("destroy")
				}
			} 
		});
		
		return false;
	}); 
	
	$(".izbrisiPost").click(function(){
		var href=$(this).attr("href");
		
		$('#dialogPost').dialog({ 
			bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
			title: "Brisanje odgovora",
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},

			buttons: { 
				"Izbriši": function() { 
					document.location=href;
					$(this).dialog("destroy")
				}, 
				"Prekliči": function(){ 
					$(this).dialog("destroy")
				}
			} 
		});
		
		return false;
	}); 
	
	$("#posljiPM").click(function(){
		
		$(this).before("<input type='text' style='display:none;' name='enterless' value='"+$('.autobox-input').find('input').slice(0,1).attr("value")+"'>")
		
	});

	
	$("#addPost").click(function(){ 
		
		var msg="x";
		
		if(FCKeditorAPI.GetInstance('vsebina').GetHTML(true).length<1){
			msg = "Vnesite vsebino odgovora.";
		}
		
		if(msg!="x"){
			$("#dialog").html(msg)
			$('#dialog').dialog({ 
				bgiframe: true,
				resizable: false,
				height:140,
				modal: true,
				title: "Nepopolni podatki",
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5	
				},
	
				buttons: { 
					"Vredu": function(){ 
						$(this).dialog("destroy")
					}
				} 
			});
			return false;
		}
		
	});
	
	
	$("#submitNewEvent").click(function(){ 
		
		
		var msg="x";
		
		
		if($("[name=categoryId]").attr("value")=="x") {
			msg = "Izberite vrsto dogodka";
		}
		
		if($("[name=eventName]").attr("value").length<1) {
			msg = "Izpolnite ime dogodka";
		}
		
		if($("[name=venue]").attr("value").length<1) {
			msg = "Izberite prizorišče dogodka";
		}
		
		if(FCKeditorAPI.GetInstance('description').GetHTML(true).length<1){
			msg = "Vnesite opis dogodka."		
		}
	
		
		if(msg!="x"){
			$("#dialog").html(msg)
			$('#dialog').dialog({ 
				bgiframe: true,
				resizable: false,
				height:140,
				modal: true,
				title: "Nepopolni podatki",
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
	
				buttons: { 
					"Vredu": function(){ 
						$(this).dialog("destroy")
					}
				} 
			});
			return false;
		}
		
		
	});
	
	
	$(".visibilityTogle").click(function(){
		var cId = $(this).attr("id");
		
		if($(this).hasClass("makeVisible")){
		
			$.ajax({
					type: "POST",
					url: "/api/koledar/narediVidno/",
		   			data: "eventId=" + cId,
		   			success: function(msg){
		   				
		   				var msgArray = msg.split('#'); 
		     			if(msgArray[0]=='ok'){
		     				var cId = msgArray[1];
		     				$("#"+cId).html("(Vidno)");
		     				$("#"+cId).attr("title","Naredi nevidno");
		     				$("#"+cId).removeClass("makeVisible")
		     				$("#"+cId).addClass("makeInvisible")
		     			}
		   			}
		 		});
		}
		
		if($(this).hasClass("makeInvisible")){
			$.ajax({
					type: "POST",
					url: "/api/koledar/narediNevidno/",
		   			data: "eventId=" + cId,
		   			success: function(msg){
		   				
		   				var msgArray = msg.split('#'); 
		     			if(msgArray[0]=='ok'){
		     				var cId = msgArray[1];
		     				$("#"+cId).html("(Nevidno)");
		     				$("#"+cId).attr("title","Naredi vidno");
		     				$("#"+cId).removeClass("makeInvisible")
		     				$("#"+cId).addClass("makeVisible")
		     			}
		   			}
		 		});
		}
	});

	
	
	$("#pridemNaDogodekBtn").click(function(){
		var eventId=$("#eventId").attr("value");	
		if($("#pridemNaDogodekBtn").attr("value")=="Pridem na dogodek"){
			$.ajax({
				type: "POST",
				url: "/api/koledar/pridem/",
	   			data: "eventId=" + eventId,
	   			success: function(msg){
	   				
	     			if(msg=='ok'){
	     				$("#pridemNaDogodekBtn").fadeOut(function(){
	     					$("#pridemNaDogodekBtn").attr("value","Ne pridem na dogodek");
	     					$("#pridemNaDogodekBtn").fadeIn();
	     				});
	     				
	     				$("#pridemHidden").animate({ width: 'show',height: 'show', opacity: 'show' }, "slow");
	     			}
	   			}
	 		});
		} else {
			$.ajax({
				type: "POST",
				url: "/api/koledar/nePridem/",
	   			data: "eventId=" + eventId,
	   			success: function(msg){
	   				
	     			if(msg=='ok'){
	     				$("#pridemNaDogodekBtn").fadeOut(function(){
	     					$("#pridemNaDogodekBtn").attr("value","Pridem na dogodek");
	     					$("#pridemNaDogodekBtn").fadeIn();
	     				});
	     				
	     				$("#pridemHidden").animate({ width: 'hide',height: 'hide', opacity: 'hide' }, "slow");
	     				$("#self").animate({ width: 'hide',height: 'hide', opacity: 'hide' }, "slow");
	     			}
	   			}
	 		});
		}
	});

/* krizo */
	$(".autoErase").focus(function(){
		autoEraseText = $(this).val();
		if(!erased)
		{
			$(this).val("");
			erased = true;
		}
	});
	
	$(".autoErase").blur(function(){
		if($(this).val() == "")
		{
			$(this).val(autoEraseText);
			erased = false;
		}
	});
	
	$("#btn_updateStatus").click(function(){
		var userId = $("#userId").val();
		var username = $("#pUsername").val();
		var status = $("#uStatus").val();
		if(status == "Kaj počneš?") return false;
		$(this).after("<center id='pStatusUpdateLoading'><img src='/images/ajax_loader.gif' alt='nalagam...' /></center>");
		$.ajax({
			dataType: "json",
			type: "POST",
			url: "/api/Uporabnik/osveziStatus/",
   			data: "userId=" + userId + "&status=" + status,
   			success: function(msg){
     			$("#profileStatus").html(msg.status + " <span>" + msg.time + "</span>");
     			$("#profileStatus").hide().slideDown("slow");
     			$("#userFeed").prepend("<li class='user' id='feed" + msg.acitivityId + "'><a href='/uporabnik/" + userId + "/'>" + username + "</a>: " + msg.status + "</li>");
     			$("#userFeed li:first").hide().slideDown("slow");
     			$("#pStatusUpdateLoading").remove();
     			$("#uStatus").val("Kaj počneš?");
     			erased = false;
   			}
 		});
 		
 		return false;
	});
	
	$("#btn_pUpdateStatus").click(function(){
		var userId = $("#pUserId").val();
		var username = $("#pUsername").val();
		var status = $("#pUStatus").val();
		if(status == "Kaj počneš?" || status == "?") return false;
		$(this).after("<center id='pStatusUpdateLoading'><img src='/images/ajax_loader.gif' alt='nalagam...' /></center>");
		$.ajax({
			dataType: "json",
			type: "POST",
			url: "/api/Uporabnik/osveziStatus/",
   			data: "userId=" + userId + "&status=" + status,
   			success: function(msg){
     			$("#publicFeed").prepend("<li class='user' id='feed" + msg.acitivityId + "'><a href='/uporabnik/" + userId + "/'>" + username + "</a>: " + msg.status + " <span class='grey0_8em'>" + msg.time + "</span></li>");
     			$("#publicFeed li:first").hide().slideDown("slow");
     			$("#pStatusUpdateLoading").remove();
     			$("#pUStatus").val("Kaj počneš?");
     			erased = false;
   			}
 		});
 		
 		return false;
	});
	
	$("#a_moreActivities").click(function(){
		$.ajax({
			dataType: "json",
			type: "GET",
			url: "/api/Aktivnosti/aktivnosti/",
   			data: "page=" + pfPage,
   			success: function(json){
   				$.each(json.activities, function(i, item){
     				$("#publicFeed").append("<li class='" + item.icon + "' id='feed" + item.activityId + "'>" + item.text + " <span class='grey0_8em'>" + item.time + "</span></li>");
   				});
   				pfPage++;
   			}
 		});
 		
 		return false;
	});
	
	$(".a_userFeedMore").click(function(){
		var userId = $(this).attr("id").replace(/user/,"");
		var lastActivityId = $("#userFeed li:last").attr("id").replace(/uFeed/, "");
		$.ajax({
			dataType: "json",
			type: "GET",
			url: "/api/Aktivnosti/uporabniskeAktivnosti/",
   			data: "lastActivity=" + lastActivityId + "&userId=" + userId,
   			success: function(json){
   				$.each(json.activities, function(i, item){
     				$("#userFeed").append("<li class='" + item.icon + "' id='uFeed" + item.activityId + "'><span>" + item.text + "</span></li>");
   				});
   				pfPage++;
   			}
 		});
 		
 		return false;
	});
	
	$(".img_setDefaultImage").click(function(){
		var newsId = $("input[name=newsId]").val();
		var imageId = $(this).attr("id").replace(/image/, "");
		$.ajax({
			type: "POST",
			url: "/api/Novice/privzetaSlika/",
   			data: "cId=" + newsId + "&imageId=" + imageId,
   			success: function(msg){
   				
   			}
 		});
 		
 		$(".img_setDefaultImage").css("border", "0px");
 		$(this).css("border", "1px solid red");
 		
 		return false;
	});
	
	$(".kajjein_setDefaultImage").click(function(){
		
		var newsId = $("input[name=newsId]").val();
		var imageId = $(this).attr("id").replace(/image/, "");
		
		$.ajax({
			type: "POST",
			url: "/api/Kajjein/privzetaSlika/",
   			data: "cId=" + newsId + "&imageId=" + imageId,
   			success: function(msg){
   				
   			}
 		});
 		
 		$(".kajjein_setDefaultImage").css("border", "0px");
 		$(this).css("border", "1px solid red");
 		
 		return false;
	});
	
	$(".img_setProfileImage").click(function(){
		var imageId = $(this).attr("id").replace(/image/, "");
		$.ajax({
			type: "POST",
			url: "/api/Uporabnik/slikaProfila/",
   			data: "&imageId=" + imageId,
   			success: function(msg){
   				
   			}
 		});
 		
 		$(".img_setProfileImage").css("border", "0px");
 		$(this).css("border", "2px solid red");
 		
 		return false;
	});
	
	$(".a_requestFriendship").click(function(){
		var userId = $(this).attr("id").replace(/frequser/, "");
		$.ajax({
			type: "GET",
			url: "/api/uporabnik/dodajPrijatelja/",
   			data: "userId=" + userId,
   			success: function(msg){
   				$('#dialog_fReqSent').dialog("open");
   			}
 		});
 		$(this).fadeOut("slow");
 		return false;
	});
	
	$(".a_acceptFriendship").click(function(){
		var friendshipId = $(this).attr("id").replace(/friendship/, "");
		$.ajax({
			type: "GET",
			url: "/api/uporabnik/potrdiPrijatelja/",
   			data: "friendshipId=" + friendshipId,
   			success: function(msg){
   				$("#fReq" + friendshipId).html("Zahteva je bila potrjena.").hide().fadeIn();
   			}
 		});
 		
 		return false;
	});
	
	$(".a_ignoreFriendship").click(function(){
		var friendshipId = $(this).attr("id").replace(/friendship/, "");
		$.ajax({
			type: "GET",
			url: "/api/uporabnik/ignorirajPrijatelja/",
   			data: "friendshipId=" + friendshipId,
   			success: function(msg){
   				$("#fReq" + friendshipId).html("Zahteva je bila zavrnjena.").hide().fadeIn();
   			}
 		});
 		
 		return false;
	});
	
	$('#dialog_fReq').dialog({ 
		bgiframe: true,
		autoOpen: false,
		resizable: false,
		height:300,
		width: 400,
		modal: true,
		title: 'Zahteve za prijateljstvo',
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		}
	});
	
	$('#dialog_fReqSent').dialog({ 
		bgiframe: true,
		autoOpen: false,
		resizable: false,
		height:50,
		width: 300,
		modal: true,
		title: 'Zahteva za prijateljstvo',
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		}
	});
	
	$('#a_notFReq').click(function(){
		$('#dialog_fReq').dialog("open");
		return false;
	});
	
	$(".a_toggleResults").click(function(){
		var box = $(this).attr("id");
		$("#search_" + box).toggle("slide");
		$("#num_" + box).toggle("fade");
		
		if($(this).children("img").attr("src") == "/images/minus.png")
		{
			$(this).children("img").attr("src", "/images/plus.png");
			$(this).children("span").html("Prikaži rezultate");
		}
		else
		{
			$(this).children("img").attr("src", "/images/minus.png");
			$(this).children("span").html("Skrij rezultate");
		}
	});
	
	//$("#liveFeed").click(function(){
		setInterval("updateFeed2()", 10000);
	//});
	
	$("#a_lastAlbums").click(function(){
		$("#ul_lastAlbums").slideDown("slow");
		$("#ul_albumsByViews").slideUp("slow");
		return false;
	});
	
	$("#a_albumsByViews").click(function(){
		$("#ul_lastAlbums").slideUp("slow");
		$("#ul_albumsByViews").slideDown("slow");
		return false;
	});
	
	$(".a_showMainNews").click(function(){
		var newsId = $(this).attr("id").replace(/a_mainNews/, "");
		$(".a_showMainNews").removeClass("li_mainNewsSelected");
		$(this).addClass("li_mainNewsSelected");
		$(".div_mainNews").hide();
		$("#mainNews" + newsId).fadeIn("slow");
		
		return false;
	});
	
	headline_count = $(".div_mainNews").size();
	old_headline = 0;
	
	if(headline_count > 1)
	{
	   	$(".div_mainNews:eq(" + current_headline + ")").fadeIn();
	   	headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
	   	$('#scrollup').hover(function(){
	    	clearInterval(headline_interval);
	   	}, function(){
	    	headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
	    	headline_rotate();
	   	});
	   	
	   	$(".a_showMainNews").click(function(){
	   		var currentId = $(this).attr("id").replace(/a_mainNews/, "");
	   		$(".li_mainNewsSelected").removeClass("li_mainNewsSelected");
	   		$(this).addClass("li_mainNewsSelected");
	   		$(".div_mainNews").hide();
	   		$("#mainNews" + currentId).show();
	   		clearInterval(headline_interval);
	   		headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
	   		return false;
	   	});
	}
	
	$('#dialog_conferenceExp').dialog({ 
		bgiframe: true,
		autoOpen: false,
		resizable: false,
		height:100,
		width: 300,
		modal: true,
		title: 'Kaj je konferenčna debata?',
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		}
	});
	
	$("#a_openConferenceExp").click(function(){
		$("#dialog_conferenceExp").dialog("open");
		return false;
	});
	
	$('#dialog_sendDirectPm').dialog({ 
		bgiframe: true,
		autoOpen: false,
		resizable: false,
		height:270,
		width: 480,
		modal: true,
		title: 'Pošlji sporočilo',
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		}
	});
	
	$(".a_sendPM").click(function(){
		var recipientData = $(this).attr("id").split("_");
		var userId = recipientData[1];
		var username = recipientData[2];
		$("#strong_pmRecipient").html(username);
		$("#pmRecipient").val(userId);
		$("#dialog_sendDirectPm").dialog("open");
		return false;
	});

	$("#submit_sendDirectPm").click(function(){
		var userId = $("#pmRecipient").val();
		var subject = $("input[name=pmSubject]").val();
		var content = $("textarea[name=pmContent]").val();
		$.ajax({
			type: "POST",
			url: "/api/sporocila/poslji/",
   			data: "recipient=" + userId + "&pmSubject=" + subject + "&pmContent=" + content,
   			success: function(msg){
   				$("#dialog_sendDirectPm").html("Sporočilo je bilo poslano").hide().fadeIn();
   			}
 		});
 		return false;
	});
	
	$(".a_deleteAlbum").click(function(){
		var href = $(this).attr("href");
		$('#dialog_deleteAlbum').dialog({ 
			bgiframe: true,
			resizable: false,
			height:150,
			width: 300,
			modal: true,
			title: 'Izbriši album',
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: { 
				"Da, izbriši.": function() { 
					document.location = href;
					$(this).dialog("destroy")
				}, 
				"Ne, prekliči.": function(){ 
					$(this).dialog("destroy");
				}
			} 
		});
	
		return false;
	});
	
	$(".a_toggleVisibility").click(function(){
		var el = $(this).attr("id").replace(/toggle_/, "");
		$("#" + el).toggle("slow");
		return false;
	});
	
/* krizo end */

	$("#newPmButton").click(function(){
		$(".pm").slideDown("slow");
		$("#sendPmHeader").slideDown("fast");
		$("#newPmButton").slideUp();
	});
	
	$("#pmCloseNew").click(function(){
		$(".pm").slideUp("slow");
		$("#sendPmHeader").slideUp("slow");
		$("#newPmButton").slideDown();
	});
	
	$("#addEventForm").keypress(function(e) {
	    if (e.which == 13) {
	    	return false;
	    }
	});
	
	
	
	$("#body_left_glasuj").click(function(){
		var answerId = jQuery("input[name=ankOdg]:checked").val();
		var pollId = jQuery(".div_anketa").attr("id").replace(/anketa/, "");
		jQuery("#div_ankCont").html("<center><img src='/images/ajaxLoader.gif' /><br /><strong>Nalagam... Prosim počakaj.</strong></center>");
		jQuery.ajax({
			type: "GET",
			url: "/api/Poll/vote/" + pollId + "/" + answerId,
			success: function(msg){
				jQuery("#div_ankCont").html(msg).fadeIn("slow");
			}
		});
		
		return false;
	});
	
	$("#body_left_rezultati").click(function(){
		jQuery("#div_ankCont").html("<center><img src='/images/ajaxLoader.gif' /><br /><strong>Nalagam... Prosim počakaj.</strong></center>");
		var pollId = jQuery(".div_anketa").attr("id").replace(/anketa/, "");
		jQuery("#div_ankCont").load("/api/Poll/results/" + pollId);
		return false;
	});
	
	
	$("#prizoriscePrihodnji").click(function(){
		$("#prizoriscePrihodnjiBox").slideDown("slow");
		$("#prizoriscePretekliBox").slideUp("slow");
		return false;
	});
	
	
	$("#prizoriscePretekli").click(function(){
		$("#prizoriscePrihodnjiBox").slideUp("slow");
		$("#prizoriscePretekliBox").slideDown("slow");
		return false;
	});
	
	
	$("#forumShowLast").click(function(){
		$("#forumMostViewed").slideUp("fast");
		$("#forumMostReplied").slideUp("fast");
		$("#forumLastPosts").slideUp("fast");
		$("#forumLast").slideDown("fast"); 
		return false;
	});

	$("#forumShowMostViewed").click(function(){
		$("#forumMostViewed").slideDown("fast");
		$("#forumMostReplied").slideUp("fast");
		$("#forumLastPosts").slideUp("fast");
		$("#forumLast").slideUp("fast");
		return false;
	});

	$("#forumShowMostReplied").click(function(){
		$("#forumMostViewed").slideUp("fast");
		$("#forumMostReplied").slideDown("fast");
		$("#forumLastPosts").slideUp("fast");
		$("#forumLast").slideUp("fast"); 
		return false;
	});  
	
	$("#forumShowLastPosts").click(function(){
		$("#forumMostViewed").slideUp("fast");
		$("#forumMostReplied").slideUp("fast");
		$("#forumLast").slideUp("fast"); 
		$("#forumLastPosts").slideDown("fast");
		return false;
	});
	
	$(function() {
		$("#datepicker").datepicker({ dateFormat: 'dd-mm-yy' });
	});

	
	var options = {
		url: '/api/koledar/povabi/',
		success: function(msg) { 
			var msgArray = msg.split('#'); 
			var ok = msgArray[0];
			ok = ok.split("_"); 
			/*var notOk = msgArray[1];
			notOk = notOk.split("_");*/
			
			$(".bit-box").slideUp("slow")
			$("#ajaxLoaderGif").fadeOut(); 
			if($("#uspesnoDodaniWrapper").is('*')) {} else {
				$(".povabiPrijatelje").before("<div id='uspesnoDodaniWrapper' style='display:none;'><div class='uspesnoDodani'><h3>Uspešno ste povabili naslednje prijatelje:</h3></div></div>");
			}
			
			for (var i in ok){
				if(isNaN(ok[i])){
					if($("#inviteList").attr("value").indexOf(","+ok[i]+",")>0){} else {
						$(".uspesnoDodani").after("<span><a href='/uporabnik/"+ok[i]+"/'>"+ok[i]+"</a>, </span>"); 
						$(".bit-box").find("input").filter("[value="+ok[i]+"]").remove(); 
					}
					$("#inviteList").attr("value",$("#inviteList").attr("value")+ok[i]+",");
				} 
			}
			$("#uspesnoDodaniWrapper").slideDown("slow"); 
			
		}
	}; 
	
	$('#povabiNaDogodek').click(function() {
		
		
		$("#ajaxLoaderGif").fadeIn();
        $("#koledarPovabiForm").ajaxSubmit(options);
        return false; // <-- important!
    });
    
    

	
	$(".prizeDeleteElement").click(function(){
		$(this).parent().slideUp("slow",function(){
			$(this).remove();
		});
		return false;
	});
	
		
	$(".addQuestionAnswer").click(function(){
		if ( isNaN($("#newAnswerId").attr("value"))){
			$(this).before("<input type='hidden' id='newAnswerId' value='0'>")
			var newAnswerId = '0';
		} else {
			var newAnswerId = $("#newAnswerId").attr("value");
			newAnswerId++;
			$("#newAnswerId").remove();
			$(this).before("<input type='hidden' id='newAnswerId' value='"+newAnswerId+"'>");
		}	
		$(this).before("<div id='answerBox"+$(this).attr("id")+"' class='prizeEditAnswerBox' style='display:none;'><div class='prizeDeleteElement'>[X]</div>&nbsp; Odgovor: <input type='text' name='newAnswer_"+$(this).attr("id")+"_"+newAnswerId+"'> pravilen odgovor: <input type='checkbox' name='newAnswerTrue_"+$(this).attr("id")+"_"+newAnswerId+"'></div>");
		$(".prizeEditAnswerBox").slideDown("slow"); 
		
		$(".prizeDeleteElement").unbind("click");
		$(".prizeDeleteElement").bind("click", function(){
			$(this).parent().slideUp("slow",function(){
				$(this).remove();
			});
			return false;
		});
		return false;
	}); 
	 
	$(".addPrizeQuestion").click(function(){
		if ( isNaN($("#newQuestionId").attr("value"))){
			$(this).before("<input type='hidden' id='newQuestionId' value='0'>")
			var newQuestionId = '0';
		} else {
			var newQuestionId = $("#newQuestionId").attr("value");
			newQuestionId++;
			$("#newQuestionId").remove();
			$(this).before("<input type='hidden' id='newQuestionId' value='"+newQuestionId+"'>");
		}	
	
		$(this).before("<div id='questionBox_"+$("#newQuestionId").attr("value")+"' class='prizeEditQuestionBox' style='display:none;'><div class='prizeDeleteElement'>[X]</div>&nbsp;Vprašanje: <input type='text' name='newQuestion_"+$("#newQuestionId").attr("value")+"'><br /><a class='addQuestionAnswer'  id=new_"+$("#newQuestionId").attr("value")+">[dodaj odgovor]</a></div>");
		
		$(".addQuestionAnswer").unbind("click");
		$(".addQuestionAnswer").bind("click", function(){
			if ( isNaN($("#newAnswerId").attr("value"))){
				$(this).before("<input type='hidden' id='newAnswerId' value='0'>")
				var newAnswerId = '0';
			} else {
				var newAnswerId = $("#newAnswerId").attr("value");
				newAnswerId++;
				$("#newAnswerId").remove();
				$(this).before("<input type='hidden' id='newAnswerId' value='"+newAnswerId+"'>");
			}	
			$(this).before("<div id='answerBox"+$(this).attr("id")+"' class='prizeEditAnswerBox' style='display:none;'><div class='prizeDeleteElement'>[X]</div>Odgovor: <input type='text' name='newAnswer_"+$(this).attr("id")+"_"+newAnswerId+"'> pravilen odgovor: <input type='checkbox' name='newAnswerTrue_"+$(this).attr("id")+"_"+newAnswerId+"'></div>");
			$(".prizeEditAnswerBox").slideDown("slow");
			
			$(".prizeDeleteElement").unbind("click");
			$(".prizeDeleteElement").bind("click", function(){
				$(this).parent().slideUp("slow",function(){
					$(this).remove();
				});
				return false;
			});
			return false;
		});
		
		$(".prizeDeleteElement").unbind("click");
			$(".prizeDeleteElement").bind("click", function(){
				$(this).parent().slideUp("slow",function(){
					$(this).remove();
				});
				return false;
			});
		
		$(".prizeEditQuestionBox").slideDown("slow");
		return false;
	}); 
	
	
	$("#koledarPoPodobnihLink").click(function(){
		$("#koledarPoPodobnih").slideDown("slow");
		$("#koledarIstoPrizorisce").slideUp("slow");
		$("#koledarPoPopularnosti").slideUp("slow");
		return false;
	}); 
		
	$("#koledarIstoPrizorisceLink").click(function(){
		$("#koledarIstoPrizorisce").slideDown("slow");
		$("#koledarPoPodobnih").slideUp("slow");
		$("#koledarPoPopularnosti").slideUp("slow");
		return false;
	}); 
	
	$("#koledarPoPopularnostiLink").click(function(){
		$("#koledarPoPopularnosti").slideDown("slow");
		$("#koledarPoPodobnih").slideUp("slow");
		$("#koledarIstoPrizorisce").slideUp("slow");
		return false;		
	}); 
	

	$(".oglasIzbris").click(function(){
		var href=$(this).attr("href");
		$('#dialog').dialog({ 
			bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},

			buttons: { 
				"Izbriši": function() { 
					document.location=href;
					$(this).dialog("destroy")
				}, 
				"Prekliči": function(){ 
					$(this).dialog("destroy")
				}
			} 
		});
		
		return false;
	}); 
	
	$(".koledarIzbris").click(function(){
		
		var href=$(this).attr("href");
		$('#dialog').dialog({ 
			bgiframe: true,
			resizable: false,
			height:140,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: { 
				"Izbriši": function() { 
					document.location=href;
					$(this).dialog("destroy")
				}, 
				"Prekliči": function(){ 
					$(this).dialog("destroy")
				}
			} 
		});
		
	}); 

	$("#innerDailyTabPon").click(function(){
		$(".innerDailyTab").removeClass("dailyTabSelected");
		$("#innerDailyTabPon").addClass("dailyTabSelected");
		$("#innerDailyPon").slideDown("fast");		$("#innerDailyTor").slideUp("fast");		$("#innerDailySre").slideUp("fast");		
		$("#innerDailyCet").slideUp("fast");		$("#innerDailyPet").slideUp("fast");		$("#innerDailySob").slideUp("fast");
		$("#innerDailyNed").slideUp("fast");
	});
	
	$("#innerDailyTabTor").click(function(){
		$(".innerDailyTab").removeClass("dailyTabSelected");
		$("#innerDailyTabTor").addClass("dailyTabSelected");
		$("#innerDailyPon").slideUp("fast");		$("#innerDailyTor").slideDown("fast");		$("#innerDailySre").slideUp("fast");		
		$("#innerDailyCet").slideUp("fast");		$("#innerDailyPet").slideUp("fast");		$("#innerDailySob").slideUp("fast");
		$("#innerDailyNed").slideUp("fast");
	});
	
	$("#innerDailyTabSre").click(function(){
		$(".innerDailyTab").removeClass("dailyTabSelected");
		$("#innerDailyTabSre").addClass("dailyTabSelected");
		$("#innerDailyPon").slideUp("fast");		$("#innerDailyTor").slideUp("fast");		$("#innerDailySre").slideDown("fast");		
		$("#innerDailyCet").slideUp("fast");		$("#innerDailyPet").slideUp("fast");		$("#innerDailySob").slideUp("fast");
		$("#innerDailyNed").slideUp("fast");
	});
	
	$("#innerDailyTabCet").click(function(){
		$(".innerDailyTab").removeClass("dailyTabSelected");
		$("#innerDailyTabCet").addClass("dailyTabSelected");
		$("#innerDailyPon").slideUp("fast");		$("#innerDailyTor").slideUp("fast");		$("#innerDailySre").slideUp("fast");		
		$("#innerDailyCet").slideDown("fast");		$("#innerDailyPet").slideUp("fast");		$("#innerDailySob").slideUp("fast");
		$("#innerDailyNed").slideUp("fast");
	});
	
	$("#innerDailyTabPet").click(function(){
		$(".innerDailyTab").removeClass("dailyTabSelected");
		$("#innerDailyTabPet").addClass("dailyTabSelected");
		$("#innerDailyPon").slideUp("fast");		$("#innerDailyTor").slideUp("fast");		$("#innerDailySre").slideUp("fast");		
		$("#innerDailyCet").slideUp("fast");		$("#innerDailyPet").slideDown("fast");		$("#innerDailySob").slideUp("fast");
		$("#innerDailyNed").slideUp("fast");
	});
	
	$("#innerDailyTabSob").click(function(){
		$(".innerDailyTab").removeClass("dailyTabSelected");
		$("#innerDailyTabSob").addClass("dailyTabSelected");
		$("#innerDailyPon").slideUp("fast");		$("#innerDailyTor").slideUp("fast");		$("#innerDailySre").slideUp("fast");		
		$("#innerDailyCet").slideUp("fast");		$("#innerDailyPet").slideUp("fast");		$("#innerDailySob").slideDown("fast");
		$("#innerDailyNed").slideUp("fast");
	});
	
	$("#innerDailyTabNed").click(function(){
		$(".innerDailyTab").removeClass("dailyTabSelected");
		$("#innerDailyTabNed").addClass("dailyTabSelected");
		$("#innerDailyPon").slideUp("fast");		$("#innerDailyTor").slideUp("fast");		$("#innerDailySre").slideUp("fast");		
		$("#innerDailyCet").slideUp("fast");		$("#innerDailyPet").slideUp("fast");		$("#innerDailySob").slideUp("fast");
		$("#innerDailyNed").slideDown("fast");
	});
	
	
	
	
	
	

	
	$("#dailyDay0").click(function(){ 
		$(".mealFrontDays").removeClass("currentMealDay");
		$("#dailyDay0").addClass("currentMealDay");
		$("#dailyFront1").hide("fast");		$("#dailyFront2").hide("fast");		$("#dailyFront3").hide("fast");		
		$("#dailyFront4").hide("fast");		$("#dailyFront5").hide("fast");		$("#dailyFront6").hide("fast");
		$("#dailyFront0").show("fast");
	});
	$("#dailyDay1").click(function(){
		$(".mealFrontDays").removeClass("currentMealDay");
		$("#dailyDay1").addClass("currentMealDay");
		$("#dailyFront0").hide("fast");		$("#dailyFront2").hide("fast");		$("#dailyFront3").hide("fast");		
		$("#dailyFront4").hide("fast");		$("#dailyFront5").hide("fast");		$("#dailyFront6").hide("fast");
		$("#dailyFront1").show("fast");		
	});
	$("#dailyDay2").click(function(){
		$(".mealFrontDays").removeClass("currentMealDay");
		$("#dailyDay2").addClass("currentMealDay");
		$("#dailyFront0").hide("fast");		$("#dailyFront1").hide("fast");		$("#dailyFront3").hide("fast");
		$("#dailyFront4").hide("fast");		$("#dailyFront5").hide("fast");		$("#dailyFront6").hide("fast");
		$("#dailyFront2").show("fast");		
	});
	$("#dailyDay3").click(function(){
		$(".mealFrontDays").removeClass("currentMealDay");
		$("#dailyDay3").addClass("currentMealDay");
		$("#dailyFront0").hide("fast");		$("#dailyFront1").hide("fast");		$("#dailyFront2").hide("fast");
		$("#dailyFront4").hide("fast");		$("#dailyFront5").hide("fast");		$("#dailyFront6").hide("fast");
		$("#dailyFront3").show("fast");		
	});
	$("#dailyDay4").click(function(){
		$(".mealFrontDays").removeClass("currentMealDay");
		$("#dailyDay4").addClass("currentMealDay");
		$("#dailyFront0").hide("fast");		$("#dailyFront1").hide("fast");		$("#dailyFront2").hide("fast");
		$("#dailyFront3").hide("fast");		$("#dailyFront5").hide("fast");		$("#dailyFront6").hide("fast");
		$("#dailyFront4").show("fast");		
	});
	$("#dailyDay5").click(function(){
		$(".mealFrontDays").removeClass("currentMealDay");
		$("#dailyDay5").addClass("currentMealDay");
		$("#dailyFront0").hide("fast");		$("#dailyFront1").hide("fast");		$("#dailyFront2").hide("fast");
		$("#dailyFront3").hide("fast");		$("#dailyFront4").hide("fast");		$("#dailyFront6").hide("fast");
		$("#dailyFront5").show("fast");		
	});
	$("#dailyDay6").click(function(){
		$(".mealFrontDays").removeClass("currentMealDay");
		$("#dailyDay6").addClass("currentMealDay");
		$("#dailyFront0").hide("fast");		$("#dailyFront1").hide("fast");		$("#dailyFront2").hide("fast");
		$("#dailyFront3").hide("fast");		$("#dailyFront4").hide("fast");		$("#dailyFront5").hide("fast");
		$("#dailyFront6").show("fast");		
	});
	
	
	
	
	$("#calDay0").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDay0").addClass("current");
		$("#koledarDan0").show("fast");		$("#koledarDan1").hide("fast");		$("#koledarDan2").hide("fast");
		$("#koledarDan3").hide("fast");		$("#koledarDan4").hide("fast");		$("#koledarDan5").hide("fast");
		$("#koledarDan6").hide("fast");
	});
	
	$("#calDay1").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDay1").addClass("current");
		$("#koledarDan0").hide("fast");		$("#koledarDan1").show("fast");		$("#koledarDan2").hide("fast");
		$("#koledarDan3").hide("fast");		$("#koledarDan4").hide("fast");		$("#koledarDan5").hide("fast");
		$("#koledarDan6").hide("fast");
	});
	
	$("#calDay2").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDay2").addClass("current");
		$("#koledarDan0").hide("fast");		$("#koledarDan1").hide("fast");		$("#koledarDan2").show("fast");
		$("#koledarDan3").hide("fast");		$("#koledarDan4").hide("fast");		$("#koledarDan5").hide("fast");
		$("#koledarDan6").hide("fast");
	});
	
	$("#calDay3").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDay3").addClass("current");
		$("#koledarDan0").hide("fast");		$("#koledarDan1").hide("fast");		$("#koledarDan2").hide("fast");
		$("#koledarDan3").show("fast");		$("#koledarDan4").hide("fast");		$("#koledarDan5").hide("fast");
		$("#koledarDan6").hide("fast");
	});
	
	$("#calDay4").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDay4").addClass("current");
		$("#koledarDan0").hide("fast");		$("#koledarDan1").hide("fast");		$("#koledarDan2").hide("fast");
		$("#koledarDan3").hide("fast");		$("#koledarDan4").show("fast");		$("#koledarDan5").hide("fast");
		$("#koledarDan6").hide("fast");
	});
	
	$("#calDay5").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDay5").addClass("current");
		$("#koledarDan0").hide("fast");		$("#koledarDan1").hide("fast");		$("#koledarDan2").hide("fast");
		$("#koledarDan3").hide("fast");		$("#koledarDan4").hide("fast");		$("#koledarDan5").show("fast");
		$("#koledarDan6").hide("fast");
	});
	
	$("#calDay6").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDay6").addClass("current");
		$("#koledarDan0").hide("fast");		$("#koledarDan1").hide("fast");		$("#koledarDan2").hide("fast");
		$("#koledarDan3").hide("fast");		$("#koledarDan4").hide("fast");		$("#koledarDan5").hide("fast");
		$("#koledarDan6").show("fast");
	});
	
	$("#calDayAll").click(function(){
		$(".calFrontDays").removeClass("current");
		$("#calDayAll").addClass("current");
		$("#koledarDan0").show("fast");		$("#koledarDan1").show("fast");		$("#koledarDan2").show("fast");
		$("#koledarDan3").show("fast");		$("#koledarDan4").show("fast");		$("#koledarDan5").show("fast");
		$("#koledarDan6").show("fast");
	});
	
	$("#oglasi_napredno_link_napredno_span").click(function(){
		$("#oglasiAdvancedSearch").slideDown("slow");
		$(this).hide();
		$("#oglasi_napredno_link_preprosto_span").show();
		$("#oglasi_napredno_bool").attr("value","1"); 
	});
	
	$("#oglasi_napredno_link_preprosto_span").click(function(){
		$("#oglasiAdvancedSearch").slideUp("slow");
		$(this).hide();
		$("#oglasi_napredno_link_napredno_span").show();
		$("#oglasi_napredno_bool").attr("value","0");
	});
	
	
	$(".newsTitle").click(function(){
		$(this).css("color", "red");
	});
	
	
	$("#allDayEvent").click(function(){
		$("#time").toggle("slow");
		$("#timeTo").toggle("slow");
	});
	
	
	$("#MultipleDayEvent").click(function(){
		$("#dateTo").toggle("slow");
	});
	
	
	$("#suggestVenue").autocomplete("/api/koledar/suggestVenue/", {
		width: 260,
		selectFirst: false,
		max: 50
	});
	
	$("#suggestMunicipality").autocomplete("/api/koledar/suggestMunicipality/", {
		width: 260,
		selectFirst: false,
		max: 50
	}); 
	
	
	$("#suggestVenue").blur(function(){
		var venue = this.value;
		lastChar = venue.substring(venue.length-1);
		if(lastChar == ']'){ 
			$("#newVenueLocation").hide("slow"); 
			$("#new_venue").attr("value","0");
		}
	});
	
	$("#suggestVenue").change(function(){
		var venue = this.value;
		var lastChar = venue.substring(venue.length-1);
		if(lastChar != ']'){ 
			setTimeout('venueToggle()','100');
		}
	});
	
	$("#suggestVenue").focus(function(){
		var venue = document.getElementById('suggestVenue').value;
		var lastChar = venue.substring(venue.length-1);
		if(lastChar == ']'){ 
			$("#newVenueLocation").hide("slow"); 
			$("#new_venue").attr("value","0");
		}
	});
	
	$("#suggestLocation").autocomplete("/api/koledar/suggestLocation/", {
		width: 260,
		selectFirst: false,
		max: 50
	});
	
	
	$(".voteUp").click(function(){
		
		var id=$(this).attr("id");
		var idArray=id.split("_");
		var type=idArray[0];
		
		id=idArray[1];
		
		$.ajax({
			type: "GET", 
	  		url: "/api/glasovanje/glasujGor/"+type+"/"+id,
	  		dataType: "html",
	  		success: function(msg){
	  			//alert(msg);
	  			if(msg=="error"){
	  				//alert("error");
	  			} else {
	  				
	  				var msgArray=msg.split('_');
	  				
	  				var newRating=msgArray[2];
	  			
	  					$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 0.001, function(){
	  						if(msgArray[0]!='komentar' && msgArray[0]!='kajjein'){
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).html("Vaš glas je bil uspešno oddan."); 
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 1);
	  						} 
	  					});
	  					
	  					$("#ocena_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 0.001, function(){
	  						$("#ocena_"+msgArray[0]+'_'+msgArray[1]).html(newRating);
	  						$("#ocena_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow",1);
	  					});

	  				return false; 
	  			}
  			}
		});
		return false;
	});
	
	
	$(".voteDown").click(function(){
		var id=$(this).attr("id");
		var idArray=id.split("_");
		var type=idArray[0];
		id=idArray[1];
		
		$.ajax({
			type: "GET", 
	  		url: "/api/glasovanje/glasujDol/"+type+"/"+id, 
	  		dataType: "html",
	  		success: function(msg){
	  			
	  			if(msg=="error"){
	  				alert("error");
	  			} else {
	  				
	  				var msgArray=msg.split('_');
	  				
	  				var newRating=msgArray[2];
	  			
	  					$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 0.001, function(){
	  						if(msgArray[0]!='komentar' && msgArray[0]!='kajjein'){
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).html("Vaš glas je bil uspešno oddan."); 
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 1);
	  						} 
	  					});
	  					
	  					$("#ocena_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 0.001, function(){
	  						$("#ocena_"+msgArray[0]+'_'+msgArray[1]).html(newRating);
	  						$("#ocena_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow",1);
	  					});

	  					if(msgArray[0]=="komentar"){
		  					$("#c_"+msgArray[1]+"_show").slideDown();
		  					$("#ul_c_"+msgArray[1]).css("overflow","hidden"); 
		  					$("#ul_c_"+msgArray[1]).animate({height: '38px'}, "slow");
		  					
	  					}
	  				return false; 
	  			}
  			}
		});
		return false;
	});
	
	$(".commentOn").click(function(){
		
		var id=$(this).attr("id");
		var idArray=id.split("_");
		var type=idArray[0];
		
		id=idArray[1];
		
		$.ajax({
			type: "GET", 
	  		url: "/api/glasovanje/komentarOn/"+type+"/"+id,
	  		dataType: "html",
	  		success: function(msg){
	  			//alert(msg);
	  			if(msg=="error"){
	  				alert("error");
	  			} else {
	  				
	  				var msgArray=msg.split('_');
	  				
	  				var newVisibility=msgArray[2];
	  			
	  				$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 0.001, function(){
	  						//if(msgArray[0]!='komentar' && msgArray[0]!='kajjein'){
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).html("Odkrito."); 
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 1);
	  						//} 
	  					});

	  				return false; 
	  			}
  			}
		});
		return false;
	});
	
	$(".commentOff").click(function(){
		var id=$(this).attr("id");
		var idArray=id.split("_");
		var type=idArray[0];
		id=idArray[1];
		
		$.ajax({
			type: "GET", 
	  		url: "/api/glasovanje/komentarOff/"+type+"/"+id, 
	  		dataType: "html",
	  		success: function(msg){
	  			
	  			if(msg=="error"){
	  				alert("error");
	  			} else {
	  				
	  				var msgArray=msg.split('_');
	  				
	  				var newVisibility=msgArray[2];
	  			
	  					$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 0.001, function(){
	  						//if(msgArray[0]!='komentar' && msgArray[0]!='kajjein'){
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).html("Skrito."); 
	  							$("#voteBox_"+msgArray[0]+'_'+msgArray[1]).fadeTo("slow", 1);
	  						//} 
	  					});
						if(msgArray[0]=="komentar"){
		  					$("#c_"+msgArray[1]+"_show").slideDown();
		  					$("#ul_c_"+msgArray[1]).css("overflow","hidden"); 
		  					$("#ul_c_"+msgArray[1]).animate({height: '38px'}, "slow");
		  					
	  					}

	  				return false; 
	  			}
  			}
		});
		return false;
	});
});



function basename(path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function removeFromString(s, t) {
  /*
  **  Remove all occurrences of a token in a string
  **    s  string to be processed
  **    t  token to be removed
  **  returns new string
  */
  var i = s.indexOf(t);
  var r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + removeFromString(s.substring(i + t.length), t);
  return r;
  }




function venueToggle(){
	var venue = document.getElementById('suggestVenue').value;
	var lastChar = venue.substring(venue.length-1);
	if(lastChar != ']'){ 
		$("#newVenueLocation").show("slow"); 
		$("#new_venue").attr("value","1");
	}
}


function changePerPage(newValue){
	var home=document.location.toString();
	tmp=home.replace("ccp=1","");
	home=tmp;
	numIndex=home.indexOf("num=");
	if(numIndex==-1){
	
		if(home.indexOf('?')>0){
			document.location=home+"&num="+newValue+"&cpp=1";
		} else {
			document.location=home+"?num="+newValue+"&cpp=1";
		}
	} else {
		
		var finish=home.substr(numIndex);
		var eqIndex=finish.indexOf('=');
		var index=numIndex+eqIndex+1;
		finish=home.substring(index);
		var index2=finish.indexOf('&');
		if(index2>0){
			var value=finish.substr(0,index2);
		} else {
			var value=finish.substr(0);
		}
		
		var newUrl=home.replace("num="+value,"num="+newValue+"&cpp=1");
		
		document.location=newUrl;
	}
	
}


function addThumb(path){
	//alert(path); 
	
	var section="";
	
	if(path.substr(0,6)=="borza|"){
		var thumbArray = path.split("|");
		path = thumbArray[1];
		section="borza|";
	}
	
	
	
	var originalPath=removeFromString(path, "thumbs/");
	originalPath=removeFromString(originalPath,"c64x64_");
	
	var filenametmp=basename(path,"wtf");
	filename = filenametmp.slice(0,(filenametmp.length)-4); 
	
	var removeFilename=removeFromString(filename,"c64x64_");
	
	if($("#addingImages").attr("value")=='1') {
		$("#firstThumb").before("<div style='display:none;'id='wrapper"+removeFilename+"' class='uploaderThumb'><a  target='_blank' href='"+originalPath+"'><img class='swfThumb' src='"+path+"' /></a><div class='uploaderRemoveImg' id='"+filename+"' onClick='removeThumb(\""+section+removeFilename+"\")'>Odstrani</div></div>");
	} else {
		$("#firstThumb").before("<div style='display:none;'id='wrapper"+removeFilename+"' class='uploaderThumb'><a  target='_blank' href='"+originalPath+"'><img class='swfThumb' src='"+path+"' /></a><div class='uploaderRemoveImg' id='"+filename+"' onClick='removeTmpThumb(\""+removeFilename+"\")'>Odstrani</div></div>");
	}
	
	$("#wrapper"+removeFilename).animate({ width: "show",height: "show"}, "slow");
	
}



function removeTmpThumb(thumb){
	//alert("/api/swfUploader/odstraniTmpThumb/"+$("#adToken").attr("value")+"/"+thumb );
	$.ajax({ 
		type: "GET", 
  		url: "/api/oglasi/odstraniTmpSliko/"+$("#adToken").attr("value")+"/"+thumb, 
  		dataType: "html",
  		success: function(msg){ 
    		$("#wrapper"+thumb).animate({ width: 'hide',height: 'hide', opacity: 'hide' }, "slow");
    		//alert(msg);
  		}	 	
	});
}

function removeThumb(thumb){
	//alert("/api/oglasi/odstraniTmpThumb/"+$("#adToken").attr("value")+"/"+thumb );
	
	var targetUrl;
	
	if(thumb.substr(0,6)=="borza|"){
		var thumbArray = thumb.split("|");
		targetUrl = "/api/borza/odstraniSliko/"+thumbArray[1];
		
	} else {
		targetUrl = "/api/oglasi/odstraniSliko/"+$("#adToken").attr("value")+"/"+thumb;
	}
	
	$.ajax({ 
		type: "GET", 
  		url: targetUrl, 
  		dataType: "html",
  		success: function(msg){ 
  			//alert(msg);
    		$("#wrapper"+msg).animate({ width: 'hide',height: 'hide', opacity: 'hide' }, "slow");
    		//alert(thumb);
  		}	 	
	});
}







function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function updateFeed()
{
	var lastActivityId = $("#publicFeed > li:first").attr("id").replace(/feed/, "");
	$.ajax({
		dataType: "json",
		type: "GET",
		url: "/api/Aktivnosti/zivo/",
   		data: "lastItem=" + lastActivityId,
   		success: function(json){
   			$.each(json.activities, function(i, item){
     			$("#publicFeed").prepend("<li class='user' id='feed" + item.activityId + "'>" + item.text + " <span class='grey0_8em'>" + item.time + "</span></li>");
     			$("#publicFeed li:first").hide().slideDown("slow");
   			});
   		}
 	});
 	
	setTimeout('updateFeed()', 10000);
}

function sortNumber(a, b)
{
	return a["activityId"] - b["activityId"];
}

function updateFeed2()
{
	oLastActivityId = $("#publicFeed > li:first").attr("id").replace(/feed/, "");
	var activities = new Array();
	$.ajax({
		dataType: "xml",
		type: "GET",
		url: "/rss/publicFeed.xml",
   		success: function(xml){
   			var numItems = 0;
   			$("item", xml).each(function(i){
   				var activityId = $(this).find("activityId").text();
   				
   				if(parseInt(activityId) <= parseInt(oLastActivityId))
   				{
	   				return false;
   				}
   				
   				var activityText = $(this).find("text").text();
   				var activityTime = $(this).find("time").text();
   				var activityIcon = $(this).find("icon").text();
   				
   				activities[numItems] = new Array();
   				
   				activities[numItems]["activityId"] = activityId;
   				activities[numItems]["activityText"] = activityText;
   				activities[numItems]["activityTime"] = activityTime;
   				activities[numItems]["activityIcon"] = activityIcon;
   				numItems++;
   			});
   			
   			if(numItems > 0)
   			{ 
   				activities.sort(sortNumber);
   				oLastActivityId = activities[numItems - 1]["activityId"];
   				
   				for(var i = 0;i < numItems;i++)
   				{
   					$("#publicFeed").prepend("<li class='" + activities[i]["activityIcon"] + "' id='feed" + activities[i]["activityId"] + "'>" + activities[i]["activityText"] + "</li>");
     				$("#feed" + activities[i]["activityId"]).hide().slideDown("slow");
     				//$("#publicFeed > li:last").fadeOut("slow");
   				}
   			}
   		}
 	});
}

function headline_rotate()
{
	var lastId;
	var currentId;
	current_headline = (old_headline + 1) % headline_count; 
   	$(".div_mainNews").hide();
   	//lastId = $(".div_mainNews:eq(" + old_headline + ")").attr("id").replace(/mainNews/, "");
   	$(".li_mainNewsSelected").removeClass("li_mainNewsSelected");
   	$(".div_mainNews:eq(" + current_headline + ")").fadeIn("slow");
   	currentId = $(".div_mainNews:eq(" + current_headline + ")").attr("id").replace(/mainNews/, "");
   	$("#a_mainNews" + currentId).addClass("li_mainNewsSelected");
   	old_headline = current_headline;
}
