var action_menu=true;
var action_search=true;
//var swf = getUrlVars()["swf"];

$().ready(function() {

	$('div#menu_tab').click(function() {
		if($('div#menu_content').width()==0){
			show_hide_menu();
		}
	});
	$('div#search_tab').click(function() {
		if($('div#search_content').width()==0){
			show_hide_search();
		}
	});
	$('body').mousedown(function(e) {
	
	var menu_area_obj=$('div#menu_tab_wrapper');
	var search_area_obj=$('div#search_tab_wrapper');
	var mouse_x=e.pageX;
	var mouse_y=e.pageY;
	
		if(check_area(menu_area_obj,mouse_x,mouse_y)==false && check_area(search_area_obj,mouse_x,mouse_y)==false){
			if($('div#menu_content').width()!=0){
				show_hide_menu();
			}
			if($('div#search_content').width()!=0){
				show_hide_search();
			}
		}
	});
	
	
	
});

function show_hide_menu(){
	if($('div#menu_content').width()==0){
		$('div#menu_tab_wrapper').css('width', '280px');
		$('#menu_content').animate({width: '245px'}, 300, function() {
		   $(this).css('display', 'block');
		});	
	}else{
		$('#menu_content').animate({width: '0px'}, 300, function() {
		   $(this).css('display', 'none');
		   $('div#menu_tab_wrapper').css('width', '30px');
		});	
	}
}

function show_hide_search(){
	if($('div#search_content').width()==0){
		$('div#search_tab_wrapper').css('width', '274px');
		$('div#search_content').animate({width: '244px'}, 300, function() {
		   $(this).css('display', 'block');
		});	
	}else{
		$('#search_content').animate({width: '0px'}, 300, function() {
		   $(this).css('display', 'none');
		   $('#search_tab_wrapper').css('width', '30px');
		});	
	}
}


function check_area(object,mouse_x,mouse_y){
	var position = object.position();
	var obj_x_1=position.left;
	var obj_x_2=obj_x_1+object.width();
	var obj_y_1=position.top;
	
	if(object.attr('id')=="search_tab_wrapper"){
		obj_y_1=obj_y_1-200;
	}

	var obj_y_2=obj_y_1+object.height()
	
	var x_between;
	var y_between;
	
	if(mouse_x>=obj_x_1 && mouse_x<=obj_x_2){
		x_between=true;
	}else{
		x_between=false;
	}
	
	if(mouse_y>=obj_y_1 && mouse_y<=obj_y_2){
		y_between=true;
	}else{
		y_between=false;
	}
	
	//alert(x_between+" "+y_between);
	//alert(obj_x_1+" "+mouse_x+" "+obj_x_2);
	//alert(+obj_y_1+" "+mouse_y+" "+obj_y_2);
	
	if(x_between==true && y_between==true){
		return true;
	}else{
		return false;
	}
}

function getUrlVars(){
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}

