$(document).ready(function() {

	//dropdown menu
    $("div#menu ul li").hover(
		function() {
			$(this).find('ul:first', this).css('display', 'block');
			//$(this).find('ul:first', this).css('position', 'absolute');
		},
		function() {
			$(this).find('ul:first', this).css('display', 'none');
		}
	);

    //login
    $("#btnLogin").click(function(){
        $("#loginForm").submit();
    });

     //submit order form
    $("a#btnSend").click(function() {
        $('.obligatory').removeClass('error');
        error = false;
        $(".obligatory").each(function() {
            //console.log($(this).val());
            if ($(this).val() == '') {
                error = true;
            }
        });
        if (!isValidEmailAddress($('input.email').val())) {
            $('input.email').addClass('error');
            error = true;
        }
        if (error) {
            $('.obligatory:[value=""]').addClass('error');
        } else {
            $("form#contactForm").submit();
        }
        return false;
    });

    //events
    $("a.calLink").click(function() {
        $('div#currentEvent').hide();
        $('div#currentEvent').load(this.href);
        $('div#currentEvent').slideDown();
        return false;
    });

    //gallery slideshow
    $('#photos').galleryView({
        panel_width: 625,
        panel_height: 400,
        frame_width: 100,
        frame_height: 64,
        overlay_text_color: '#bdb9b9',
        caption_text_color: '#aba6a6',
        show_captions: true,
        transition_speed: 1200,
        transition_interval: 0,
        nav_theme: 'light',
        filmstrip_position: 'top',
        overlay_position: 'top'

    });

    //colorbox
    //Examples of how to assign the ColorBox event to elements
        $("a[rel='example1']").colorbox();
        $("a[rel='example2']").colorbox({transition:"fade"});
        $("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
        $("a[rel='example4']").colorbox({slideshow:true});
        $(".example5").colorbox();
        $(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
        $(".example7").colorbox({width:"80%", height:"80%", iframe:true});
        $(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
        $(".example9").colorbox({
            onOpen:function(){ alert('onOpen: colorbox is about to open'); },
            onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
            onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
            onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
            onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
        });

        //Example of preserving a JavaScript event for inline calls.
        $("#click").click(function(){
            $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
            return false;
        });

});



function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

