jQuery(document).ready(function($){
	
	//calculte_nav_offset(); // NOT used - fixed width for top menu //call this before lavaLamp
	
	buttonOverState('.applyNowCelta .divSubmit .inputSubmit', 'inputSubmitOver');
	buttonOverState('.applyNowDelta .divSubmit .inputSubmit', 'inputSubmitOver');
	buttonOverState('.applyNowTeacherDev .divSubmit .inputSubmit', 'inputSubmitOver');
	
	//console.log( $('.leftMenu_2 li').text() );
	$('.leftMenu_2 li > a:not(".selected")').hover(function(){
		$(this).addClass('selected');
	},
	function(){
		$(this).removeClass('selected');
	});
	
	
	// Equalize ".listBox_1"
	$('.listBox_1 .listRow').each(function(){
		// itemTitle
		var highest = 0;
		$('.listItem .itemTitle', this).each(function() {
			//alert( $(this).height() );
			var elem_height = $(this).height();
			if(elem_height>highest) {
				highest = elem_height;
			}
		});
		$('.listItem .itemTitle', this).height(highest); // use min-height except ie6
		
		// UL LI list container
		var highest = 0;
		$('.listLinks', this).each(function() {
			//alert( $(this).height() );
			var elem_height = $(this).height();
			if(elem_height>highest) {
				highest = elem_height;
			}
		});
		$('.listLinks', this).height(highest); // use min-height except ie6
	});
	// END Equalize ".listBox_1"
	
	
	//button hover (contact form)
	$('.buttonDark,.buttonLight').hover(function(){
		$(this).addClass('buttonOver');
	},function(){
		$(this).removeClass('buttonOver');
	});
	
	// Set captcha by JS
	$("input[name='cap_prot']").val('1');
	
	$('#faqList').accordion({header: '.head',alwaysOpen: false, autoheight: false ,active: false});
	
	$('.newsletterForm .DivInputText .inputText').each(function(){
		$(this).watermark( $(this).val() );
	});
	
	
	$('#styledSelect_180_18').styledSelect({
		"selectClass": "styledSelect_180_18"
		,"zIndexApply": true
		,"zIndexStart": 315
	});
	
	$('#styled_salutation').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 314
	});
	$('#styled_education_school_1_date_from').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 313
	});
	$('#styled_education_school_1_date_to').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 312
	});
	$('#styled_education_school_2_date_from').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 311
	});
	$('#styled_education_school_2_date_to').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 310
	});
	$('#styled_education_university_1_date_from').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 309
	});
	$('#styled_education_university_1_date_to').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 308
	});
	$('#styled_education_elt_1_date_from').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 307
	});
	$('#styled_education_elt_1_date_to').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 306
	});
	$('#styled_education_language_1_level').styledSelect({
		"selectClass": "styledSelect_167_21"
		,"zIndexApply": true
		,"zIndexStart": 305
	});
	$('#styled_education_language_2_level').styledSelect({
		"selectClass": "styledSelect_167_21"
		,"zIndexApply": true
		,"zIndexStart": 304
	});
	$('#styled_education_language_3_level').styledSelect({
		"selectClass": "styledSelect_167_21"
		,"zIndexApply": true
		,"zIndexStart": 303
	});

	$('#styled_elt_experience_1_date').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 302
	});
	$('#styled_elt_experience_2_date').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 301
	});
	$('#styled_elt_experience_3_date').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 300
	});
	$('#styled_elt_experience_4_date').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 299
	});
	$('#styled_elt_experience_5_date').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 298
	});
	$('#styled_elt_experience_6_date').styledSelect({
		"selectClass": "styledSelect_67_21"
		,"zIndexApply": true
		,"zIndexStart": 297
	});
	
	$('#jcarousel-accomodation').jcarousel({
		//auto: 4, // seconds
		scroll: 4,
		//wrap: 'last',
		initCallback: carousel_accomodation_initCallback
	});
	
	$('#jcarousel-accomodation a').lightBox(); //a[rel*=lightbox]
	
	checkWindowHash(); // used on anchors on Celta/Delta sections!
	
	equalize_row_table_cells('.tableContentOneRow table, td .cc_middle', 'td .cc_middle');
	equalize_row_table_cells_vertical_align_top('.tableContentOneRowVerticalAlignTop table, td .cc_middle', 'td .cc_middle');
	
	$('#datepicker_birth_date').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_1_date_from').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_1_date_to').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_2_date_from').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_2_date_to').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_3_date_from').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_3_date_to').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_4_date_from').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	$('#datepicker_work_experience_4_date_to').datepicker({
		changeMonth: true,
		changeYear: true,
		yearRange: '1940:2010',
		dateFormat: 'dd/mm/yy',
		inline: false,
		//showOn: 'button',
		showOn: 'both',
		buttonImage: '/images/common/icons/calendar_1.gif',
		buttonImageOnly: true // to show without a button tag
	});
	
});

function calculte_nav_offset()
{
	var max_width = $('#contentLight .wrapper').width();
	var nav_width = $('#nav').width();
	//alert(max_width);
	//alert(nav_width);
	if(max_width>nav_width) {
		var margin_offset = (max_width-nav_width) / 2;
		if( margin_offset >0 ) {
			margin_offset = Math.floor(margin_offset);
			//alert(margin_offset);
			//$('#nav').width(nav_width).css('margin-left', margin_offset + 8); // we have 15px left offset of the background image in header. Use half of this width
			//$('#nav').css('margin-left', margin_offset + 8);
			$('#nav').css('margin-left', margin_offset); // no correction needed
		}
	}
}


/* OnOver - add class for IE - Should be used on elements different from Links */
function buttonOverState(selector, className)
{
	/* Hover over the login button */
	$(selector).hover(function(){
		$(this).addClass(className);
	},
	function(){
		$(this).removeClass(className);
	});
}

function checkWindowHash()
{
	if (location.href.indexOf("#") != -1) {
		// Your code in here accessing the string like this
		// location.href.substr(location.href.indexOf("#"))
		var url_hash = location.href.substr(location.href.indexOf("#"));
		if( url_hash.substr(1,2) == 'p-' ) {
			//alert(url_hash);
			$(url_hash).css('background-color', '#ffffff').css('padding', '7px');
		}
	}	
}

function carousel_accomodation_initCallback(carousel)
{
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
	    carousel.startAuto(0);
	});
	
	carousel.buttonPrev.bind('click', function() {
	    carousel.startAuto(0);
	});
	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
	    carousel.stopAuto();
	}, function() {
	    carousel.startAuto();
	});
}

function equalize_row_titles(selector_row, selector_title)
{
	$(selector_row).each(function(){
		// itemTitle
		var highest = 0;
		$(selector_title, this).each(function() {
			//alert( $(this).height() );
			var elem_height = $(this).height();
			if(elem_height>highest) {
				highest = elem_height;
			}
		});
		$(selector_title, this).height(highest); // use min-height except ie6
	});
}

function equalize_row_table_cells(selector_row, selector_title)
{
	$(selector_row).each(function(){
		// itemTitle
		var highest = 0;
		$(selector_title, this).each(function() {
			//alert( $(this).height() );
			var elem_height = $(this).height();
			if(elem_height>highest) {
				highest = elem_height;
			}
		});
		
		// FIX - when the highest = 29, 1 px difference ! Now all element will set height!
			//alert(highest); // 29
			//alert(elem_height); //14
			//alert(temp_differ); //15
			//alert(temp_differ_half); //7
		if(Math.floor(highest/2)!=Math.round(highest/2)) {
			highest = highest + 1; // convert to even
		}
		// END FIX
		
		count = 0;
		$(selector_title, this).each(function() {
			count++;
			
			//alert( $(this).height() );
			var elem_height = $(this).height();
			
			if(elem_height<highest) {
				temp_differ = Math.floor(highest-elem_height); // Math.floor(x) - rounded downwards to the nearest integer
				temp_differ_half = Math.floor(temp_differ/2);
				/*
				if(count==4) {
					alert(highest); // 29
					alert(elem_height); //14
					alert(temp_differ); //15
					alert(temp_differ_half); //7
				}
				*/
				$(this).height(highest-temp_differ_half).css('padding-top', temp_differ_half).css( 'padding-bottom', 0);
				//$(this).height(highest); // vertical-align: middle should be preserved!
			}
		});
	});
}


function equalize_row_table_cells_vertical_align_top(selector_row, selector_title)
{
	$(selector_row).each(function(){
		// itemTitle
		var highest = 0;
		$(selector_title, this).each(function() {
			//alert( $(this).height() );
			var elem_height = $(this).height();
			if(elem_height>highest) {
				highest = elem_height;
			}
		});
		
		// FIX - when the highest = 29, 1 px difference ! Now all element will set height!
			//alert(highest); // 29
			//alert(elem_height); //14
			//alert(temp_differ); //15
			//alert(temp_differ_half); //7
		if(Math.floor(highest/2)!=Math.round(highest/2)) {
			highest = highest + 1; // convert to even
		}
		// END FIX
		
		count = 0;
		$(selector_title, this).each(function() {
			count++;
			
			//alert( $(this).height() );
			var elem_height = $(this).height();
			
			if(elem_height<highest) {
				temp_differ = Math.floor(highest-elem_height); // Math.floor(x) - rounded downwards to the nearest integer
				temp_differ_half = Math.floor(temp_differ/2);
				/*
				if(count==4) {
					alert(highest); // 29
					alert(elem_height); //14
					alert(temp_differ); //15
					alert(temp_differ_half); //7
				}
				*/
				//
				
				if(count==5) {
					$(this).height(highest-temp_differ_half).css('padding-top', temp_differ_half).css( 'padding-bottom', 0);
				}
				else {
					$(this).height(highest); // vertical-align: middle should be preserved!?
				}
				
			}
		});
	});
}



