//Aids work around for JQtransform JQUERY onchange
function perform_option_free_text(selectid,optiontext){
	if(optiontext == "Others"){
		switch(selectid){
		case "inqtyp_id":
			$('#inq_type_free_span').show("slow");
		break;		
		default:
		break;
		}
	}else{
		$('#inq_type_free_span').hide();		
	}
}

$(document).ready(function(){
    //SexyLightbox.initialize({color:'white'});
    //20100503:boneysze:removed ajax for calendar
	//$("#objectID").load("calendar/calendar.php");
	SexyLightbox.initialize();	
	$('#contact-form').jqTransform();
	$('#inq_type_free_span').hide();	
	$("button").click(function(){
		$(".formError").hide();
	});
	var use_ajax=true;
	$.validationEngine.settings={};

	$("#contact-form").validationEngine({
		inlineValidation: false,
		promptPosition: "centerRight",
		success :  function(){use_ajax=true},
		failure : function(){use_ajax=false;}
	 })
	$("#contact-form").submit(function(e){
			if(!$('#inqtyp_id').val().length){
				$.validationEngine.buildPrompt(".jqTransformSelectWrapper","* This field is required","error")
				return false;
			}			
			if($('#inq_type_free').val() == "" && $('#inqtyp_id').val() == 9){
				$.validationEngine.buildPrompt(".jqTransformSelectWrapper","* This field is required","error")
				return false;
			}			
			if(use_ajax)
			{
				$('#loading').css('visibility','visible');
				$.post('inquiries/submit.php',$(this).serialize()+'&ajax=1',				
					function(data){
						if(parseInt(data)==-1){
							$.validationEngine.buildPrompt("#captcha","* Wrong verification number!","error");
						}else{
							$("#contact-form").hide('slow').after('Thank you for taking the time to fill the inquiry form.');
						}
						$('#loading').css('visibility','hidden');
					}
				
				);
			}
			e.preventDefault();
	})
	$().piroBox({
			my_speed: 600, //animation speed
			bg_alpha: 0.5, //background opacity
			radius: 4, //caption rounded corner
			scrollImage : true, // true == image follows the page, false == image remains in the same open position
			pirobox_next : 'piro_next', // Nav buttons -> piro_next == inside piroBox , piro_next_out == outside piroBox
			pirobox_prev : 'piro_prev',// Nav buttons -> piro_prev == inside piroBox , piro_prev_out == outside piroBox
			close_all : '.piro_close',// add class .piro_overlay(with comma)if you want overlay click close piroBox
			slideShow : 'slideshow', // just delete slideshow between '' if you don't want it.
			slideSpeed : 4 //slideshow duration in seconds(3 to 6 Recommended)
	});
	
	
	//LOADING POPUP
	//Click the button event!
	$("#directions").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	$("#ebam").click(function(){
		//centering with css
		centerPopup("Ebam");
		//load popup
		loadPopup("Ebam");
	});
	$("#announcement").click(function(){
		//centering with css
		centerPopup("Announcement");
		//load popup
		loadPopup("Announcement");
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#popupEbamClose").click(function(){
		disablePopup("Ebam");
	});
	$("#popupAnnouncementClose").click(function(){
		disablePopup("Announcement");
	});
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup("Ebam");
		disablePopup("Announcement");
		popupStatus=1;
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup("Ebam");
			disablePopup("Announcement");
			popupStatus=1;
			disablePopup();
		}
	});
});
