$(document).ready(function () {
	// Navigation ---------------------------------------
	$('#nav li').has('.subNav').mouseenter(function(){
			$(this).find('.subNav').show();
	})
	
	$('#nav li').has('.subNav').mouseleave(function(){
			$(this).find('.subNav').hide();
	})

    //Menu Controls --------------------------------------
    $('#menuList a:not(#menuList li.menuExtras a)').click(function () {
        var index = $("#menuList a").index(this);
        changeMenu(index, $(this));
        return false;
    });

    function changeMenu(index, clickedLink) {
        $('#menuList a').removeClass('on');
        $(clickedLink).addClass('on');
        $(".menuContentItem").css('display', 'none');
        $(".menuContentItem:eq(" + index + ")").fadeIn();
    }

    if ($('#menuList').length != 0) {
        $('#menuList a:eq(0)').trigger('click');
    }

    //press controls--------------------------------------
    $('#pressList li').mouseenter(function () {
        $(this).css('background', '#002715');
    });
    $('#pressList li').mouseleave(function () {
        $(this).css('background', '#001B0E');
    });


    //Color Box
    $("a[rel='color-box']").colorbox({transition:"fade"});
    $(".color-box-modal").colorbox({width:"840px", inline:true, href:"#modal"});
  

    //sports controls------------------------------------
    $('#sportsChannel a').mouseenter(function () {
        var currentHeight = $(this).height();
        var currentWidth = $(this).width();
        $(this).prepend('<div class="highLight">&nbsp;</div>')        
        $(this).css('position','relative')
        $(this).find('.highLight').css({            
            width: currentWidth,
            height: currentHeight,
            position: 'absolute',
            backgroundColor: 'yellow',
            opacity:.5,
            cursor: 'pointer'           
        })
    });


    $('#sportsChannel a').mouseleave(function () {       
        $(this).find('.highLight').remove()
    });
	
	//Contact us Controls---------------------------------
	$('#numbersList tbody tr:even, #additionalContact tr:even ').css('background','#001B0E');
	$('#contactUsForm input,#contactUsForm textarea').focus(function(){		
		$(this).css({ 
						borderColor: "#F05A00",
						backgroundColor: "#ffffff"
				    });
		
	});
	
	$('#contactUsForm input,#contactUsForm textarea').blur(function(){
		$(this).css({ 
						borderColor: '#001109',
						backgroundColor: '#8F8F8F'
				    });
		
	});
	
	
	if($('#mainImageSub').length > 0){
		$('.slideshow').cycle({
			fx: 'scrollRight' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	}
	
	if($('#mainImage').length > 0){
		$('.home-slideshow').cycle({
			fx: 'scrollRight' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	}
	
	// -----------------------------------------------
	//------------------------------------------------
	//-------------------Locator----------------------
	// -----------------------------------------------
	//------------------------------------------------
 

	if($('#storeLocator').length > 0){
			load()
			$('#mapNav input').trigger('click');
	}
	
});

	var map;
    var geocoder;


    function load() {
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById('map'));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(28.0832605, -80.6544894), 4);
      }
    }



function searchLocations() {
     var address = document.getElementById('addressInput').value;
     geocoder.getLatLng(address, function(latlng) {
       if (!latlng) {
         alert(address + ' not found');
       } else {
         searchLocationsNear(latlng);
       }
     });
   }


  function searchLocationsNear(center) {
     var radius = document.getElementById('radiusSelect').value;
     var searchUrl = 'location-search-xml-gen.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
     GDownloadUrl(searchUrl, function(data) {
       var xml = GXml.parse(data);
       var markers = xml.documentElement.getElementsByTagName('marker');
       map.clearOverlays();

       var sidebar = document.getElementById('sidebar');
       sidebar.innerHTML = '';
       if (markers.length == 0) {
         sidebar.innerHTML = 'No results found.';
         map.setCenter(new GLatLng(28.0832605, -80.6544894), 4);
         return;
       }

       var bounds = new GLatLngBounds();
       for (var i = 0; i < markers.length; i++) {
         var name = markers[i].getAttribute('name');
         var address = markers[i].getAttribute('address');
		 var phone = markers[i].getAttribute('phone');
		 var imageLink = markers[i].getAttribute('imageLink');
         var description = markers[i].getAttribute('description');
         var imageDirectory = markers[i].getAttribute('imageDirectory');
		 var distance = parseFloat(markers[i].getAttribute('distance'));
         var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                                 parseFloat(markers[i].getAttribute('lng')));
         
         var marker = createMarker(point, name, address);
         map.addOverlay(marker);
         var sidebarEntry = createSidebarEntry(marker, name, address, distance, phone, imageLink, description,imageDirectory);
         sidebar.appendChild(sidebarEntry);
         bounds.extend(point);
       }
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }

	var Icon = new GIcon();
		Icon.image = "images/duffysgooglemapicon.png";     
		Icon.iconSize = new GSize(41, 38);
		Icon.iconAnchor = new GPoint(9, 34);
      	Icon.infoWindowAnchor = new GPoint(9, 2);
      	Icon.infoShadowAnchor = new GPoint(18, 25);

		
    function createMarker(point, name, address) {
      var marker = new GMarker(point,Icon);         
      var html = '<b>' + name + '</b> <br/>' + address +'<br><a style="color:#001109;" target="_blank" href="http://maps.google.com/maps?daddr='+address+'">Get Directions</a>';
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

    function createSidebarEntry(marker, name, address, distance, phone, imageLink, description,imageDirectory) {
	  var div = document.createElement('div');
      //$(div).html('<img src="images/locations/'+ imageLink + '" align="right><br><b>' + name + '</b><br/>' + address +'<br>' + '<b>'+ phone + '</b><br><br>' + description);	
	  div.innerHTML = "<img src='images/locations/"+ imageLink + "' align=right><br><b>" + name + "</b><br/>" + address +"<br>" + "<b>" + phone + "</b><br><br>" + description + "<br><a href='locationgallery.php?loc=" + imageDirectory + "'>View Photos</a>";
	  div.style.marginBottom = "5px"
	  div.style.cursor = "pointer"
  	  div.setAttribute("class", "sidebarOption"); //For Most Browsers
	  div.setAttribute("className", "sidebarOption"); //For IE; harmless to other browsers.
      GEvent.addDomListener(div, 'click', function() {
        GEvent.trigger(marker, 'click');
      });
      GEvent.addDomListener(div, 'mouseover', function() {
        div.style.backgroundColor = '#002715';
      });
      GEvent.addDomListener(div, 'mouseout', function() {
        div.style.backgroundColor = '#001B0E';
      });
      return div;
    }


// mvp card login-----------------------------------------
function popChat(url,boxname,w,h)
{
    window.open(url, boxname, 'width=' + w + ',height=' + h + ',left=0,top=0,menubar=0,toolbar=0,status=0,resizable=0');
    return false;
} 




