/**
* Site specific JS
*
*
* @author   Amal Alsad (aa@langarth.com)
* @date     28 Oct 2011
*/

//extend jQuery.browser to add mobile detection
jQuery.extend(jQuery.browser, {
    safariMobile: navigator.userAgent.toLowerCase().match(/iP(hone|ad)/i)
});

mb = {
    resize: function (theWindow, theDocument) {
        if ( theWindow > theDocument ) {
            $('.flexible_wrapper').height(theWindow - 260 - 175 - 105); // footer:260 - header:175 - nav:105
        }
    }
};

$(document).ready(function () {

    $('#contact_form').submit(function (e) {
        var name  = $('#name').val();
        var email = $('#email').val();
        var phone = $('#phone').val();
        var valid = true;
        if (!name || name === 'required') {
            $('#name').val('required').css('color', 'red');
            valid = false;
        }
        if (!email || email === 'required') {
            $('#email').val('required').css('color', 'red');
            valid = false;
        }
        if (!phone || phone === 'required') {
            $('#phone').val('required').css('color', 'red');
            valid = false;
        }
        if (!valid) {
            e.preventDefault();
            return false;
        } else {
            return true;
        }
    });

    $('.left_menu').children('h1').click(function() { $(this).next('ul').toggle(); });  
    $('.item').mouseover(function() { $(this).children('.item_name').fadeIn(); });    
    $('.item').mouseleave(function() { $(this).children('.item_name').fadeOut(); });    
    /* Thumbnail images names should match the main image name replacing 465x600 with 172x210 for this to work */
    $('.dress_small').click(function () {
        if ( $('.dress_small').children().size() > 0 ) {
            var new_thumb = $('.dress_large').html().replace(/465/g, "172").replace(/600/g, "210");
            var new_main = $(this).html().replace(/172/g, "465").replace(/210/g, "600");
            $('.dress_large').html(new_main);
            $(this).html(new_thumb);
        }
    });
    
    $('#load_blog').load('library/blogspot.php');

    var i = 0;
    setInterval(function() {
        $('.quote_box').fadeOut(1000).delay(1000);$('.q'+i).fadeIn('slow').delay(3000);i++; if (i==3) { i = 0; }
    }, 5000);

});
