var SA = {
UI: {
	contact:$('#main_contact_form')
}
}

/*
swfobject.embedSWF("PgBiography.swf", "biography", "95", "109", "8.0.0", "expressInstall.swf");
swfobject.embedSWF("PgAwards.swf", "awards", "95", "109", "8.0.0", "expressInstall.swf");
swfobject.embedSWF("PgTestimonials.swf", "testimonials", "95", "109", "8.0.0", "expressInstall.swf");
swfobject.embedSWF("PgPortraits.swf", "portraits", "95", "109", "8.0.0", "expressInstall.swf");
swfobject.embedSWF("PgWeddings.swf", "weddings", "95", "109", "8.0.0", "expressInstall.swf");
swfobject.embedSWF("PgCorporate.swf", "corporate", "95", "109", "8.0.0", "expressInstall.swf");
swfobject.embedSWF("PgPortfolio.swf", "portfolio", "95", "109", "8.0.0", "expressInstall.swf");
*/

SA.UI.contact.submit(function() {
	var $t = $(this);
	var is_left_empty = false;
	$('#feedback').attr('class','').text('');
	
	$t.find('.mandatory').removeClass('left_empty').each(function(i,val) {
		$t = $(this);
		
		if((!$t.val()) || ($t.attr('name')==='tel' && $t.val().length<5)){
			$t.addClass('left_empty');
			is_left_empty = true;
		}
		
	})
	
	if (is_left_empty) {
	$('#feedback').addClass('error').text('Please fill in all required form fields (marked in red)');
	return false;
	}
	
	else {
	return true;
	}
})

$('#pregnancy_label').hide();
$('#pregnancy_box').mouseover(function() {
    $('#pregnancy_label').fadeIn(2000, function() {$(this).fadeOut(2000)});
});

$('#international_label').hide();
$('#international_box').mouseover(function() {
    $('#international_label').fadeIn(2000, function() {$(this).fadeOut(2000)});
});


//slideshow


function simple_slideshow(conf) {
    var c = conf || {},
        self = this,
        $ = jQuery,
        api = {},
        fade_in_speed = c.fade_in_speed || 750,
        fade_out_speed = c.fade_out_speed || 1000,
        showing_time = c.showing_time || 2500,
        dir = c.dir || "",
        imgs = c.imgs || [],
        selector = c.selector || "div:first",
        imn = [],
        ix = 0,
        kl = true,
        go = true,
        slideshow,
        slideshow_width,
        n = $("<img>"),
        timeout;

    function load_handler() {
        var $t = $(this),
            w = $t.width();
        $t.css("margin-left", (slideshow_width - w) / 2 + "px");
        show_new($t);
    }


    function image_node() {
        if (kl) {
            var node = n.clone().appendTo(slideshow);
            imn.push(node);
            node.load(load_handler);
            node.attr("src", dir + imgs[ix]);
        } else {
            show_new(imn[ix]);
        }
        return node;
    }


    function _after_fadeout() {
        ix++;
        timeout = setTimeout(init, showing_time);
    }


    function show_new(img) {
        hide_prev();
        img.fadeIn(fade_in_speed, _after_fadeout);
    }


    function hide_prev() {
        var prev_ix = ix - 1 >= 0 ? ix - 1 : imgs.length - 1;
        if (imn[prev_ix]) {
            imn[prev_ix].fadeOut(fade_out_speed);
        }
    }


    function init() {
        if (go) {
            if (!imgs[ix]) {
                ix = 0;
                kl = false;
            }
            image_node();
        }
    }

    slideshow = $(selector);
    slideshow_width = slideshow.width();
    if (imgs.length) {
        init();
    }
    
    //api
    return {
        remove:function() {
            clearTimeout(timeout);
            go = false;
            slideshow.empty();
        }
    };
    
};


VIEW = {

    books:function() {
        
        var current_slideshow;
        var shows_length = [50, 44, 30, 58]
        
        $('#slideshow_menu a').click(function(e) { 
            var $t = $(this);
            current_slideshow.remove();
            init_slideshow(+($t.attr('href').match(/\d/)[0]))
            return false;
        });
        
        function init_slideshow(index) {
            var img_list = [];
            for (var i=1;i<=shows_length[index-1];i++) {
                img_list.push('PG0'+(i<10?'0':'')+i+'.jpg');
            }
            
            current_slideshow = simple_slideshow({
                selector:'#show',
                dir:'wedding/books/'+index+'/',
                imgs:img_list
            });
        }
        
        init_slideshow(1);

    }

}

var current_view = $('body').attr('id');
if (current_view && current_view in VIEW) {
    VIEW[current_view]();
};
