$(function() {
	$("ul.sf-menu").supersubs({ 
            minWidth:    10, 
            maxWidth:    27,
            extraWidth:  1
        }).superfish({ 
		delay:       500,
		animation:   {height:'show'},
		speed:       'fast',
		autoArrows:  false,
		dropShadows: true
	});
	// Slider
	$("#slider").easySlider({
		auto: true,
		continuous: true,
		pause: 4000,
		numeric: true
	});
	// font resize
	var originalFontSize = $('.post_body').css('font-size');
	$(".resetFont").click(function(){
		$('.post_body').css('font-size', originalFontSize);
		return false;
	});
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('.post_body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum<16){
			var newFontSize = currentFontSizeNum*1.2;
		}
		$('.post_body').css('font-size', newFontSize);
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		var currentFontSize = $('.post_body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum>10){
			var newFontSize = currentFontSizeNum*0.8;
		}		
		$('.post_body').css('font-size', newFontSize);
		return false;
	});
	
	//register popup
	$(".kozmoLogin").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false
	});
	// nagradna popup
	$("a.nagradne-igre-zoom").fancybox({
		'titleShow'     : false
	});
	//reci-frendu popup
	$(".reciFrendu").fancybox({
		'autoDimensions'	: false,
		'scrolling'		: 'no',
		'titleShow'		: false,
		'width' : 520,
		'height' : 490
	});
	//Kozmo srijeda
	$("#ksrijeda_email_wrap").css("display","none");
	$("#ksrijeda_mobile_wrap").css("display","none");
	
	$("#show_ksrijeda_email").click(function(){
		$("#ksrijeda_email_wrap").toggle("fast");						
		$("#ksrijeda_mobile_wrap").hide("fast");
		$("#show_ksrijeda_mobile").removeClass("ksm_active");
		$(this).toggleClass("kse_active");
		return false;
	});
	$("#show_ksrijeda_mobile").click(function(){
		$("#ksrijeda_mobile_wrap").toggle("fast");						
		$("#ksrijeda_email_wrap").hide("fast");
		$("#show_ksrijeda_email").removeClass("kse_active");
		$(this).toggleClass("ksm_active");
		return false;
	});

	$(".commentlist li").each(function (i) {
		i = i+1;
		$(this).prepend('<span class="commentnumber"> #' +i+ '</span>');
	});

	if ($('.page_subtitle > p').length) {
		var el = $('.page_subtitle > p');
		el.html(el.html().replace(/m2/ig, "m<sup>2</sup>"));
	}
	
});



function checkform() {
	for (i=0;i<fieldstocheck.length;i++)
	{
		if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].type") == "checkbox")
		{
			if (document.subscribeform.elements[fieldstocheck[i]].checked)
			{
			} else {
				alert("Molimo unesite Vaš "+fieldnames[i]);
				eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
				return false;
			}
		} else {
			if (eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].value") == "")
			{
				alert("Molimo unesite Vaš "+fieldnames[i]);
				eval("document.subscribeform.elements['"+fieldstocheck[i]+"'].focus()");
				return false;
			}
		}
	}
	for (i=0;i<groupstocheck.length;i++)
	{
		if (!checkGroup(groupstocheck[i],groupnames[i]))
		{
			return false;
		}
	}
	
	var dan = document.getElementById('dan');
	var mjesec = document.getElementById('mjesec');
	var godina = document.getElementById('godina');

	if (dan.selectedIndex <= 0)
	{
		alert("Molimo odaberite dan rođenja.");
		dan.focus();
		return false;
	}
	else if (mjesec.selectedIndex <= 0)
	{
		alert("Molimo odaberite mjesec rođenja");
		mjesec.focus();
		return false;
	}
	else if (godina.selectedIndex <= 0)
	{
		alert("Molimo odaberite godinu rođenja");
		godina.focus();
		return false;
	}


	if(!compareEmail())
	{
		alert("E-mail adrese koje ste unijeli nisu jednake");
		return false;
	}
	return true;
}

var fieldstocheck = new Array();
var fieldnames = new Array();
function addFieldToCheck(value,name)
{
	fieldstocheck[fieldstocheck.length] = value;
	fieldnames[fieldnames.length] = name;
}
var groupstocheck = new Array();
var groupnames = new Array();
function addGroupToCheck(value,name)
{
	groupstocheck[groupstocheck.length] = value;
	groupnames[groupnames.length] = name;
}

function compareEmail()
{
	return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}
function checkGroup(name,value)
{
	option = -1;
	for (i=0;i<document.subscribeform.elements[name].length;i++)
	{
		if (document.subscribeform.elements[name][i].checked)
		{
			option = i;
		}
  	}
	if (option == -1)
	{
		alert ("Molimo unesite Vaš "+value);
		return false;
	}
	return true;
}
