$(document).ready(function(){
	
	// search_exhibitor();
	
	/* menu */
	$(".textboxsearch").keyup(function (e) {
		search_exhibitor($(this).val());
	});
	$(".textboxsearch").click(function (e) {
		$(".textboxsearch").val("");
		search_exhibitor();
	});
		
	$('#menu li').hover(function(){
		$(this).addClass('selected');
		$(this).find('ul:first').css({display:'block'});
	},function(){
		$(this).removeClass('selected');
		$(this).find('ul:first').css({display:'none'});
	})	
	
	/* cal */
	
	var date = readCookie('cal_date');
	var url = 'events/cal';
	if(date)
		url = date;
	$('#cal').load(site_url+url);
	
	/* outlook */
	
	$('.outlook .btn').click(function(){
		$(this).next().slideToggle();							  
		$(this).toggleClass('on');
		return false;
	});	

	$(".printme").click(function()
	{
		window.open(location.href+'#print');
	});

	// check if print hash is detected
	print_page();
	
	// search sponsors slideshow
	sponsors_slideshow();
	
});

/* sponsors slideshow */

	function sponsors_slideshow()
	{
		
	}

/* slideshows */

	function start_slideshow(id)
	{
		
		var slideshow_id = id;
		
		// active
		//$("#"+id+" ul li a:first").addClass('selected');
		
		var link_height = 0;
		
		// find highest link
		$("#"+id+" ul li a").each(function(){
			var this_height = $(this).height();
			if(this_height>link_height)
			{
				link_height = this_height;	
			}
		})
		
		$("#"+id+" ul li a").css({minHeight:link_height+'px'});
		
		// assign links
		$("#"+id+" ul li a").hover(function(){
			var id = $(this).attr('id');
			var key = id.replace('image','');
			var move = -key*608 + 'px';
			//alert(move);
			$("#"+slideshow_id+" .images").stop();
			$("#"+slideshow_id+" .images").animate({left:move},750);
			
			$("#"+slideshow_id+" ul li").removeClass('selected');
			$(this).parent().addClass('selected');

		},function(){})

	}

/* print controls */

	var hash = location.hash.replace('#','');
	print_css();
	
	function print_css()
	{
		if(hash=='print')
		{
			var print_url = assets_url+"assets/template/css/print.css";
			$("#stylesheet").attr("href",print_url);
		}	
	}
	
	function print_page()
	{
		if(hash=='print')
		{
			print();
		}
	}


function search_exhibitor(searchitem)
{
	var contents;
	var searchme = $(".textboxsearch").val().toLowerCase().replace(/^\s+|\s+$/g,"");
	
	if (searchme.length > 0) { 
		$(".sectiontab").parent().hide();
		$('.exhibitors .name').each(function(e) {
			var contents = $('a',this).html().toLowerCase().replace(/^\s+|\s+$/g,"");
			pos = contents.indexOf(searchme);


			if (pos>-1) { 
				$(this).parent().show();
				
			} else { 
				$(this).parent().hide();
			}
	
		})
	} else { 

		$(".sectiontab").parent().show();
		$('.exhibitors .name').parent().show();
	}

}


function show_category(s,id)
{
	var value = s.value;
	
	if(value=='ALL')
	{
		$('#list'+id+' tr').show();	
	}
	else
	{
		$('#list'+id+' tr').hide();	
		$('#list'+id+' tr.cat'+value).fadeIn();
	}
	
}

function goto_letter(s)
{
	location.href = '#'+s.value;
}

function change_month(year,month)
{
	$('#cal').load(site_url+'events/cal/'+year+'/'+month);
	createCookie('cal_date','events/cal/'+year+'/'+month,0);
	return false;
}

function send_to_friend(url,title,message)
{
	scrollTo(0,0);
	createCookie('url',url);
	createCookie('title',title);
	createCookie('message',message);
	//url = url.replace('/','~');
	open_win(site_url+'friend',600,400,'friend');
}

var _w;

function open_win(path,width,height,win)
{
	var w = window.screen.availWidth;
	var h = window.screen.availHeight;	
	
	var posL = (w-width)*.5;
	var posT = (h-height)*.5;
	
	if(_w && _w.open){
		_w.close();
	}	
	
	_w = window.open(path,win,'width='+width+',height='+height+',top='+posT+',left='+posL+',menubar=0,location=0,toolbar=0,personalbar=0,status=0,scrollbars=1,allowresize=1,dependent=1,resizable=1');	
}

function you_sure()
{

	var check = confirm('Are you sure?');
	if(check)
		{
			return true;
		}			
	else
		{
			return false;	
		}

}
