function nav_showItemFields(id) {
	if(id.value == "1") {
		document.getElementById("nav_exturl").style.display = "none";

		document.getElementById("nav_page").style.display = "table-row";
		document.getElementById("nav_cleanurl").style.display = "table-row";
	}
	else if(id.value == "2") {
		document.getElementById("nav_exturl").style.display = "table-row";

		document.getElementById("nav_page").style.display = "none";
		document.getElementById("nav_cleanurl").style.display = "none";
	}
	
}

// Ads
var ads = new Array(); 

function ads_startRotator(container, ads_class, time) {
	var children = $("#"+ container + "").children().size();	
	
	ads.push(container);	
	ads[container] = 0;
	
	if(children != 1) {
		ads_changeAd(container, ads_class, time);
	} else {
		$("#"+ container + "").children().show();
	}
}

function ads_changeAd(container, ads_class, time) {
	var first = false;
	var children = $("#"+ container + "").children().size();	
	var previous = ads[container] != 1 ? ads[container] - 1 : children;		
	
	if(ads[container] == 0) {
		first = true;
		ads[container] = 1;
	}
	
	if(first) {
		$("#"+ container + " ."+ ads_class + ":nth-child(1)").show();
	} else {
		var c = ads[container];
		
		$("#"+ container + " ."+ ads_class + ":nth-child("+ previous +")").fadeOut(500, function() {
			$("#"+ container + " ."+ ads_class + ":nth-child("+ c +")").fadeIn(500);
		});	
	}
	
	if(ads[container] == children) {
		ads[container] = 1;
	} else {
		ads[container]++;
	}
	
	setTimeout("ads_changeAd('"+ container +"', '"+ ads_class +"', "+ time +")", time);
}

// Weather
function weather_style() {
	$("#weather-inside .weather-city:nth-child(1) div > p").appendTo("#weather-module");
	$("#weather-inside .weather-city div > p").remove();
	
	$("#weather-module > p").css("margin-top", "5px").css("text-align", "center").css("margin-left", "0px");
	$("#weather-module > p a").html("vir: Pro-Vreme");
}

function weather_styleImages(site) {
	$("#weather-inside .weather-city img").each(function(index, image) {
		// Replace
		$(image).attr("src", $(image).attr("src").toString().replace(/(.*?)ikone\/(.*).gif/, "/sites/"+ site +"/images/weather/$2.png"));
	});
}

function weather_change(id, name) {	
	$("#weather-city-title").html(name);
	
	$("#weather-inside .weather-city").hide();
	$("#weather-inside #weather-city-"+ id +"").show();
	weather_style();
}

// Comments
function comments_load_all(id) {
	$.ajax({url: "/index.php?action=loadComments&id="+ id + "", async: true, success: function(data) {
		$("#comments-navigation").remove();
		$("#comments-list").append(data);
	}});
}

// Mailing list
function ml_inputFocus(el) {
    if(el.value == "vaš e-poštni naslov") el.value = "";
}

function ml_inputBlur(el) {
    if(el.value == "") el.value = "vaš e-poštni naslov";
}

function ml_submitForm() {
    var email = $("#ml-mail").val();   
    
    if(email != "" && email != "vaš e-poštni naslov") {
        $("#ml-mail").val("prijavljam...");
        
        $.ajax({
            url: "/index.php?action=mailingListSubscribe&email="+ email,
            success: function(data) {
                $("#ml-mail").val(data);
            }
        });
    }
}

function ml_unsubscribeSubmit() {
    var data = $(".ml-unsubscribe-container input").serialize();
    
    window.location = "?" + data;
}

// Survey
function survey_checkFields() {
    var ok = false;
    
    $(".survey-answers input[type=\"radio\"]").each(function(index) {
        if(this.checked) ok = true;
    });
    
    if(!ok) {
        alert("Prosimo izberite odgovor.");
    }
    
    return ok;
}

// News archive
function news_archive_search() {
    var data = $(".news-search-container select").serialize();
    
    window.location = "?" + data;
}

// Prices
function prices_search() {
    var data = $(".prices-search-container select, .prices-search-container input").serialize();
    
    window.location = "?" + data;
}


