// JavaScript Document

var resizeTimer;
var current_hash;
var timeout_id;

jQuery.each(jQuery.browser, function(i) {
  if($.browser.msie){
  	isIE = 1;
  }else{
  	isIE = 0;
  }
});

/* ---------------------------------------------------------------------------------------------------- */
// functions
function init_page () {

//	$('#main_table').css({
//		"height": ($('window').height())+"px"
//		});

	elements_size ();

//	alert ($('body').height());
	}


function elements_size () {
	var c_height;

	c_height = $(window).height() - $('#center_column_top').height();
	if ($(window).height() < $("#left_panel").height()) c_height = $("#left_panel").height() - $('#center_column_top').height();

//	$('#center_column').height($(window).height());
	$('#center_column_bottom').height((isIE)?c_height-4:c_height-2);
	}

// ---------------------------------------------------------------------------------------------------- //

function hash_check () {
//	$("#div_content").html (location.href);
	if (current_hash != location.href) {
//		if (current_hash = "#")
		current_hash = location.href;

		var as = current_hash.split("#");
		if (as.length > 1) {

			$(".div_menufolder").removeClass ("div_menu_selected");
			$(".div_menuitem").removeClass ("div_menu_selected");

			var values = as[1].split("=");
			if (values.length > 1) {
				$.each($(".div_menufolder"), function(i, val) {
					if ($(val).children("a").attr("href") == "#"+as[1]) $(val).addClass ("div_menu_selected");
					});

				if (values[0] == 'cat') {
					$("#page_frame").attr("src", "products.php?cat="+values[1]);
					}

				}
			else { // normal page

				$.each($(".div_menuitem"), function(i, val) {
					if ($(val).children("a").attr("href") == "#"+as[1]) $(val).addClass ("div_menu_selected");
					});

				switch (values[0]) {
					case "cum":
					$("#page_frame").attr("src", "cum.php");
					break;
					case "cine":
					$("#page_frame").attr("src", "cine.php");
					break;
					case "contact":
					$("#page_frame").attr("src", "contact.php");
					break;
					case "utile":
					$("#page_frame").attr("src", "utile.php");
					break;
					default:
					break;
					}
				}
			}
		else { // no deep link, display front page
//			location.href = "#cine";
			$("#page_frame").attr("src", "cine.php");
			}
		}
	timeout_id = setTimeout ("hash_check()",200);
	}

/* ---------------------------------------------------------------------------------------------------- */

function hash_silentset (new_hash) {
	clearTimeout (timeout_id);
	current_hash = new_hash;
	location.href = new_hash;
	timeout_id = setTimeout ("hash_check()",200);
	}

/* ---------------------------------------------------------------------------------------------------- */

$(document).ready(function(){
	init_page();

	$(window).load(function(){

		current_hash = "";
		hash_check ();

		$(window).bind('resize', function() {
		    if (resizeTimer) clearTimeout(resizeTimer);
		    resizeTimer = setTimeout(elements_size, 10);
			});

		});

	});

/* ---------------------------------------------------------------------------------------------------- */

