var cC = "daily_star"; // currentCategory
var cClist = ["daily_star"];
var cA = 1; // currentArticle
var cI = 0; // currentInterval

function load_cal(vector){


	if(refresing == true) return;
	var rand = Math.floor(Math.random( ) * 999999999);
	if(vector == "next"){
		cal_month = cal_month + 1;
		if(cal_month > 12){
			cal_month = 1;
			cal_year = cal_year + 1;
		}
	}
	else if(vector == "prev"){
		cal_month = cal_month - 1;
		if(cal_month < 1){
			cal_month = 12;
			cal_year = cal_year - 1;
		}
	}
	refresing = true;
	new Ajax.Request(webroot + locale + "/calendar/get_cal/", {
		method: "get",
		parameters: {"year": cal_year, "month": cal_month, "rand": rand},
		onComplete: function(transport){
			refresing = false;
		},
		onSuccess: function(transport){
			$("calendar").update(transport.responseText);
		}
	});
}

function selectArticle(aId, cName){


	$(cC + "_a" + cA).hide();

	$("article" + cA).toggleClassName("active");
	cA = aId;

	if(typeof(cName) != "undefined") cC = cName;
	$(cC + "_a" + cA).show();

	$("article" + cA).toggleClassName("active");
}
function selectCategory(cName){
	selectArticle(1, cName);
}
function nextArticle(countA){
	if(cA == countA){
		i = cClist.indexOf(cC);
		i = (i + 1) % 2;
		ncC = cClist[i];
		selectCategory("daily_star");
	}
	else{
		selectArticle(cA+1);
	}
}
function stopArticles(){
	clearInterval(cI);
}

function startArticles(){
	cI = setInterval(function() {
	var count = $('daily_stars_count').value; nextArticle(count); }, 5000);
}

Event.observe(window, 'load', function() {
	startArticles();
	Event.observe('daily_stars', 'mouseover', function(){
		stopArticles();
	});
	Event.observe('daily_stars', 'mouseout', function(){
		startArticles();
	});

	//new PeriodicalExecuter(nextArticle, 30);
});


function hidediv(hide, show, generate, slug1, slug2) {
if (generate == 'luck') {
	$("luck").update('');
	new Ajax.Request( rooturl + locale + "/ajax/pickluck", {
		method: "get",
		onSuccess: function(transport) {
			$("luck").update(transport.responseText);
		}

	});
}

else if (generate == 'com') {

	$("wm3").update('');
			
	slug1 = $(slug1).options[$(slug1).selectedIndex].value;
	slug2 = $(slug2).options[$(slug2).selectedIndex].value;


	new Ajax.Request( rooturl + locale + "/ajax/compatibility?slug1=" + slug1 + "&slug2=" + slug2, {
		method: "get",
		onSuccess: function(transport) {

			$("wm3").update(transport.responseText);
		}

	});

}



if (document.getElementById) { // DOM3 = IE5, NS6
	document.getElementById(hide).style.visibility = 'hidden';
}
else {
	if (document.layers) { // Netscape 4
	document.hide.visibility = 'hidden';
}
else { // IE 4
	document.all.hide.style.visibility = 'hidden';
}
}
document.getElementById(show).style.display = "none";
showdiv(show);
}

function showdiv(show, hide) {
	if (document.getElementById) { // DOM3 = IE5, NS6
	document.getElementById(show).style.visibility = 'visible';
}
else {
	if (document.layers) { // Netscape 4
	document.show.visibility = 'visible';
}
else { // IE 4
	document.all.show.style.visibility = 'visible';
}
}
document.getElementById(show).style.display = "block";

hidediv(hide);
}



var ZodiacSigns = {

    hover: function(signId, className) {
        if($(signId)) {
            var sign = $(signId);

			if (sign.hasClassName(className)) {
                sign.removeClassName(className);
            } else {
                sign.addClassName(className);
            }
        }
    }
};

function show_lunar_phases(year, month) {

$("lunar_text").update('');
	new Ajax.Request( rooturl + locale + "/ajax/show_lunar_months/?year=" + parseInt(year, 10) + "&month=" + month, {
		method: "get",
		onSuccess: function(transport) {
			$("lunar_text").update(transport.responseText);
		}

	});

}




function onover(what){
document.getElementById('text').innerHTML=''+what+'';
}
function onout(){
document.getElementById('text').innerHTML='';
}

function changesubmenu(textchange2)
{

var id = document.getElementById("navigation-sub");

id.innerHTML=textchange2;
}


function send_form()
{
	new Ajax.Request('http://10.0.0.1/myhoroscope_new/bg/horoscopes/send_to_friend', {
		method: 'post',
		parameters: {
			'from' : $F('from'),
			'to' : $F('to'),
			'msg' : $F('msg')
		},
		onSuccess: function(transport) {
			$('send-form').update(transport.responseText);
		}
	});
}

function ScrollBy(dir){
  var left = $('alpha_pager').scrollLeft;
	$('alpha_pager').scrollLeft = (dir =='left') ? left - 28 : left + 28;
}

function changeName (){

	if($('autocomplete-name').value='Въведете име'){
		$('autocomplete-name').value = '';
	}
}


Element.observe(window, "load", function(){
	stars_list();


	//var f = Math.random();
	//if(f < 0.5) {

	//document.getElementById('right_banner').innerHTML = "<embed src='http://myhoroscope.bg/public/flash/baner_300x250.swf' quality='high' bgcolor='#ffffff' width='300' height='250' name='baner_300x250' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	//}
//	new Autocompleter.SelectBox('day');
});

/* Add button functions */

var networkTimeout = 0;

function show_network(){

	clearTimeout(networkTimeout);

	$('networks').show();

}

function hide_network(){

	networkTimeout = setTimeout('close_butt()', 3000);

}

function show_more(){

	$('net_buttons').setStyle({'width': '360px'});

	$('more_networks').setStyle({'width': '350px'});

	$('more_links').show();

	$('more_net').hide();

	$('close_net').show();

}

function close_butt(){

	$('networks').hide();

	$('net_buttons').setStyle({'width': '240px'});

	$('more_networks').setStyle({'width': '230px'});

	$('more_links').hide();

	$('more_net').show();

	$('close_net').hide();

}

function addToFavorites(urlAddress, pageName){

	if (window.sidebar) { // Mozilla Firefox Bookmark

		window.sidebar.addPanel(pageName, urlAddress,"");

	} else if( window.external ) { // IE Favorite

		window.external.AddFavorite( urlAddress, pageName);

	} else { alert("Sorry! Your browser doesn't support this function."); }

}



function vote(id, voting){

	new Ajax.Request( rooturl + locale + "/ajax/vote", {

		method: "get",

		parameters: {"id" : id, "voting" : voting},

		onSuccess: function(transport) {

			$("vote").update(transport.responseText);



		}

	});

}



/* Article tect changing */

function larger_text(element_name){

	if(current_text_size < 5){

		current_text_size++;

		$(element_name).setStyle({'fontSize' : text_sizes[current_text_size]+'%'});

	}

}

function smaller_text(element_name){

	if(current_text_size > 0){

		current_text_size--;

		$(element_name).setStyle({'fontSize' : text_sizes[current_text_size]+'%'});

	}

}

var text_sizes = new Array(80,90,100,120,140,160);

var current_text_size = 2;


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


