var tmr_banner, tmr_lastnews, now_banner_index;

$(document).ready(function()
{
	$('.ratings_stars').hover(
		function() {
			$(this).prevAll().andSelf().addClass('ratings_over');
			$(this).nextAll().removeClass('ratings_vote');
		},
		function() {
			$(this).prevAll().andSelf().removeClass('ratings_over');
			set_rate($(this).parent());
		}
	);
		
$('.ratings_stars').bind('click', function()
{
	var star = this;
	var rate = $(star).attr('lang');
	var id = $(star).parent().attr('lang');
	var cont = $('#rate'+id).children('s').html();
	add_rate(cont, id, rate);
});

	if ($('#popup').size() > 0) {showPopup();}
});

$(".block .title").click(function(){$(this).next().slideToggle(500);});
$("#c-pause").click(function(){$(this).css('display', 'none');$('#c-resume').css('display', 'inline-block');$('#currencies').stop();});
$("#c-resume").click(function(){$(this).css('display', 'none');$('#c-pause').css('display', 'inline-block');curr_interval=curr_def_interval;currMove();});
$("#login-remember, #login-remember + span").click(function(){if($("#login-remember").attr('class')=='icheckbox-unchecked'){$("#login-remember").attr('class', 'icheckbox-checked');}else{$("#login-remember").attr('class', 'icheckbox-unchecked');}});
$('#searchbox').val(search_text).focus(function(){if ($(this).val() == search_text) {$(this).val('');}}).blur(function(){if ($(this).val()==''){$(this).val(search_text);}}).keypress(function(e){var code = (e.keyCode ? e.keyCode : e.which);if (code == 13) {whois();}});
$('#login-username').focus(function(){if ($(this).val() == 'Username') {$(this).val('');}}).blur(function(){if ($(this).val() == '') {$(this).val('Username');}});
$('#login-password').focus(function(){if ($(this).val() == 'password') {$(this).val('');}}).blur(function(){if ($(this).val() == '') {$(this).val('password');}});
$('#searchbox').keypress(function(e){var code = (e.keyCode ? e.keyCode : e.which);if (code == 13) {do_search();}});

//Currency
var curr_tmr, from_moves=false, curr_def_interval=400, curr_fas_interval=60, curr_med_interval=200;
var curr_movement = 20//parseInt($('#currencies li').width());
var curr_interval = curr_def_interval;
var curr_width = parseInt($('#currencies li').width()) * $('#currencies li').size();
var curr_max_left = curr_width - parseInt($('.currs').width());
var curr_goto = '-';
$('#currencies').css('width', curr_width + 'px');
function currMove()
{return;
	if ($('#c-resume').css('display') == 'inline-block'){return;}
	clearTimeout(curr_tmr);
	if (curr_goto == '-' && $('#currencies').position().left <= -curr_max_left){curr_goto = '+'; if(from_moves){return;}; curr_tmr = setTimeout("currMove()", 2000); return;}
	if (curr_goto == '+' && $('#currencies').position().left >= 0){curr_goto = '-'; if(from_moves){return;}; curr_tmr = setTimeout("currMove()", 2000); return;}
	$('#currencies').animate({'left': curr_goto+'='+curr_movement+'px'}, curr_interval, 'linear', function(){currMove();});
}
$("#currs-move1").hover(function(){curr_interval=curr_fas_interval;curr_goto='-';from_moves=true;$('#currencies').stop();currMove();}, function(){curr_interval=curr_def_interval;from_moves=false;$('#currencies').stop();currMove();});
$("#currs-move2").hover(function(){curr_interval=curr_med_interval;curr_goto='-';from_moves=true;$('#currencies').stop();currMove();}, function(){curr_interval=curr_def_interval;from_moves=false;$('#currencies').stop();currMove();});
$("#currs-move3").hover(function(){curr_interval=curr_med_interval;curr_goto='+';from_moves=true;$('#currencies').stop();currMove();}, function(){curr_interval=curr_def_interval;from_moves=false;$('#currencies').stop();currMove();});
$("#currs-move4").hover(function(){curr_interval=curr_fas_interval;curr_goto='+';from_moves=true;$('#currencies').stop();currMove();}, function(){curr_interval=curr_def_interval;from_moves=false;$('#currencies').stop();currMove();});
currMove();
//End Currency

//LASTNEWS
var news_num = $('#lastnews li').size();
var now_news_index = 1;
var news_stop=5000;
var news_speed=1000;
if(news_num>1){tmr_lastnews = setTimeout("lastnewsShow()", news_stop);}
function lastnewsGoTo(id)
{
	$("#lastnews ul").animate({"marginTop": "-=40px"}, news_speed);
	clearTimeout(tmr_lastnews);
	tmr_lastnews = setTimeout("lastnewsShow()", news_stop);
}
function lastnewsShow()
{
	var id = now_news_index;
	if (id >= news_num) {$("#lastnews ul").animate({"marginTop": "0px"}, 500, '', function() {now_news_index = 2; tmr_lastnews = setTimeout("lastnewsGoTo(1)", news_stop);});}
	else {lastnewsGoTo(id);}
	now_news_index += 1;
}
//END LASTNEWS

//BANNER
var banner_num = banner_image.length;
now_banner_index = 0;
sliderGoTo(0);
preload_banners();
function sliderGoTo(id)
{
	clearTimeout(tmr_banner);
	if (id == -1) {id = banner_num-1;}
	if (id < 0 || id >= banner_num) {id=0;}
	$('#img').fadeTo(500, 0.1, function(){$(this).attr('src', banner_image[id]).fadeTo(500, 1); $(this).parent().attr('href', banner_link[id]);})
	if (banner_num > 1)
		tmr_banner = setTimeout('nextShow()', banner_stop[id]*1000);
	now_banner_index = id;
}
function previousShow()
{
	sliderGoTo(now_banner_index-1);
}
function nextShow()
{
	sliderGoTo(now_banner_index+1);
}
function startStopShow(el)
{
	if ($(el).attr("class") == "play") {
		nextShow();
		$(el).attr("class","stop");
	} else {
		clearTimeout(tmr_banner);
		$(el).attr("class","play");
	}
}
function preload_banners()
{
	var imgs = new Array();
	for (i=0; i<banner_num; i++)
	{
		imgs[i] = new Image();
		imgs[i].src = banner_image[i];
	}
}
//END BANNER

function toggle_forgetpass()
{
	if ($('#login-login').css('display') == 'none')
	{
		$('#login-login').css('display', 'block');
		$('#login-forgetpass').css('display', 'none');
	}
	else
	{
		$('#login-login').css('display', 'none');
		$('#login-forgetpass').css('display', 'block');
	}
}

function getCheckboxValuesByName(name, delimiter)
{
	if (typeof(delimiter) == "undefined")
	{
		delimiter = "";
	}
	len = document.getElementsByName(name).length;
	rtn='';
	for (i=0; i<len; i++)
	{
		if (document.getElementsByName(name)[i].checked)
			rtn += document.getElementsByName(name)[i].value + delimiter;
	}
	return rtn;
}
function jqScrollTo(target, more)
{
	var top = target.offset().top + more;
	$('html,body').animate({scrollTop: top}, 1000);
	return false;
}
function verifyDelete()
{
	if (confirm("Are you sure you want to delete?")){
		return true;
	} else {
		return false;
	}
}
function regform_backto(step)
{
	$('#regform'+(step+1)).slideUp(500);
	$('#regform'+step).slideDown(500);
}
function startUpload()
{
	$('#up_form').css('display', 'none');
	$('#up_status').html('<p class="uploading></p>').css('display', 'block');
	return true;
}
function showPopup()
{
	var doc_width = $(document).width();
	var doc_from_top = $('html').scrollTop();
	var my_width = 300;
	var cent = (doc_width - my_width) / 2;
	$('#popup').css('left', cent+'px').css('top', (doc_from_top+150)+'px').show(900);
}

function addBookmark()
{
	var title = document.title;
	var url = window.location.href;
	if(window.sidebar){ // Firefox
		window.sidebar.addPanel(title, url,'');
	}else if(window.opera){ //Opera
		var a = document.createElement("A");
		a.rel = "sidebar";
		a.target = "_search";
		a.title = title;
		a.href = url;
		a.click();
	} else if(document.all){ //IE
		window.external.AddFavorite(url, title);
	}
}
function refresh_captcha()
{
	var d = new Date();
	d = d.getTime();
	$('#img-captcha').attr('src', 'captcha/'+d);
}
