// IE - fix blikajicich backgroundu
eval("try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}");

$(document).ready(function() {

	$("#user-box .login a.action").bind("click",function(){
		$("#user-box .login form").toggle();
		return false;
	});

	$("#content table").each(function(){
		$("tbody tr:even",this).addClass("odd");
	});

	$(".manage-widget").click(function(){
		index = $(this).prevAll(".hide-widget").length-1;
		$(this).prevAll(".hide-widget:eq("+index+")").slideToggle("blind","",500);
		$(this).prevAll(".hide-widget:eq("+index+") input.text").val("");
		if($(this).hasClass("hide")){
			$(this).removeClass("hide").addClass("show").text(locale[$(this).attr("rel")+'-show']);
		} else {
			$(this).removeClass("show").addClass("hide").text(locale[$(this).attr("rel")+'-hide']);;
		}
		return false;
	});

	$("#content input.date").datepicker({
		showOn: "button",
		buttonImage: "/img/u/ico-calendar.png",
		buttonImageOnly: true,
		changeMonth: true,
		changeYear: true,
		yearRange: 'c-40:c+10'
	});

	$("#content input.dateDayMonth").datepicker({
		showOn: "button",
		buttonImage: "/img/u/ico-calendar.png",
		buttonImageOnly: true,
		changeMonth: true,
		changeYear: true,
		yearRange: 'c-40:c+10',
		dateFormat: 'd.m.'
	});

	$("#content input.date, #content input.time").attr("readonly","readonly");

	$('#content input.time').ptTimeSelect({
		hoursLabel: locale['hours'],
		minutesLabel: locale['minutes'],
		setButtonLabel: locale['set'],
		popupImage: '/img/u/ico-time.png',
		onFocusDisplay: false
	});

	$("form#registerGirl #tattoDescription").parent("p").hide();
	$("form#registerGirl #piercingDescription").parent("p").hide();
	$("form#registerGirl #tattoo_1").change(function() {
		$("form#registerGirl #tattoDescription").parent("p").show();
	});
	$("form#registerGirl #tattoo_2").change(function() {
		$("form#registerGirl #tattoDescription").parent("p").hide();
	});
	$("form#registerGirl #piercing_1").change(function() {
		$("form#registerGirl #piercingDescription").parent("p").show();
	});
	$("form#registerGirl #piercing_2").change(function() {
		$("form#registerGirl #piercingDescription").parent("p").hide();
	});

	$(".gallery.girls li").each(function() {
		$("a:first", this).mouseover(function(){
			$(".info-box",$(this).parent()).show();
		});
		$(".info-box", this).mouseover(function(){
			$(this).show();
		});
	});

	$(".gallery.girls li").mouseout(function(){
		$(".info-box",this).hide();
	});

	$("table.table-view tbody td").mouseover(function(){
		$(".info-box",this).show();
	}).mouseout(function(){
		$(".info-box",this).hide();
	});

	$(".info-box table tr").each(function(){
		$("td:first",this).addClass("title");
	});

	$("table.table-view tbody tr").mouseover(function(){
		$(this).addClass("hover");
	}).mouseout(function(){
		$(this).removeClass("hover");
	});

	$("#birthDate").removeAttr("readonly");

	var zindex = 10000;
	$(".gallery.girls li").each(function(){
		$(this).css("z-index",zindex);
		zindex--;
	});

	var actualZindex = 0;
	$(".gallery.girls li.last").mouseover(function(){
		actualZindex = $(this).css("z-index");
		$(this).css("z-index",10001);
	}).mouseout(function(){
		$(this).css("z-index",actualZindex);
	});

	if($("form#registerGirl #tattoo_1:checked").length >0 ){
		$("form#registerGirl #tattoDescription").parent("p").show();
	}
	if($("form#registerGirl #piercing_1:checked").length >0 ){
		$("form#registerGirl #piercingDescription").parent("p").show();
	}
});


/**
 * nahrazeni nojs prepinani jazyku dhtml selectem
 */
function initLangSwitchHp() {
	var oId = "#tool-box .languages .in";
	var sb = new StringBuffer();
	$("a:eq(0)", $(oId)).each(function() {
		sb.append('<a href="'+$(this).attr("href")+'">'+$(this).html()+'</a>'+$(this).attr("title"));
	});

	sb.append('<ul class="hidden">');
	$("a:gt(0)", $(oId)).each(function() {
		sb.append('<li class="png-fix"><a href="'+$(this).attr("href")+'">'+$(this).html()+'</a>'+$(this).attr("title")+'</li>');
	});
	sb.append('</ul>');

	$(oId).html(sb.getString());

	$("#tool-box .languages .right").bind("click", function(event) {
		$("ul", $(oId)).slideToggle(100);
		event.preventDefault();
	});

	$("ul li", $(oId)).bind("click",function(event){
		window.location = $("a",this).attr("href");
		event.preventDefault();
	});

}

function initLangSwitch() {
	var oId = "#tool-box";
	var sb = new StringBuffer();

	$(oId).html('<span class="languages png-fix">'+$(oId+" .languages").html()+'</span>').addClass("subpage");

	$(".languages a:eq(0)", $(oId)).each(function() {
		sb.append('<a href="'+$(this).attr("href")+'" class="actual">'+$(this).html().replace("-small","-inact")+'</a>');
	});

	sb.append('<ul class="hidden">');
	$(".languages a:gt(0)", $(oId)).each(function() {
		sb.append('<li><a href="'+$(this).attr("href")+'">'+$(this).html().replace("-small","")+'</a></li>');
	});
	sb.append('</ul>');

	$(".languages", $(oId)).html(sb.getString());

	$("a.actual", $(oId)).bind("click",function(){
		if($(oId).hasClass("active")){
			$("img",$(this)).attr("src",$("img",$(this)).attr("src").replace(".","-inact."));
		} else {
			$("img",$(this)).attr("src",$("img",$(this)).attr("src").replace("-inact.","."));
		}

		$("ul", $(oId)).slideToggle(50);
		$(oId).toggleClass("active");
		return false;
	});

	$(oId).append('<a href="#" class="print png-fix">'+locale["print"]+'</a>');
	$(".print",$(oId)).bind("click",function(){
		window.print();
		return false;
	});
}

function StringBuffer() {
	this.buffer = "";
	this.append = function(str) { this.buffer += str; return this; };
	this.getString = function() { return this.buffer; };
	this.reset = function() { this.buffer=""; };
}
