if($('#googlemap').length) {
    google.load("maps", "2.x", {"callback" : mapsLoaded});
}

$(window).load(
    function() {
        var flashvars = {};
        var params = {};
        params.wmode = "transparent";
        var attributes = {};
        attributes.id = "event-equipment-logo";
        swfobject.embedSWF("swf/ee_logo.swf", "ee-logo", "960", "250", "9.0.0", false, flashvars, params, attributes);
    }
);


$(document).ready(function() {
    var flashvars = {};
    var params = {};
    params.wmode = "transparent";
    var attributes = {};
    attributes.id = "banner";
    swfobject.embedSWF("swf/new_banner.swf", "flash-anim", "960", "250", "8.0.0", false, flashvars, params, attributes);

    var flashvars = {};
    var params = {};
    params.wmode = "transparent";
    var attributes = {};
    attributes.id = "the-showreel";
    swfobject.embedSWF("swf/showreel.swf", "showreel", "296", "224", "9.0.0", false, flashvars, params, attributes);

    // quote form checking
    if($('div.formbuilderform').length) {

        if($('div.delivery-options input:checked').val() == "1") {
            $('.ee-deliver').hide();
            $('.client-pickup-dates').show();
            $('.ee-delivery-dates').hide();
            $('.ee-delivery-dates input').val();
        } else if ($('div.delivery-options input:checked').val() == "2") {
            $('.ee-deliver').show();
            $('.client-pickup-dates').hide();
            $('.ee-delivery-dates').show();
            if ($('#m3_37').is(':checked')) {
                $('.ee-deliver-details').hide();
            } else {
                $('.ee-deliver-details').show();
            }
        } else {
            $('.ee-deliver').hide();
            $('.client-pickup-dates').hide();
            $('.ee-delivery-dates').hide();
        }

        $('div.delivery-options input').click(function() {
            if ($(this).val() == "1") {
                $('.ee-deliver').hide();
                $('.client-pickup-dates').show();
                $('.ee-delivery-dates').hide();
                if ($('#m3_37').is(':checked')) {
                    $('.ee-deliver-details').hide();
                } else {
                    $('.ee-deliver-details').show();
                }
            } else if ($(this).val() == "2") {
                $('.ee-deliver').show();
                $('.client-pickup-dates').hide();
                $('.ee-delivery-dates').show();

                if ($('#m3_37').is(':checked')) {
                    $('.ee-deliver-details').hide();
                } else {
                    $('.ee-deliver-details').show();
                }
            } else {
                if ($('#m3_37').is(':checked')) {
                    $('.ee-deliver-details').hide();
                } else {
                    $('.ee-deliver-details').show();
                }
            }
        });

        $('#m3_37').click(function() {
            if ($('#m3_37').is(':checked')) {
                $('.ee-deliver-details').hide();
            } else {
                $('.ee-deliver-details').show();
            }
        });
        $('#m3fbrp__51').DatePicker({
	        format:'d/m/Y',
	        date: $('#m3fbrp__51').val(),
	        current: $('#m3fbrp__51').val(),
        	starts: 1,
	        position: 'bottom',
	        onBeforeShow: function(){
		        $('#m3fbrp__51').DatePickerSetDate($('#m3fbrp__51').val(), true);
	        },
	        onChange: function(formated, dates){
		        $('#m3fbrp__51').val(formated);
                $('.datepicker').hide();
	        }
        });
        $('#m3fbrp__53').DatePicker({
	        format:'d/m/Y',
	        date: $('#m3fbrp__53').val(),
	        current: $('#m3fbrp__53').val(),
        	starts: 1,
	        position: 'bottom',
	        onBeforeShow: function(){
		        $('#m3fbrp__53').DatePickerSetDate($('#m3fbrp__53').val(), true);
	        },
	        onChange: function(formated, dates){
		        $('#m3fbrp__53').val(formated);
                $('.datepicker').hide();
	        }
        });
        $('#m3fbrp__57').DatePicker({
	        format:'d/m/Y',
	        date: $('#m3fbrp__57').val(),
	        current: $('#m3fbrp__57').val(),
        	starts: 1,
	        position: 'bottom',
	        onBeforeShow: function(){
		        $('#m3fbrp__57').DatePickerSetDate($('#m3fbrp__57').val(), true);
	        },
	        onChange: function(formated, dates){
		        $('#m3fbrp__57').val(formated);
                $('.datepicker').hide();
	        }
        });
        $('#m3fbrp__59').DatePicker({
	        format:'d/m/Y',
	        date: $('#m3fbrp__59').val(),
	        current: $('#m3fbrp__59').val(),
        	starts: 1,
	        position: 'bottom',
	        onBeforeShow: function(){
		        $('#m3fbrp__59').DatePickerSetDate($('#m3fbrp__59').val(), true);
	        },
	        onChange: function(formated, dates){
		        $('#m3fbrp__59').val(formated);
                $('.datepicker').hide();
	        }
        });
    };

    $('a.boxen').click(function(e) {
        $.Boxen.open(this, {
            showTitleBar: true,
            showCloseButton: true,
            title: null,
            titleAttribute: 'title',
            closeButtonText: null,
            width: 620,
            height: 500,
            url: null,
            urlAttribute: 'href',
            overlayOpacity: 0.8,
            modal: false
        });
        return false;
    });

    $('#launch-street-view').click(function() {
        $.Boxen.open(this, {
            showTitleBar: true,
            showCloseButton: true,
            title: null,
            titleAttribute: 'title',
            closeButtonText: null,
            width: 645,
            height: 507,
            url: null,
            urlAttribute: 'href',
            overlayOpacity: 0.8,
            modal: false
        });
        return false;
    });

    /* Accordion for FAQ */
    if($('ul.questions').length) {
        //$('ul.questions li > .accContent').css('visibility','visible');
        //$('ul.questions li > .accContent').css('height','auto');

        $('ul.questions span').click(function() {
            $(this).parent().siblings('li').removeClass('active');
            $(this).next('div').slideToggle('fast').parent().siblings('li.accPart').children('div').slideUp('fast');
            if($(this).parent().hasClass('active')) {
                $(this).parent().removeClass('active');
            } else {
                $(this).parent().addClass('active');
            }
        });

        $('.questions span').hover(function() {
            $(this).css('color','#FF0000');
        },function() {
            $(this).css('color','#FFFFFF');
        });
    }
    /* end accordion for FAQ */
});

function mapsLoaded() {
    if($('#googlemap').length) {
        var map = new GMap2(document.getElementById("googlemap"));
        map.setCenter(new GLatLng(-37.799025,144.991489), 16);
        map.setUIToDefault();

        // Add Controls
        var c = new GMapTypeControl();
        map.addControl(c);

        var point = new GLatLng(-37.799025,144.991489);
        map.addOverlay(new GMarker(point));
        var marker = new GMarker(point, {draggable: false});

        var html = "<div class='gmap-address'><p>Event Equipment<br />139 Sackville St, Collingwood,<br />Victoria 3066</p></div>";
        map.openInfoWindowHtml(map.getCenter(), html, {maxWidth:360,maxHeight:80});

        GEvent.addListener(marker, "click", function() {
            map.openInfoWindowHtml(map.getCenter(), html, {maxWidth:360,maxHeight:80});
        });
        map.addOverlay(marker);
        map.setCenter(new GLatLng(-37.799025,144.991489), 16);
    }
}