/**
 * @author ResolutionDesign Ltd
 * @copyright 2011
 * @site www.resolutiondesign.co.uk
 */
 
$( document ).ready(
    function()
    {
        $( 'a.lbox', 'ul#gallery' ).lightBox( { fixedNavigation:true } );
        if( $( 'div#that-map' ).length >= 1 )
        {
    		var latlng = new google.maps.LatLng( 51.435943, -2.207256 );
            
    		var settings = {
    			zoom: 15,
    			center: latlng,
    			mapTypeId: google.maps.MapTypeId.ROADMAP 
            };
            
            /*
            roadmap (default) specifies a standard roadmap image, as is normally shown on the Google Maps website. If no maptype value is specified, the Static Maps API serves roadmap tiles by default.
            satellite specifies a satellite image.
            terrain specifies a physical relief map image, showing terrain and vegetation.
            hybrid specifies a hybrid of the satellite and roadmap image, showing a transparent layer of major streets and place names on the satellite image.
            */
            
    		var map = new google.maps.Map(document.getElementById( "that-map" ), settings );
            
    		var companyImage = new google.maps.MarkerImage( '../images/googlemaps-logo.png',
    			new google.maps.Size( 120, 68 ),
    			new google.maps.Point( 0, 0 ),
    			new google.maps.Point( 70, 10 )
    		);
    
    		var companyShadow = new google.maps.MarkerImage( '../images/googlemaps-shadow.png',
    			new google.maps.Size( 150, 73 ),
    			new google.maps.Point( 0, 0 ),
    			new google.maps.Point( 70, 10 )
            );
    
    		var companyPos = new google.maps.LatLng( 51.435943, -2.207256 );
    
    		var companyMarker = new google.maps.Marker(
                {
        			position: companyPos,
        			map: map,
        			icon: companyImage,
        			shadow: companyShadow,
        			title: "GuyersHouse",
        			zIndex: 3
                }
            );
        }
        
        function getInternetExplorerVersion()
        {
            var rv = -1; // Return value assumes failure.
            
            if (navigator.appName == 'Microsoft Internet Explorer')
            {
                var ua = navigator.userAgent;
                var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
                if (re.exec(ua) != null)
                {
                    rv = parseFloat( RegExp.$1 );
                }
            }
            
            return rv;
        }
        
        function InternetExplorer7()
        {
            var ver = getInternetExplorerVersion();
            
            if( ver > -1 )
            {
                if( ver == 7 )
                {
                    return true;
                }
            }
            
            return false;
        }
        
        if( InternetExplorer7() )
        {
            ie7 = true;
        }
        else
        {
            ie7 = false;
        }
        
        
        $( 'img.over' ).hover(
            function()
            {
                $( this ).attr( 'src', $( this ).attr( 'src' ).replace( 'open', 'over' ) );
            },
            function()
            {
                $( this ).attr( 'src', $( this ).attr( 'src' ).replace( 'over', 'open' ) );
            }
        );
        
        $( 'a.over, button.over' ).hover(
            function()
            {   
                $( this ).css( 'background-image', $( this ).css( 'background-image' ).replace( 'open', 'over' ) );
            },
            function()
            {
                $( this ).css( 'background-image', $( this ).css( 'background-image' ).replace( 'over', 'open' ) );
            }
        );

        $( 'a.over-down, button.over-down' ).hover(
            function()
            {   
                if( ie7 ) return;
                
                $( this ).css( 'backgroundPosition', "0px -" + $( this ).css( 'height' ) );
            },
            function()
            {
                $( this ).css( 'backgroundPosition', "0px 0px" );
            }
        );
        
        $( 'a.dim-down, button.dim-down' ).hover(
            function()
            {
                $( this ).stop().fadeTo( 250, 0.8 );
            },
            function()
            {
                $( this ).stop().fadeTo( 250, 1 );
            }
        );

        $( 'input[name="arrival"]' ).datepicker( { 'dateFormat' : 'yy-mm-dd' } );

        var banners = new Array();
        var bannersLinks = new Array();
        
        banners[0] = "guyers-wedding-jquery.jpg"; 
        banners[1] = "guyers-accommodation-jquery.jpg"; 
        banners[2] = "guyers-conference-jquery.jpg"; 
        banners[3] = "guyers-restaurant-jquery.jpg"; 

        bannersLinks[0] = "offers-weddings.php"; 
        bannersLinks[1] = "offers-accommodation.php"; 
        bannersLinks[2] = "offers-conference.php"; 
        bannersLinks[3] = "offers-restaurant.php"; 
        
        var slide = $( '.slide', '#jquery-offers' );
        var anchor = $( 'a', '#jquery-offers' );
        
        var currentBanner = 0;
        var totalBanner = 3;
        
        // <div class="slide"><a href="#" class="btn animatingLink"></a></div>
        
        function fadeAnimation()
        {  
            image = "url( '../images/" + banners[ currentBanner ] + "' )";
            
            anchor
                .fadeOut(0)
                .css( { 'background-image' : image } )
                .attr( 'href', bannersLinks[ currentBanner ] )
                .fadeIn( 1000,
                    function()
                    {
                        slide.css( { 'background-image' : image } );
                    }
                );
            
            currentBanner++;
            
            if( currentBanner == 4 )
            {
                currentBanner = 0;
            }
            
            // After anchor faded in load background onto div.slide
            
            
        }
        
        var intervalSlider = setInterval( fadeAnimation, 4000 ); fadeAnimation();
        
        
        $( 'input[name="brochure_please"][type="checkbox"]' ).change(
            function()
            {
                if( $( this ).is(':checked') )
                {
                    $( 'div#brochure_address' ).slideDown();
                }
                else
                {
                    $( 'div#brochure_address' ).slideUp();
                }
            }
        );
        
    }
);
