$(document).ready(function(){
	// Options for SuperBGImage
		$.fn.superbgimage.options = {
			id: 'superbgimage', // id for the containter
			z_index: 0, // z-index for the container
			inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
			showimage: 1, // number of first image to display
			vertical_center: 0, // 0-align top, 1-center vertical
			transition: 1, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
			transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
			randomtransition: 0, // 0-none, 1-use random transition (0-7)
			showtitle: 1, // 0-none, 1-show title
			slideshow: 1, // 0-none, 1-autostart slideshow
			slide_interval: 5000, // interval for the slideshow
			randomimage: 0, // 0-none, 1-random image
			speed: 1000, // animation speed
			preload: 1, // 0-none, 1-preload images
			onShow: superbgimage_show, // function-callback show image
			onHide: superbgimage_hide // function-callback hide image
		};
	
		// initialize SuperBGImage
		$('#thumbs').superbgimage();

	
	$('#contact-form').jqTransform();

	$("button").click(function(){
		$(".formError").hide();

	});
	
	// toggle overlay
	$("#btn").click(function() {
		$("#request").lightbox_me();
		return false;
		  
	});	

	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(use_ajax)
			{
				$('#loading').css('visibility','visible');
				$.post('submit.php',$(this).serialize()+'&ajax=1',
				
					function(data){
						$("#contact-form").hide('slow').after('<h1>Thank you!</h1>');
						
						$('#loading').css('visibility','hidden');
					}
				
				);
			}
			e.preventDefault();
	})

});

// function callback on hiding image
function superbgimage_hide(img) {
	$('#showtitle').hide();
}

// function callback on showing image
// get title and display it
function superbgimage_show(img) {
	$('#superbgimage').css('background', 'none');
	$('#superbgimage').append($('#showtitle'));
	//$('#showtitle p.title').html($('#thumbs a' + "[rel='" + img + "']").attr('title'));
	$('#showtitle p.title').html("<img src='img/"+$('#thumbs a' + "[rel='" + img + "']").attr('title')+".png' alt='"+$('#thumbs a' + "[rel='" + img + "']").html()+"' title='"+$('#thumbs a' + "[rel='" + img + "']").html()+"'>");
	$('#showtitle').fadeIn(1000);
}

my_slideshowActive = false;

$(function() {

	// update superbgimage options
	function update_superbgOptions() {

		// speed
		var newspeed = 0;
		if (($("input[name='optspeed']").val() == 'slow') || ($("input[name='optspeed']").val() == 'normal') || ($("input[name='optspeed']").val() == 'fast')) {
			newspeed = $("input[name='optspeed']").val(); 
		} else {
			newspeed = parseInt($("input[name='optspeed']").val(), 10); 
			if (isNaN(newspeed)) {
				newspeed = 'slow';
				$("input[name='optspeed']").val('slow');
			}
		}
		
		// slidshow interval
		var newinterval = parseInt($("input[name='optinterval']").val(), 10); 
		if (isNaN(newinterval)) {
			newinterval = 5000;
			$("input[name='optinterval']").val(newinterval);
		}
		if ($.superbg_slideshowActive) { // restart slideshow
			clearInterval($.superbg_interval);
			return $('#thumbs').startSlideShow();
		}

		// transition out
		var newtransitionout = 0;
		if ($("input[name='opttransout']:checked").val() == 'on') {
			newtransitionout = 1;
		} else {
			newtransitionout = 0;
		}

		// random transition
		var newrandomtransition = 0;
		if ($("input[name='optrandomtrans']:checked").val() == 'on') {
			newrandomtransition = 1;
		} else {
			newrandomtransition = 0;
		}
		
		// random image
		var newrandomimage = 0;
		if ($("input[name='optrandom']:checked").val() == 'on') {
			newrandomimage = 1;
		} else {
			newrandomimage = 0;
		}

		// onclick-callback
		if ($("input[name='optclick']:checked").val() == 'on') {
			onclickfunc = superbgimage_click;
			$('#superbgimage img').each(function() { // add click-callback to all images
				$(this).unbind('click').click(function(){ superbgimage_click($(this).attr('rel')); });
			});	
		} else {
			onclickfunc = null;
			$('#superbgimage img').each(function() { // remove click-callback from all images
				$(this).unbind('click');
			});	
		}

		// onshow-callback
		if ($("input[name='optshow']:checked").val() == 'on') {
			onshowfunc = superbgimage_show;
			$('#showtitle').fadeIn('fast');
		} else {
			onshowfunc = null;
			$('#showtitle').hide();
		}
		
		// update options
		$.fn.superbgimage.options = { 
			transition: parseInt($("#transition").val(), 10),
			speed: 'slow',
			slide_interval: newinterval,
			transitionout: parseInt(newtransitionout, 10),
			randomtransition: parseInt(newrandomtransition, 10),
			randomimage: parseInt(newrandomimage, 10),
			onClick: onclickfunc,
			onShow: onshowfunc
		};
	
	}

	$('#showtitle').fadeTo('slow', 1.00);
	
});
