/* Addons */

String.prototype.replaceAll = function(search, replace)
{
	return this.split(search).join(replace);
}

function uniqId()
{
	return (new Date()).getTime() + "" + Math.random() + "" + Math.random();
}

/* Captcha */

function captchaRefresh(img_id)
{
	$('img#'+img_id).attr("src", "captcha?"+uniqId());
}

/* Functions URL */

function urlConfirm(url, msg) {
	if (confirm(msg))
		window.location = url;
}

function jsConfirm(js, msg) {
	if (confirm(msg))
		eval(js);
}

function urlPopup(p_url, p_w, p_h) {

	var p_left = ($(window).width() - p_w) / 2;
	var p_top = ($(window).height() - p_h) / 2;

	newWin = window.open(p_url, 'newWin', 'location,width='+p_w+',height='+p_h+',left='+p_left+',top='+p_top);
	newWin.focus();
}

/* Cufon styles & Navigation JS & colorbox & accordion */

$(document).ready(function() { /* doc ready start */

	/* Form submit */
	$("form").submit(function() {
		$("input[type=submit]:not(.no-auto-disable)").attr({
			'disabled': 'disabled',
			'value': 'Loading...'
		});
	});

	/* colorbox */
	$("a[rel='cb_gallery']").colorbox({
					initialWidth:200,
					initialHeight:50,
					opacity: 0.6,
					maxWidth:'1200px'
	});
	$("a.cb_gallery").colorbox({
					initialWidth:200,
					initialHeight:50,
					opacity: 0.6,
					maxWidth:'1200px'
	});
	$(".cb_accordion").accordion({ header: "h6", active: false });

	/* Cufon styles */
	Cufon.replace(".cf-gen", {hover: true});

	Cufon('h1, h2, h3, h4, h5 .quote_author', {
		color: '-linear-gradient(#282828, #1d1d1d)',
		textShadow: '1px 1px #fff'
	});

	/* news date */
	Cufon('.post_type div, .post_type span', {
		color: '-linear-gradient(#fff, 0.4=#e8eaeb, #b0b5b8)',
		textShadow: '1px 1px #000'
	});

	/* widget header */
	Cufon('.w_header', {
		color: '-linear-gradient(#fff, 0.4=#e8eaeb, #b0b5b8)',
		textShadow: '1px 1px #000'
	});

	/* cufon styles for nav level 1 list */
	Cufon('#nav > li > a', {
		color: '-linear-gradient(#fff, 0.4=#0f52cf, 0.6=#00385c, blue)',
		textShadow: '1px 1px #a3c8e0',
/*
		textShadow: '1px 1px #a3c8e0',

xz:
		color: '-linear-gradient(#fff, 0.4=#bb007b, 0.6=#000, #fff)',
		textShadow: '1px 1px #b06195',
*/

		hover: {
			color: '-linear-gradient(#fff, 0.7=#0f52cf, 0.3=#00385c, #fff)',
			textShadow: '1px 1px #b06195'
/*
old:
			color: '-linear-gradient(#fff, 0.4=#0f52cf, 0.6=#bb007b, #fff)',
			textShadow: '1px 1px #b06195'
*/
		}
	});

	/* vars */
	var tout = new Array();
	var the_elem;
	var the_elem2;
	var n = 0;

	/* make IDs for level 1 list */
	$("#nav > li").each(function () {
		$(this).find("a:eq(0)").attr("id", "m"+(++n));
	});

	/* level 1 item: mouseover */
	$("#nav > li.parent").mouseover(function ()
	{
		var dd = $(this).find("a:eq(0)").attr("id"); /* get "li > a" ID */
		if ( tout[dd] ) clearTimeout( tout[dd] ); /* timeout clear */
		the_elem = $(this); /* get "li" */

		tout[dd] = setTimeout(function ()
		{
			if (the_elem.find("div").is(":visible")) return; /* if level 2 = visible => do nothing */
			$("#nav > li > div").hide(); /* hide all level 2 menues */

			if ($.browser.msie) /* if IE = no animation */
			{
				the_elem.find("div").css({
					display: 'block',
					opacity: 0.75,
					top: '20px'
				});
				the_elem.find("div")[0].style.removeAttribute('filter');
				return;
			}

			/* animation */
			the_elem.find("div").css({
				display: 'block',
				opacity: 0,
				top: '30px'
			}).animate({
				opacity: 0.75,
				top: '15px'
			}, {
				duration: 200,
				queue: false,
				complete: function () {
					if ($.browser.msie) this.style.removeAttribute('filter');               
				}
			});
		}, 100);
	});

	/* level 1 item: mouseout */
	$("#nav > li.parent").mouseout(function ()
	{
		the_elem2 = $(this);
		var dd = $(this).find("a:eq(0)").attr("id");

		if ( tout[dd] ) clearTimeout( tout[dd] );

		tout[dd] = setTimeout(function () {
			the_elem2.find("div:eq(0)").hide();
		}, 100);
	});

	/* <marquee> animation */
	$('marquee').marquee();

}); /* doc ready end */

/* Book comments delete function */
function book_com_del(c_id)
{
	/* ajax */
	$.post("mod/proc-a-book-com-del", {c_id: c_id}, function(data){
		if (data === 'ok')
		{
			$("#book-com-id-" + c_id).slideUp("fast");
		}
		else {
			alert(data);
		}
	});
}
