/**
 * This function makes sure that the left bar and the right bar allways end at the same spot.
 * It makes sure the layout is nice and beautiful.
 * 
 * @author Christoffer Lejdborg
 * @return void
 */
function equal_heights()
{
	var compensation = 17;
	var left_height = jQuery('#left-inner-content').height();
	var right_height = jQuery('#right-inner-content').height() + compensation; // Compensate for top corner of the right bar
	
	// If left bar is smaller, make it the same height as the compensated right bar
	if ( left_height < right_height ) jQuery('#left-inner-content').css('height', right_height+'px');
	
	// If right bar is smaller, make it the same height as the left bar minus <compensation> pixels
	if ( right_height < left_height ) jQuery('#right-inner-content').css('height', (left_height-compensation)+'px');
	
}

/**
 * Adds a placeholder text in an input field.
 * When selected the text disappears and when left the placeholder-text will appear if the input
 * field is empty.
 * 
 * @author Christoffer Lejdborg
 * @return void
 */
function add_placeholder()
{
	jQuery('.placeholder').each(function() {
		jQuery(this).val(jQuery(this).attr('siral:place-holder-text'));
		
		jQuery(this).click(function() {
			if ( jQuery(this).val() == jQuery(this).attr('siral:place-holder-text') ) jQuery(this).val('');
		});
		
		jQuery(this).blur(function() {
			if ( jQuery(this).val() == '' ) jQuery(this).val(jQuery(this).attr('siral:place-holder-text'));
		});
	});
}

//tab effects
var selectedTabId = null;
var TabbedContent = {	
	init: function() {	
		$('.tab_item').click(TabbedContent.selectTab);
		$('.tab_item_selected').click(TabbedContent.selectTab);
		
		selectedTabId = $('.tab_item_selected').attr('id'); 
		
		/*
				function() {
		
			var background = $(this).parent().find(".moving_bg");
			
			$(background).stop().animate({
				left: $(this).position()['left']
			}, {
				duration: 0
			});
			
			TabbedContent.slideContent($(this));
			
		});*/
	},
	
	selectTab: function(obj) {
		if (selectedTabId != $(this).attr('id'))
		{
			//console.log('clicking unselected: ' + $('#'+selectedTabId).attr('class'));
			$('#'+selectedTabId).removeClass('tab_item_selected');
			$('#'+selectedTabId).addClass('tab_item');
			selectedTabId = $(this).attr('id');
			$('#'+selectedTabId).addClass('tab_item_selected');
			$('#'+selectedTabId).removeClass('tab_item');
			
			TabbedContent.toggleContent($(this));
			equal_heights();
		}
	},
	
	toggleContent: function(obj) {
		$('.tabslider').children().hide();
		$('.tabslider').children().eq($(obj).index()).show();
	},
	
	/*slideContent: function(obj) {
		
		var margin = $(obj).parent().parent().find(".slide_content").width();
		margin = margin * ($(obj).prevAll().size() - 1);
		margin = margin * -1;
		
		$(obj).parent().parent().find(".tabslider").stop().animate({
			marginLeft: margin + "px"
		}, {
			duration: 0
		});
	}*/
}

//
// Document ready (1 sec delay)
//
function document_loaded()
{
	equal_heights();
	TabbedContent.init();	
}

//
// Document Ready
//
jQuery(document).ready(function() {
	equal_heights();
	add_placeholder();
	
	jQuery('#map_frame').css('-webkit-border-radius', '10px');
	jQuery('#map_frame').css('-moz-border-radius', '10px');
	
	setTimeout("document_loaded();",1000);
});
