$(function() {
	if ($('#msg').html()) {
		$.prompt($('#msg').html());
	}
	
	$('.force-empty').val('');
	
	setTimeout(function(){
		window.scrollTo(0, 1);
	}, 0);
	
	if (jQuery().cycle) {
		$('#slideshow .slides').cycle({
			before:  function(prev,curr,z) {
				var ele = $('#slideshow .nav img').eq( $(prev).find('img').attr('title').split('-')[1] );			
				ele.attr('src', ele.attr('src').replace('active','inactive'));
				
				ele = $('#slideshow .nav img').eq( $(curr).find('img').attr('title').split('-')[1] );			
				ele.attr('src', ele.attr('src').replace('inactive','active'));
			},
			speed : 3000
		});
		$('#slideshow .nav img').each(function() {
			$(this).click(function() {
				$('#slideshow .slides').cycle( parseInt($(this).attr('title').split('-')[1]) )		   
			});
		});
	}
	
	$('#menu-nav li.parent > a').each(function(i) {
		var ul = $(this).parent().find('ul');
		var h = $(ul).height();
		$(ul).addClass('closed is_closed');
		
		$(this).bind('click', function(e) {	
			
			if ($(ul).length > 0) {
				e.preventDefault();
				
				if ($(ul).hasClass('is_closed')) {
					$(ul).removeClass('is_closed');
					
					if (ul.length > 0)
						$(this).find('img.arrow').css({'-webkit-transform': 'rotate(0deg)'});
					
					$(ul).css({height: h});
					menu_nav_box_height += h;
					$('#menu-nav').css({height: menu_nav_box_height});
				} else {
					$(ul).addClass('is_closed');
					$(ul).css({height: 0});
					
					if (ul.length > 0)
						$(this).find('img.arrow').css({'-webkit-transform': 'rotate(90deg)'});
					
					menu_nav_box_height -= h;
					$('#menu-nav').css({height: menu_nav_box_height});
				}	
			}
		});
	});	
	

	
	$('#header-menu a').click(function(e) {
		e.preventDefault();
		
		if ($('#menu-nav').hasClass('closed')) {
			if (jQuery().cycle) {
				$('#slideshow .slides').cycle('resume');
			}
			$('#menu-nav').removeClass('closed');
			$('#menu-nav').css({height: menu_nav_box_height});
			$(this).addClass('active');			
			$(this).find('img').attr('src', $(this).find('img').attr('src').replace('off','on'));	
		} else {
			if (jQuery().cycle) {
				$('#slideshow .slides').cycle('pause');
			}
			$('#menu-nav').addClass('closed');
			
			$('#menu-nav').css({height: 0});
			$(this).removeClass('active');	
			$(this).find('img').attr('src', $(this).find('img').attr('src').replace('on','off'));	
			
		}
	});
	
	var menu_nav_box_height = $('#menu-nav').height() + 22;
	$('#menu-nav').addClass('closed');
	
	//var accordion_group = Array();
	
	$('.accordion .group').each(function(i) {									  
		var header = $(this).find('.header');
		var box = $(this).find('.content');
		//accordion_group[i] = $(box).height();
		$(box).css('display','none');
		
		$(header).click(function() {
			$(box).slideToggle();			 
		});
	});
	
});


