var d = document;
$(document).ready(function(){
	$.fn.tagName=function(){return this.get(0).tagName.toLowerCase();}
	function get_val(s){var a=window.location.search.substring(1).split('&');for(i=0;i<a.length;++i){b = a[i].split('=');if(b[0]==s){return b[1];}}return 0;}

	if($('#body div:first').attr('class') == "wrapper2") {
		if(!$.browser.msie){
			$('#menuH').css({opacity: 0.2});
		}
		Cufon.replace("#menuH",{hover: true, textTransform: 'uppercase'});
	} else {
		Cufon.replace("#menu ul li",{hover: true, textTransform: 'uppercase'});
	}

	$("#menu ul li a").hover(function(){ var id = $(this).attr('name'); $(id).animate({opacity: .5}, 1000); },function(){ var id = $(this).attr('name'); $(id).animate({opacity: 1}, 1000); });
	$('#home_img img').unbind('hover');
	$("#home_img img").hover(function(){
		$('a[name=#'+ $(this).attr('id') +']').addClass('active');
		Cufon.replace("#menu ul li",{hover: true, textTransform: 'uppercase'});
	},function(){
		$('a[name=#'+ $(this).attr('id') +']').removeClass('active');
		Cufon.replace("#menu ul li",{hover: true, textTransform: 'uppercase'});
	});

	$('#home_img img').hover(function(){ $(this).animate({opacity: .5}, 1000); }, function(){ $(this).animate({opacity: 1}, 1000);	});
//	$('#menuH').unbind('hover');
	if(!$.browser.msie){
		$('#menuH').hover(function(){
			$(this).animate({opacity: 1}, 750);
	//		$(this).animate({color: '#bebebe'}, 750,);
			Cufon.refresh("#menuH");
		}, function(){
			$(this).animate({opacity: .2}, 750);
			Cufon.refresh("#menuH");
		});
	}

	// left menu functions
	$('#menuH ul:not(#menuH ul:first)').parent().hide();

	$('#left a[id='+get_val('page_id')+'a'+get_val('record_id'));

	$('#left li a').click(function(){
		if($(this).parent().next().has('ul').length > 0){
			$(this).parent().next().toggle();
			return false;
		}else{
			return true;
		}
	});

	var page = '?page_id='+ get_val('page_id');
	if(get_val('record_id') != 0) {
		page += '&record_id='+ get_val('record_id');
	}
	$('#left a[href='+ page +']').addClass('active').parents().each(function(){
		if($(this).attr('id') == 'menuH'){ return false; } else { $(this).show(); }
	});

	$('#left a.active').parent().next().show();
	$('#menuH *').css({margin: "1px 0", padding: 0});

	$('input[type=text]').blur(function(){
		if($(this).val()==""){ $(this).val($(this).attr('alt')); }
	}).focus(function(){
		if($(this).val()==$(this).attr('alt')){ $(this).val(""); }
	});

	$('#menuH ul:first').show();

	$('#back_menu a').click(function(){
		if($(this).attr('class') != 'return_back') {
			$(this).parent().next().hide(500).next().show(500);
			$(this).addClass('return_back');
		} else {
			$(this).parent().next().show(500).next().hide(500);
			$(this).removeClass('return_back');
		}
		return false;
	});

	$('#hidden_menu').hide();


	$('.cbox').colorbox({maxWidth: "95%", maxHeight: '95%'});
});
