var home = {

    fileLocation : '/assets/images/',
    mapSect : {
        'south' : 'warner_ukmap_southengland.gif',
        'anglia' : 'warner_ukmap_eastanglia.gif',
        'wales' : 'warner_ukmap_wales.gif',
        'north' : 'warner_ukmap_northengland.gif'
    },


    init : function(){
        $('#Map area').mouseover(function(){
            $('.mapregion').css('display','block').html($(this).attr('alt'));
            var areaTmp = $(this).attr('id');
            var picTmp = home.fileLocation + home.mapSect[areaTmp];
            $('#SelectMap').attr('src',picTmp);
        }).mouseout(function(){
            $('.mapregion').html('').css('display','none');
            $('#SelectMap').attr('src','/assets/images/warner_ukmap.gif');
        });

        //show the hotel menu        
        $('#hotelSelectDrop').change(function(){
            window.location=$(this).val();
        })
    }
}

var general = {
    //functions which are generalised for all pages eg side nav
    init : function(){
        $('select#selectahotel').change(function(){
            window.location = $(this).val();
        });
        

        $('#subBtn').click(function(){
            window.location = '/jumpto.html?outlink='+general.headto();
            return false;
        });

        //move the calendar button from the left of the form to thr right
        //$('#hotelDate').datePicker({dateFormat: 'dd/mm/yy'});
        //var t= $('#hotelDate').clone();
        //$('#hotelDate').remove();
        //$('.dp-choose-date').after(t);
        /*
        $("#hotelDate").date_input();
        $('.date_selector').live(function(){
           css('top','0px').css('left','0px') ;
        });
        */

    },
    headto : function(debug){
        //create THE link for the form
            //affiliate link parts
            //eg http://www.awin1.com/awclick.php?mid=1015&id=63715&clickref=111223344~~1ai1ix7a7*1scsvk*e9r&p=http://www.warnerleisurehotels.co.uk/hotels/holme-lacy-house-hotel/overview/
        var prefix = "http://www.awin1.com/awclick.php?mid=1015&id=63715";
        var trackParam ="&clickref=";//the track code
        var trackCode = general.getTrackingWithDcStorm('a08_warner_srchFrm');
        var fwdParam = "&p=";
            //template for the GET result
        var searchUrlTemplate = "http://bookonline.warnerleisurehotels.co.uk/breaklistings.aspx?ht=X_hotel&sd=X_date&tp=X_vouch&n=X_dur"
        var redirPg; //final redire URL string;

            //build the end page
                //hotel name
        searchUrlTemplate = searchUrlTemplate.replace("X_hotel", $('#hotelChoice').val());
                //arrival date
        searchUrlTemplate = searchUrlTemplate.replace("X_date", $('#hotelDate').val() );
                //duration
        searchUrlTemplate = searchUrlTemplate.replace("X_dur", $('#durationselect :selected').val());
                //voucher code
        searchUrlTemplate = searchUrlTemplate.replace("X_vouch", $('#offerCode').val() );

            //build time
        redirPg = prefix + trackParam + trackCode + fwdParam + searchUrlTemplate;
        redirPg = escape( redirPg ); //escape special url characters so we can grab the link later without it getting broken.

        if(debug){
            alert(redirPg);
            return false
        }
        else{
            return redirPg;
        }
    },
    getTrackingWithDcStorm : function(defaultTrack){
    /*-------------------------------------
    Description:
    Concatenates a8id, delimiter and dc storm id. We are doing this as the regular
    dc storm scripts dont work with expedia little widget

    Author: JL Aug '09
    Dependencies: jquery.js, jq.cookie.js

    -------------------------------------*/
	var delimiter ='~~';//change this if the delimiter changes on DC storm
	var DcStormCookie = ''; // the dc storm cookie which is set
        var a8id ='';

	if (general.getCookie('A8ID') == null){
            a8id = defaultTrack;
	}
	else{
            a8id = general.getCookie('A8ID');
	}

        if(!general.getCookie('_#clkid')){//if no dc storm id defined for what ever reason
		DcStormCookie = 'NoDcStormCookieSet';
	}
	else{
		DcStormCookie = general.getCookie('_#clkid');
	}
	return a8id + delimiter + DcStormCookie;
    },
    setCookie : function(c_name,value,expiredays){
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
    },

    getCookie : function(c_name){
        if (document.cookie.length>0){
            c_start=document.cookie.indexOf(c_name + "=");
            if (c_start!=-1){
                c_start=c_start + c_name.length+1;
                c_end=document.cookie.indexOf(";",c_start);
                if (c_end==-1){
                    c_end=document.cookie.length;
                }
                return unescape(document.cookie.substring(c_start,c_end));
            }
        }
    }
}

var hotel = {
    init : function(){
        $('.smallimg').mouseover(function(){
            $('.largeimg').attr('src',$(this).attr('src')).attr('title',$(this).attr('title'));
        })
        hotel.setMarkers(htlInfo.lat, htlInfo['long'], htlInfo.dist,htlInfo.limit);
        //add the "last" class to attraction to remove the margin
        $('#attractionmiddle li:last-child').addClass('last');
    },
    setMarkers : function(lat, lng, radius,limit){
        $.getJSON( 'ajaxcalls.html',
            {
                action: 'getNearestAttractions',
                lat: lat,
                lon: lng,
                radius: radius,
                limit: limit}, function(data){
                    for( var i = 0; i < data.length; i++ ){
                        var myLatlng = new google.maps.LatLng(data[i].latitude,data[i].longitude);
                        var text = '<div style="width: 210px"><b>'+data[i].name+'</b><br/>'+data[i].shortcopy+'</div>';

                        var marker = new google.maps.Marker({
                            position: myLatlng,
                            map: mapConfig.mapDomObj,
                            title: data[i].name
                        });
                        hotel.createMarker(marker, text);
                    }
        });
    },
    createMarker : function(marker, text) {
        var infowindow = new google.maps.InfoWindow({
            content: text
        })
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(mapConfig.mapDomObj,marker);
        });
    },
    addStreetView : function(){
        //$('#banners').append('<li id="streetView"></li>');
        //$('#streetView').css('border','solid 1px black').css('width','223px').css('height','300px');
        //var ll = new google.maps.LatLng(42.345573,-71.098326);

        var panoramaOptions = {
          position: new google.maps.LatLng(htlInfo.lat,htlInfo['long']),
          //position: new google.maps.LatLng(42.345573,-71.098326),
          addressControl : false,
          pov: {
            heading: 34,
            pitch: 10,
            zoom: 1
          }
        }

        var panorama = new  google.maps.StreetViewPanorama(document.getElementById("streetview"),panoramaOptions);
        mapConfig.mapDomObj.setStreetView(panorama);
    }
}



