
var vtsSite = {
		
	init: function() {
		vtsSite.setupLanguagesList();
		vtsSite.setupContactForm();
		vtsSite.setupHotelsList();
		vtsSite.setupExternalLinks();
		vtsSite.setupTourSearchForm();
		vtsSite.setupSearchHotelFormSubmit();
	},
	
	setupLanguagesList:function() {
		$('#languages_list li:first').addClass('first');
	},
	
	setupHelpMenusHide:function() {
		$('.sub').hover(
	            function(){$(this).addClass('hover');},
	            function(){$(this).removeClass('hover');}
		);;
	},

	setupHotelsList:function()
	{
		$('.hotels_list > li').hover(
			function() {$(this).addClass('hover');},
			function() {$(this).removeClass('hover');}
		);

		$('.hotels_list > li').live('click', function() {
			  window.location = $(this).find("a.title").attr("href");return false;
		});

		/*
		$('.hotels_list h4 a').live('click', function() {
			  window.location = $(this).attr('href'); return false;
		});
		*/
		$('.hotel_links_list a').live('click', function() {
			  window.location = $(this).attr('href');return false;
		});	
	},

	setupContactForm:function() {
		$('.required').append('<span class="required_char">*</span>');
	},

	setupSearchHotelFormSubmit:function() {
		
		$('#search_hotel_form').submit(function(){

			//var tourism = $('#form_hotel_tourism').val();
			var destination = $('#destination').val();
			var category = $('#category').val();
			var keyword = $('#hotel').val();

			var url="/bg/search/hotel";

			//if (tourism.length) 		url += "/tourism/" + tourism;
			if (destination.length)		url += "/destination/" + destination;
			if (category.length) 		url += "/category/" + category;
			if (keyword.length) 		url += "/keyword/" + keyword;
			
			window.location = url;
			return false;
		});
	},
	
	setupTourSearchForm:function() {
		$('#form_tour_search').submit(function(){
			
			var theme = $('#form_tour_theme').val();
			var destination = $('#form_tour_destination').val();
			var days = $('#form_tour_days').val();
			var month = $('#form_tour_month').val();
			var transport = $('#form_tour_transport').val();
			var price = $('#form_tour_price').val();

			var url="/bg/tour/search";
			
			if (theme.length) 		url += "/type/" + theme;
			if (destination.length)		url += "/dest/" + destination;
			if (days.length) 		url += "/length/" + days;
			if (month.length) 		url += "/month/" + month;
			if (transport.length)		url += "/transport/" + transport;
			if (price.length) 		url += "/price/" + price;
			
			window.location = url; 
			return false;
		});
	},	

	setupExternalLinks : function() {
		$('a[rel*=external]').click( function() {
			window.open(this.href);
			return false;
		});
	}
};		


$(document).ready(function() {
	
	vtsSite.init();

    function megaHoverOver() {
    	$(this).addClass('active');
		$(this).find(".sub").stop().fadeTo(70, 1).show();
		
		//Calculate width of all ul's
		(function($) {
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {
					rowWidth += $(this).width();
				});
                //rowWidth += 20;
			};
		})(jQuery);

		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;
			//Calculate each row
			$(this).find(".row").each(function() {
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
            //biggestRow += 20;
			//Set width
			//$(this).find(".sub").css({'width': biggestRow});
			//$(this).find(".row:last").css({'margin':'10px'});

		} else { //If row does not exist...

			$(this).calcSubWidth();
            rowWidth = 1 + rowWidth;
			$(this).find(".sub").css({'width': rowWidth});

		}
	}


	function megaHoverOut()
	{
		$(this).removeClass('active');
		$(this).find(".sub").stop().fadeTo('fast', 0, function() {
			$(this).hide();
		});
	}


	var config = {
		 sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)
		 interval: 30, // number = milliseconds for onMouseOver polling interval
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
		 timeout: 50, // number = milliseconds delay before onMouseOut
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};

	$("#primary_nav li.level1 .sub").css({'opacity':'0'});
	$("#primary_nav li.level1").hoverIntent(config);


	/*
	$('#home_destinations_wrapper ul').columnizeList({
		cols: 2,
		constrainWidth: 10
	});
	*/

	jQuery('.placeholder').each(function(i) {

        var item = jQuery(this);
        var text = item.attr('rel');
        var form = item.parents('form:first');

        if (item.val() === '')
        {
            item.val(text);
            item.css('color', '#888');
        }

        item.bind('focus.placeholder', function(event) {
            if (item.val() === text)
                item.val('');
            item.css('color', '');
        });

        item.bind('blur.placeholder', function(event) {
            if (item.val() === '')
            {
                item.val(text);
                item.css('color', '#888');
            }
        });

        form.bind("submit.placeholder", function(event) {
          if (item.val() === text)
            item.val("");
        });

    });

/*
	$("#feedback_button").fancybox({
		'padding'			: 0,
		'width'				: 680,
		'height'			: 480,
		'autoScale'     	: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'titleShow'			: false
	});
	*/
});



