﻿<!--

var cellEmpty = "<!-- -->";
var htmlMinWidth = 1000;
var suggestSrc;
var suggestValue = '';
var suggestLoad = false;
var id = '';
var suggest = '';
cell = [];

// Set columns count cookie
function setColCookie()
{
var theDate = new Date();
var oneYearLater = new Date(theDate.getTime() + 31536000000);
var expiryDate = oneYearLater.toGMTString();

document.cookie='col=' + col + '; expires=' + expiryDate + '; path=/';
}


// Check comment's length
function checkLength(len, label_id, button)
{
document.getElementById(label_id).innerHTML = len+'&nbsp;/ ' + max_comment_size;

if( 0 == len || len > max_comment_size)
	{
	$(button).disabled = true;
	}
else
	$(button).disabled = false;
}


// Add to bookmarks
function bookmark(a)
{
if(window.opera)
	{
	a.href = location.href;
	a.rel = 'sidebar';
	a.title = document.title;
	}

if(window.sidebar && !window.opera)
	window.sidebar.addPanel(document.title, location.href, "");

if(window.external && !window.sidebar && !window.opera)
	window.external.AddFavorite(location.href, document.title);

return true;
}


// Check and rebuild table if necessary
function checkTable()
{
tableWidth = $("body").width() * .75 - 40;
newCol = Math.floor(tableWidth/cellMinWidth);

// rebuild table with new columns value
if(newCol != col && newCol > 0)
	{
	i = 0;
	newTable = "";

	for(i = 0; i < Math.ceil(cell.length/newCol); i++)
		{
		buffer = "";

		for(j = 0; j < newCol; j++)
			{
			k = i * newCol + j;

			buffer += "<td>"

				+ (k < cell.length
					? cell[k]
					: cellEmpty )
				+ "</td>";
			}

		newTable += "<tr>" + buffer + "<tr>";
		}

	$("#films").css("overflow-x", "hidden");
	$("#films").empty();
	$("#films").append(newTable);
	$("#films").css("overflow-x", "visible");

	col = newCol;

	// update cookie
	setColCookie();
	}

var width = Math.floor(tableWidth/col-60);
document.cookie='cell=' + width + '; path=/';
$("#films td").css("width", width + "px");

}


// Docement onLoad
$(document).ready(function()
{
// add to bookmarks (after send link)
$("#links").each(function()
	{
	if(window.sidebar || window.external || window.opera)
		$(this).append(" <a href=\"javascript:void(0)\" onclick=\"return bookmark(this);\" class=arrow>" + txt_bookmark + "</a>");
	} );

// wrappers
$("#lang ul").wrap("<div class=w></div>");
$("#guardian").wrapInner("<div class=w></div>");
$("#user ul").wrap("<div class=w></div>");
$("#banner a").wrap("<div class=w></div>");

// links
$("#banner a.arrow").each(function()
	{
	$(this).after("<a href=\"" + $(this).attr('href') + "\" class=link>&nbsp;</a>");
	} );


// msie-specified operations
/*@cc_on

// ie7 and older
@if(@_jscript_version <= 5.7)
	{
	$("#lang .w").after("<div class=ie></div>");
	$("#guardian .w").after("<div class=ie></div>");
	$("#user .w").after("<div class=ie></div>");
	$("#banner .w").after("<div class=ie></div>");
	}
@end

// show header
$("#header").css("display", "block");
@*/

// email decode
$(".email").each(function()
	{
	encoded = $(this).html().match(/([\s\S]*)<!--([\s\S]+)-->/);

	if(null != encoded)
		{
		email = '';
		len = encoded[2].length;

		for(i = 0; i < len; i += 2)
			email += (i + 1 < len ? encoded[2].charAt(i + 1) + encoded[2].charAt(i) : encoded[2].charAt(i));

//20010511
//		$(this).replaceWith("<a href=\"mailto:" + email + "\">" + ( 8212 == encoded[1].charCodeAt(0) ? email : encoded[1] ) + "</a>");
		$(this).replaceWith("<a href=\"mailto:" + email + "\">" + email + "</a>");
		}
	} );

// Hanging quotes
///$("#content").html($("#content").html().replace(/</g, '<span class=q>&#171;</span>').replace(/ <span class=q>/g, '<span class=sq> </span><span class=q>'));

// Get table cells into array
$("#films td").each(function(i)
	{
	if(this.innerHTML != cellEmpty)
		cell[i] = this.innerHTML;
	});

// Image frames
$("#content img.i").each(function()
	{
	$(this).wrap("<div class=i></div>");
	$(this).after("<div><div><div><div style=\"width:"
		+ ($(this).width() + 10) + "px;height:" + ($(this).height() + 10)
		+ "px\"><!-- --></div></div></div></div>");

	$(this).removeClass("i");
	});

// Unobtrusive JS
$("#order_s").change(function()
	{
	$("#order").submit();
	});

$("#favorite_s").change(function()
	{
	$("#favorite").submit();
	});

$("#rating_s").change(function()
	{
	$("#rating").submit();
	});

$("#comment textarea").keypress(function()
	{	
	checkLength(this.value.length, 'size', "#comment:submit");
	});

$("#comment textarea").keyup(function()
	{	
	checkLength(this.value.length, 'size', "#comment:submit");
	});

$("#comment textarea").change(function()
	{	
	checkLength(this.value.length, 'size', "#comment:submit");
	});

$("#comment textarea").each(function()
	{
	checkLength(0, 'size', "#comment:submit");
	});

// Password show/hide
$("#show").click(function()
	{
	setPasswordForm(this);
	});

// EMBED CODE
// Supress form submit
$("#embed").submit(function()
	{
	return false;
	});

// Place code to the field
$("#embedmode").change(function()
	{
	$("#embedcode").val($(this).val());
	});

// Select all code on entry
$("#embedcode").click(function()
	{
	this.focus();
	this.select();
	});

// Check column cookie
if(-1 == document.cookie.indexOf('col='))
	setColCookie();

// Suggest callback init
suggestSrc = $("#suggest").attr("src");

$(".suggest").keydown(function()
	{
	suggestValue = this.value;
	});

// Suggest update
$(".suggest").keyup(function()
	{
	// Update suggest
	if(suggestValue != this.value)
		{
		suggestLoad = false;
		time = new Date();

		$("#suggest").load
			( suggestSrc
			, "suggest=" + this.name
				+ "&query=" + encodeURI($(this).val())
				+ "&time=" + time.getTime()

			, showSuggest
			);

		suggestValue = this.value;
		}
	});


// Simulate window resizing
$(window).resize();

// Set change password form state
setPasswordForm($("#show").get(0));

/*@cc_on
$("#pw_change").show();
@*/
});


// Window onResize
$(window).resize(function()
{
// ie6 min-width emulation
/*@cc_on
@if(@_jscript_version <= 5.6)
	{
	width = $(window).width();
	$("body").width(width < htmlMinWidth ? htmlMinWidth : width);
	}
@end
@*/

checkTable();
});


// Show suggested values
function showSuggest()
{
eval($("#suggest").html());
}


// Set change password form status
function setPasswordForm(show)
{
if(show.checked)
	{
	var pwd = $("#pwh").val();

	$("#pw_hide").hide();
	$("#pw_show").show();

	$("#pwo").val(pwd);
	$("label.error[for=pwh]").attr("for", "pwo");
	}
else
	{
	var pwd = $("#pwo").val();

	$("#pw_show").hide();
	$("#pw_hide").show();

	$("#pwh").val(pwd);
	$("label.error[for=pwo]").attr("for", "pwh");
	}
}

// -->
