$(document).ready(function(){
	
	$("ul#nav").mlddm({
	});
	


	$('ul.accordion a.trigger').click(function(){
		if($(this).parent('li').is('.active'))
		{
			$(this).parent('li').removeClass('active');
			$(this).parent('li').find('div.content').animate({ height:'hide', opacity:'hide' });
			return false;
		}
		else
		{
			// works the about us accordion...
			$(this).parent('li').addClass('active').siblings().removeClass('active');
			$(this).parents('ul').find('div.content').animate({ height:'hide', opacity:'hide' });
			$(this).next('div.content').animate({ height:'show', opacity:'show' });
			window.location.hash = $(this).attr('href');
			return false;
		}
		
	});

	

	
	function log(s)
	{
		if (typeof console != "undefined" && typeof console.debug != "undefined") {
			console.log(s);
		}
	}
	
	/*if(window.location.hash){
		$('a[href="'+ window.location.hash +'"]').trigger('click');
		
		offset = $('a[href="'+ window.location.hash +'"]').offset();
		$('html, body').animate({scrollTop:offset.top}, 500);
	}*/
	
	if(location.hash)
	{
		$('a[href="'+ window.location.hash +'"]').trigger('click');
		id = location.hash.slice(1);
		element_to_show = $('#' + id);
		$('#'+id).next('div.content').slideToggle().siblings('div.content').slideUp(1000);
		
		offset = $('a[href="'+ window.location.hash +'"]').offset();
		$('html, body').animate({scrollTop:offset.top}, 500);
	}
	
	$('.locator, .search').focus(function(){
		$(this).addClass('active');
		if(this.value == this.defaultValue)
			this.value = '';
	}).bind('blur',function(){
		if(this.value == '')
		{
			$(this).removeClass('active');
			this.value = this.defaultValue;
		}
	});
	
	$('.collapsible h2').toggle(
		function(){
			if($(this).next('ul').is(':animated')){ return }
			$(this).find('.arrow').attr('src', path.template_path+'images/arrow-blue-down.gif');
			$(this).css('padding-bottom', 5);
			$(this).next('ul').slideDown();
		},
		function()
		{
			if($(this).next('ul').is(':animated')){ return }
			$(this).find('.arrow').attr('src', path.template_path+'images/arrow-blue.gif');
			$(this).animate({ 'padding-bottom':0 });
			$(this).next('ul').slideUp();
		}
	);
	
	// blocks cookie states
	$('.block').each(function(){
		state = $.cookies.get( $(this).attr('id') ); // block should be open
		if(state)
		{
			$(this).find('h2').css( 'padding-bottom', 5 );
			$(this).find('ul').css( 'display', 'block' );
			$(this).find('h2').find('.arrow').attr('src', path.template_path+'images/arrow-blue-down.gif');
		}
	});
	
	$('.block h2').click(function(){
	
		date = new Date();
		
		if($(this).next('ul').is(':visible')) // block is open
		{
			if($(this).next('ul').is(':animated')){ return }
			$.cookies.del( $(this).parent().attr('id') );
			$(this).find('.arrow').attr('src', path.template_path+'images/arrow-blue.gif');
			$(this).animate({ 'padding-bottom':0 });
			$(this).next('ul').slideUp();
		}else{
			if($(this).next('ul').is(':animated')){ return }
			$.cookies.set( $(this).parent().attr('id'), '1', {expiresAt:new Date(date.getFullYear()+2, date.getMonth(), date.getDate())} );
			$(this).find('.arrow').attr('src', path.template_path+'images/arrow-blue-down.gif');
			$(this).css('padding-bottom', 5);
			$(this).next('ul').slideDown();
		}
		
	});
	
	$('.hover').hover(
		function()
		{
			if($(this).find('a.link'))
			{
				$(this).find('a.link').stop(true, true).animate({ opacity:'show' });
			}
			$(this).css('background','#edf0f4');
		},
		function()
		{
			if($(this).find('a.link'))
			{
				$(this).find('a.link').stop(true, true).animate({ opacity:'hide' });
			}
			$(this).css('background','#ffffff');
		}
	);
	
	if($("#jflow_slider_control").length > 0){
		$("#jflow_slider_control").jFlow({
			slides: "#jflow_slider_slides",
			width: "650px",
			height: "170px",
			duration: 400
		});
	}
	
	
	// video popup settings...
	$('.video_popup').popupWindow({ 
		height:480, 
		width:853, 
		centerBrowser:1
	});
	
});
