/* 
 * horoskopai
 */

function open_horoscope_sign_select(){
	$(document).one("click", close_horoscope_sign_select);
	$("#horoscope_sign_sel").removeClass("hidden");
	return false;
}

function close_horoscope_sign_select() {
	if($("#horoscope_sign_sel").hasClass("hidden")) {
		return true;
	} else {
		$("#horoscope_sign_sel").addClass("hidden");
		return false;
	}
}

function toggle_horoscope_sign_select() {
	if($("#horoscope_sign_sel").hasClass("hidden")) {
		open_horoscope_sign_select();
	} else {
		close_horoscope_sign_select();
	}
	return false;
}

function change_horoscope_sign(sign) {
	close_horoscope_sign_select();
	$("#horoscope").ajaxStart(function(){
		$("#horoscope").addClass("loading");
	});
	$("#horoscope").ajaxComplete(function(){
		$("#horoscope").removeClass("loading");
	});

	$.ajax({
		url: "/horoscope/view/"+sign,
		type: "POST",
		timeout: 20000,
		data: "",
		error: function(){
			/*alert("klaida");*/
		},
		success: function(html){
			$("#horoscope").html(html);
			prepare_horoscope_sign_select();
		//	$("#horoscope").load(window.location+"?multi_disable=true");
			return true;
		}
	});
	return false;
}

function prepare_horoscope_sign_select() {
	$("#horoscope_sign_sel_a").click(toggle_horoscope_sign_select);
	$("#horoscope_sign_sel_img").click(toggle_horoscope_sign_select);
}


/*
*	Orai	
*/

function open_weather_select(){
	$(document).one("click", close_weather_select);
	$("#weather_sel").removeClass("hidden");
	return false;
}

function close_weather_select() {
	if($("#weather_sel").hasClass("hidden")) {
		return true;
	} else {
		$("#weather_sel").addClass("hidden");
		return false;
	}
}

function toggle_weather_select() {
	if($("#weather_sel").hasClass("hidden")) {
		open_weather_select();
	} else {
		close_weather_select();
	}
	return false;
}

function change_weather(sign) {
	close_weather_select();
	$("#weather").ajaxStart(function(){
		$("#weather").addClass("loading");
	});
	$("#weather").ajaxComplete(function(){
		$("#weather").removeClass("loading");
	});

	$.ajax({
		url: "/weathers/view/"+sign,
		type: "POST",
		timeout: 20000,
		data: "",
		error: function(){
			/*alert("klaida");*/
		},
		success: function(html){
			$("#weather").html(html);
			prepare_weather_select();
			return true;
		}
	});
	return false;
}

function prepare_weather_select() {
	$("#weather_sel_a").click(toggle_weather_select);
	$("#weather_sel_img").click(toggle_weather_select);
}
/**
vote
**/
/* 
 * balsavimas
 */

$(document).ready(function(){
	$("#pollcontrol").show();
	$("#voteFrm").submit( function(){
	    var str = $("#voteFrm").serialize();
        $(this).ajaxStart(function(){
                $(this).addClass("loading");
        })
        $(this).ajaxComplete(function(){
                $(this).removeClass("loading");
        });

		if(str.match(/answer/)!=null){
		    $.ajax({
		        url: "/poll/add/?multi_disable=true",
		        type: "POST",
		        timeout: 20000,
		        data: str,
		        error: function(){
		            /*alert("klaida");*/
		        },
		        success: function(html){
		            $("#apklausa").html(html);
		        //    $("#apklausa").load(window.location+"?multi_disable=true #apklausa");
		        	return true;
		        }
		    });
	    }
	    return false;
	});
	
	$("a.ap_rez").click(function(event){
	    $("#apklausa").load("http://"+window.location.hostname+"/poll/view/?multi_disable=true");
		return false;
	});
});

/*
sizing
*/

$(document).ready(function()  
{ 
	var min=10;
	var max=16;
	 
	$('a.didinti').click(function()  
	{  
	    var theElement = $('.duc1').css("font-size");
	    var textSize = parseFloat(theElement, 10);  
	    var unitOfMeasurement = theElement.slice(-2); 
	     
		if(textSize!=max) {
		   textSize += 1;
		}
		var lineSize = (textSize + 3);
	    $.cookie('textSize',textSize ,{ path: '/', domain: '.atn.lt', expires: 100 }) 
	    $('.duc1').css("font-size",  textSize + unitOfMeasurement);
	    $('.duc1').css("line-height",lineSize.toString() + unitOfMeasurement );
	    $('.fs14').css("font-size", textSize+2 );
	    $('h2').css("font-size", textSize+5 );
	    $('p').css("font-size",  (textSize ) + unitOfMeasurement);
	    return false;  
	}); 
	    
	$('a.mazinti').click(function()  
	{  
	    var theElement = $('.duc1').css("font-size");  
	    var textSize = parseFloat(theElement, 10);  
	    var unitOfMeasurement = theElement.slice(-2);  

		if(textSize!=min) {
		   textSize -= 1;  
		}	  
		var lineSize = (textSize + 3);
	    $.cookie('textSize',textSize ,{ path: '/', domain: '.atn.lt', expires: 100 }) 
	    $('.duc1').css("font-size",  textSize + unitOfMeasurement);
	    $('.duc1').css("line-height", lineSize.toString() + unitOfMeasurement );
	    $('.fs14').css("font-size", textSize+2 );
	    $('h2').css("font-size", textSize+5 );
	    $('p').css("font-size",  (textSize ) + unitOfMeasurement);
	    return false;  
    });
    function setFromCookie(){
    	var theElement = $('body').css("font-size");   
	    var unitOfMeasurement = theElement.slice(-2);
	    textSize = $.cookie('textSize');
    	//alert(textSize);to
    	if (textSize){
    		var lineSize = (parseInt(textSize) + 3);
	    	$('.duc1').css("font-size",textSize + unitOfMeasurement);
	    	$('.duc1').css("line-height",lineSize.toString() + unitOfMeasurement );
	    	$('.fs14').css("font-size", (parseInt(textSize) + 2));
	    	$('p').css("font-size",(textSize)  + unitOfMeasurement);
	    }
	    return false;
    } ; 
    setFromCookie();
});

/* 
 * paieska
 */

$(document).ready(function() {
	$("#live_search").autocomplete("/search/live/", {single:'true', minChars:3, matchSubset:1, matchContains:1, cacheLength:10, selectOnly:0 });
});



$(document).ready(prepare_weather_select);
$(document).ready(prepare_horoscope_sign_select);
