var main = {
	init: function() {
	
		this.menuInit();
		
		if($('#contact-form').length > 0) {
			this.formInit();
		}
		
		if($('#gallery').length > 0) {			
			this.galleryInit();
			$('#gallery a').fancybox();
			$('#gallery').jScrollHorizontalPane();
		}
	},
	
	menuInit: function() {
		$('#navigation ul li ul').hide();
		
		$('#navigation ul li:has(ul)').mouseover(
			function() {
				$(this).addClass('active');
				$(this).children('ul').show();
			}
		).mouseout(
			function() {
				$(this).removeClass('active');
				$(this).children('ul').hide();
			}
		);
	},
	
	formInit: function() {
		$('input[type="text"]').addClass("idleField");
    
		$('input[type="text"]').focus(function() {
       		$(this).removeClass("idleField").addClass("focusField");
    	
			if(this.value == this.defaultValue) { 
    	    	this.value = '';
			}
			
			if(this.value != this.defaultValue) {
	    		this.select();
	    	}
    	});
    	
		$('input[type="text"]').blur(function() {
    		$(this).removeClass("focusField").addClass("idleField");
    	
			if($.trim(this.value) == '') {
			   	this.value = (this.defaultValue ? this.defaultValue : '');
			}
    	});
	},
	
	galleryInit: function() {		
		var handler = $('#gallery li'),
			desc = $('h3'),
			info = $('h4');
				
		var actElem = 0,
			hovElem = actElem,
			inActiveOp = 0.2,
			visible = 3,
			itemWidth = 315;
			count = handler.length;
			
		$('#gallery ul').css('width', count * itemWidth);
			
		handler.eq(actElem).addClass('active');
		desc.text(handler.eq(actElem).find('a img').attr('alt'));
		info.text((actElem + 1)+' z '+count);
		
		handler.eq(actElem).siblings().css('opacity', inActiveOp);
		
		handler.mouseover(
			function() {
				$(this).siblings('.active').removeClass('active').css('opacity', inActiveOp);
				$(this).addClass('active').css('opacity', 1);
				
				hovElem = handler.index(this);
				
				desc.text(handler.eq(hovElem).find('a img').attr('alt'));
				info.text((hovElem + 1)+' z '+count);
			}
		);
	}
};

$(document).ready(function() {
	main.init();
});

