$(document).ready(function(){
  
   $.fn.cycle.transitions.fadeOutWaitFadeIn = function($cont, $slides, opts) {
	opts.fxFn = function(curr, next, opts, after) {
	    $(curr).fadeOut(opts.fadeSpeed, function() {
		$(next).delay(opts.delayBetweenFades).fadeIn(opts.fadeSpeed, function() {
		    after();              
		});
	    });
	};
    };

    $(".quotes").cycle({
        fx: 'fadeOutWaitFadeIn',
        fadeSpeed:250,
        delayBetweenFades:50,
        timeout:7478
    });
    
    $(".news").cycle({
        fx: 'fadeOutWaitFadeIn',
        fadeSpeed:250,
        delayBetweenFades:50,
        timeout:5844
    });
    
    $("#dvd").click(function(hash){
	hash.preventDefault();
	$(".prospectus").show();
	$(".main").hide();
    });
    
    $("#nextStep").click(function(hash){
	hash.preventDefault();
	$(".panels").animate({"left":"-390px"},250)
    });
    
    $(".submit").click(function(hash){
	hash.preventDefault();
	
	var proceed = false;
	
	title	    =   $("select[name=title]").val();
	name	    =   $("input[name=name]").val();
	surname	    =   $("input[name=surname]").val();
	address	    =   $("input[name=address]").val();
	city	    =   $("input[name=city]").val();
	region	    =   $("input[name=region]").val();
	postcode    =   $("input[name=postcode]").val();
	country	    =   $("select[name=country]").val();
	childCount  =   $("select[name=childCount]").val();
	moreInfo    =   $("select[name=moreInfo]").val();
	dvdFormat   =   $("select[name=dvdFormat]").val();
	otherReq    =   $("textarea[name=otherReq]").val();
	
	$("input").each(function(){
	    if($(this).val()==''){
		$(this).css({"background-position":"-10px -48px"});
		proceed = false;
	    }else{
		proceed = true;
	    }
	})
	
	$(".large select").each(function(){
	    if($(this).val()==''){
		$(this).next(".sbHolder").css({"background-position":"-280px -48px"});
		proceed = false;
	    }else{
		proceed = true;
	    }
	})
	
	$(".small select").each(function(){
	    if($(this).val()==''){
		$(this).next(".sbHolder").css({"background-position":"-911px -48px"});
		proceed = false;
	    }else{
		proceed = true;
	    }
	})
	

	if(proceed == false){
	    $(".panels").animate({"left":"0"},250)
	    // do somthing to sort errors
	}else{
	    alert(title + name + surname + address + city + region + postcode + country + childCount + moreInfo + dvdFormat + otherReq);
	    $.post("form.php", { 
		name	:   name, 
		surname	:   surname,
		address	:   address,
		city	:   city,
		region	:   region,
		postcode	:   postcode,
		country	:   country,
		childCount	:   childCount,
		moreInfo	:   moreInfo,
		dvdFormat	:   dvdFormat,
		otherReq	:   otherReq	    
	    },function(data) {
		//alert(data);
		$(".panels").animate({"left":"-780px"},250)
	    });
	}
    });
    
    $("#backStep").click(function(hash){
	hash.preventDefault();
	$(".panels").animate({left:0},250)
    });
    
    $(".close").click(function(){
	$(".prospectus").hide();
	$(".main").show();
    });
    
    $(".main .scroll").cycle({
	fx:      'scrollRight',
	speed:	250,
	next:   '.arrow a',
	timeout:  0
    });
    
    $(".video").toggle(function(){
	$("p.img").hide();
	$("#film").show();
    },function(){
	$("p.img").show();
	$("#film").hide();
    });
    
/*end DOM ready*/
});
