
$j = $; //jQuery.noConflict();

/*$(window).resize(function() {
	if($j("#Main-2").outerHeight({margin:true})<($j(window).innerHeight()-12)) {
		$j("#Main-2").css("height",($j(window).innerHeight()-12)+"px");
		$j("#BottomMenuLine").css("top",($j("#Main-2").innerHeight()-6-$j("#BottomMenuLine").height())+"px");
	} else {
		$j("#Main-2").css("height",($j(document).height()+$j("#BottomMenuLine").outerHeight()+12)+"px");
		$j("#BottomMenuLine").css({
			"position": "absolute",
			"top": ($j("#Main-2").outerHeight()-6-$j("#BottomMenuLine").outerHeight())+"px"
		});
	}
});*/


$j(document).ready(function(){
	$j("#Main-2").css("min-height",($j(window).height()-12)+"px");
	/*if($j("#Main-2").outerHeight({margin:true})<($j(window).innerHeight()-12)) {
		$j("#Main-2").css("height",($j(window).innerHeight()-12)+"px");
		$j("#BottomMenuLine").css("top",($j("#Main-2").innerHeight()-6-$j("#BottomMenuLine").height())+"px");
	} else {
		$j("#Main-2").css("height",($j(document).height()+$j("#BottomMenuLine").outerHeight()+12)+"px");
		$j("#BottomMenuLine").css({
			"position": "absolute",
			"top": ($j("#Main-2").outerHeight()-6-$j("#BottomMenuLine").outerHeight())+"px"
		});
	}*/
	
	
	// disable old events
	/*
	$j('li.Level0Item > ol').hide();

	$j('li.Level0Item').mouseover(function(){
		console.log('hover');
		$j('> ol', this).slideDown();
	}).mouseout(function(){
		$j('> ol', this).slideUp();
	});
	*/

/*
	if (TransMenu.isSupported() && 0)
	{
		function init_transmenu_subitems(transmenu, subitems)
		{
			subitems.each(function(i){
				var link = $j('> a', this);
				var item = transmenu.addItem(link.text(), link.attr('href'), link.attr('target'));

				var subitems = $j('> ol > li', this);
				if (subitems.length)
				{
					var subtransmenu = transmenu.addMenu(transmenu.items[i], i);
					init_transmenu_subitems(subtransmenu, subitems);
				}
			});
		}

		function hide_transmenu()
		{
			TransMenuSet.registry[0].hide();
		}

		var menuitems = $j('li.Level0Item').add('li.TopMenuItem').add('#MoilHeader');

		var ms = new TransMenuSet(TransMenu.direction.down, 1, 24, TransMenu.reference.topLeft);

		// generate transmenu from html
		menuitems.each(function(){
			var subitems = $j('> ol > li', this);
			if (!subitems.length)
			{
				this.onmouseover = hide_transmenu;
			}
			else
			{
				var link = $j('> a', this);
				var transmenu = ms.addMenu(link[0], 0);

				init_transmenu_subitems(transmenu, subitems);
			}
		});

		// remove menu from html
		menuitems.find('> ol').remove();
*/
		/*
		menu.onactivate = function() {};
		menu.ondeactivate = function() {};
		*/
/*
		// init transmenu
        var aMenuHtml = [];
        for (var i = 0, menu = null; menu = TransMenu.registry[i]; i++) {
                aMenuHtml[i] = menu.toString();
        }
        $j('body').append(aMenuHtml.join(""));

		TransMenu.initialize();
	}
	
*/
	$('a.image-popup').lightBox();
	
	if($("#Banners .search").length>0) {

		$("#Banners .search input[name=s]").keyup(function(){
			var val = $("#Banners .search input[name=s]").val();
			var length = val.length;
			var pos = $("#Banners .search").offset();
			
			var lastChar = val.substr(length-1,1);
			
			if(lastChar==' ') {
				if($("#AutoComplete").length>0)
					$("#AutoComplete").remove();				
			} else if(val!= '') {
				var my_url = '/autocomplete.php?s='+val;
				
				search_complete = false;
				var response = $.ajax({
				   type: "POST",
				   url: my_url,
				   processData: false,
				   async: false,
				   success: function(msg) {
						search_complete = true;
					}

				 }).responseText;
				
				if($("#AutoComplete").length>0)
					$("#AutoComplete").remove();
				
				if($.browser.msie && $.browser.version<8) {
					pos.left -= 227;
				}
				
				$("body").append("<div id=\"AutoComplete\"></div>");
				$("#AutoComplete").css({"position":"absolute","top":pos.top+"px","left":pos.left+"px"});
				
				$("#AutoComplete").html(response);	
			}
		});
	}
});

function selectWords(text) {
	$("#Banners .search input[name=s]").focus();
	
	$("#Banners .search input[name=s]").val(text);
	
	$("#AutoComplete").remove();
}

function MenuSlide(id)
{
	if($("#Level0Sub-"+id).length)
	{
		if($(".Level0Sub:visible").length)
		{
			if($(".Level0Sub:visible").attr('id') == "Level0Sub-"+id)
				return true;
			else
				$(".Level0Sub:visible").slideUp(300, function(){
					$("#Level0Sub-"+id).slideDown(300, function(){
						document.location.href = $("#Level0Item-"+id).attr("href");
					})
				});
		}
		else
			$("#Level0Sub-"+id).slideDown(300, function(){document.location.href = $("#Level0Item-"+id).attr("href");});
	}
	else
	{
		if($(".Level0Sub:visible").length)
			$(".Level0Sub:visible").slideUp(300, function(){document.location.href = $("#Level0Item-"+id).attr("href");});
		else
			return true;
	}
	
	return false;
} 

function open_image_popup()
{
	var show = function(hash) {
		hash.w.fadeIn();
	};
	var hide = function(hash) {
		hash.o.remove();
		hash.w.fadeOut();
	};		
	
	//html = "test";
	
	//if (!$('#PopupImage').length)
	//	$('body').prepend('<div id="PopupImage" style="width:799px; height:450px; background-color:#E3001B; border: 1px solid white;" class="jqmWindow"></div>');
		
		
	//$("#PopupImage").html(html);
	$('body').prepend($('#PopupImage'));
	$("#PopupImage").jqm({modal: false,onShow: show, onHide: hide}).jqmShow();	
}

function close_image_popup()
{
	$("#PopupImage").jqmHide();	
}

function et_track_ajax_page_call(name, area) {
	var tc_et_key				= "F5E3Ws";
	var tc_et_pagename	= '';

	name = name.split("+").join(" ");
	var pagename = area.split("/").join(">")
	pagename += " > "+name;
	var et_areas = area;
	et_areas += "/"+name;
	
	et_eC_Wrapper(tc_et_key,decodeURIComponent(pagename),decodeURIComponent(et_areas));
}

