$(function(){
	var $menu_area = $('.menu_area');
	
	// Hide menu elements
	$menu_area.find('a.m').find('span').hide();
	
	// jScrollPane
	$('.scrollable').find('.content').jScrollPane({
		verticalDragMaxHeight: 12,
		showArrows: false
	});
	
	// Submenus
	$menu_area.find('a.hsub').each(function(){
		_hsub($(this));
	});
	$('.menu_area .content').mouseleave(function(){
		_hsub_to = setTimeout(function(){
			$('#submenus').slideUp('fast', function(){
				_hsub_open = false;
			});
		},25);
	});
	
	// Registration init
	$('.formReg').find('.text').each(function(){
		var $t = $(this);
		$t.attr('rel', $t.val());
		$t.focus(function(){
                    if($t.attr('type') != 'file') {
                        if($t.val() == $t.attr('rel')) $t.val(''); 
                    }
		}).blur(function(){
                    if($t.attr('type') != 'file') {
                        if($t.val() == '') $t.val($t.attr('alt')); 
                    }
                });
	});
	$('#formImage').customFileInput();	
	
	// Cycle gallery for default home page
	if($('#gallery').length > 0){
		$('#gallery').cycle({
			delay: 	0,
			sync: 	true,
			fx:     'fade', 
		    timeout: 5000, 
		    speed: 1000,
		    pause: 1
		});
	}
	
	// Cycle gallery for other all pages
	if($('.image_frame .content img').length > 2){
		$('.image_frame .content').cycle({
			delay: 	0,
			sync: 	true,
			fx:     'scrollHorz', 
		    timeout: 4000, 
		    speed: 1000,
		    pause: 1
		});
	}
});

var _hsub_open = false;
var _hsub_to = 0; // timeout
function _hsub($t){
	var id = $t.attr('id');
	var sub_id = id+'s';
	var $s = $('#'+sub_id);
	var $sm = $('#submenus');
	if($s.length == 1){
		$t.mouseenter(function(){
			$('.ms').hide();
			$s.show();
			if(_hsub_open == true){
				clearTimeout(_hsub_to);
				$sm.stop(true,true).slideDown('fast', function(){
					_hsub_open = true;
				});
			}else{
				$sm.slideDown('fast', function(){
					_hsub_open = true;
				});
			}
		}).click(function(){
			return false;
		});
	}
}
