/* Author: Nathan Zander

Scripts to run onload.

*/

 $(document).ready(function(){
		external(); //launch external window script
		css_browser_selector(navigator.userAgent);
		//$.preloadCssImages();		
		//$("p").ieffembedfix();
		
		/*function(){
     $(".swap").hover(
          function(){this.src = this.src.replace("_off","_on");},
          function(){this.src = this.src.replace("_on","_off");
     
		 }); 
		//});*/
		
		
		//Colobox helpers
		function injectClass(newClass){
			console.log(newClass);
			if(newClass){
				$('#colorbox').addClass(newClass);
			} else {
				$('#colorbox').removeClass('weather');
			}
		}
		
	
		$("#menu-item-5 a").colorbox({iframe:true, innerWidth:350, innerHeight:425, scrolling: false, onOpen: function(){ $('#colorbox').addClass('weather'); } }); //Colorbox init for the weather tab
		$(".iframe").colorbox({iframe:true, innerWidth:400, innerHeight:350, transition:'elastic', onOpen: function(){ $('#colorbox').addClass('weather'); }});
		$("a[rel='cbox']").colorbox({iframe:true, innerWidth:630, innerHeight:825, scrolling:false, previous: "< Previous Homesite |", close: "Close Tour", next: "Next Homesite >", onOpen: function(){ $('#colorbox').removeClass('weather'); }});
		$(".holes > a").colorbox({iframe:true, innerWidth:630, innerHeight:825, scrolling:false, previous: "< Previous Hole |", close: "Close Tour", next: "Next Hole >", onOpen: function(){ $('#colorbox').removeClass('weather'); }});
		$(".homes > a").colorbox({iframe:true, innerWidth:630, innerHeight:825, scrolling:false, previous: "< Previous Homesite |", close: "Close Tour", next: "Next Homesite >", onOpen: function(){ $('#colorbox').removeClass('weather'); }});
		
		//code to start lightbox from external link
		var $slideshow = $('a[rel=golf-course]');

    $slideshow.colorbox();

    $('a.lower').click(function(){
        $slideshow.eq(0).click();
        return false;
    }); 
		
		//

		
		//Dynamically add <hr /> in sidebar
		$('.widget_text').after('<hr />');
		
		if ($.browser.msie) { //IE box shadows
    
		 if($(".wp-post-image").length){
  		var $elm = $(".wp-post-image");
		  var pos = $elm.position();
      $elm.after("<div class='ie-shadow'></div>");
      $(".ie-shadow").width($elm.width()).height($elm.height()).css("left", (pos.left - 4) + "px").css("top",(pos.top - 4) + "px");
		 }
		
		 if($(".shadow").length){
  		var $elm = $(".shadow");
		  var pos = $elm.position();
      $elm.after("<div class='ie-shadow2'></div>");
      $(".ie-shadow2").width($elm.width()).height($elm.height()).css("left", (pos.left - 4) + "px").css("top",(pos.top - 4) + "px");
		 }
		 
		 if($(".textwidget > img").length){
  		var $elm = $(".textwidget > img");
		  var pos = $elm.position();
      $elm.after("<div class='ie-shadow3'></div>");
      $(".ie-shadow3").width($elm.width()).height($elm.height()).css("left", (pos.left - 4) + "px").css("top",(pos.top - 4) + "px");
		 }
		 
		}
	
		
		//Golf Course banners 
		$('.hoverfade').each(function () {
			  var $span = $('> img.hover', this);//.css('opacity', 0);
				var $hoverImg = $('> img.icon', this);
				$hoverImg.hover(function () {
					//console.log($span);
					$span.css("display", "block");
					$span.stop().animate({
						opacity: 1,
						top: '-56',
					}, 750)
				}, function () {
					$span.stop().animate({
						opacity: 0,
						top: '-16',
					}, 250, function() {
   								 // Animation complete.
									 $span.css("display", "none");
  								})
				});
		}); 
		
		//Real Estate banners 
		$('.homesfade').each(function () {
			  var $span = $('> img.hover', this);//.css('opacity', 0);
				var $hoverImg = $('> img.icon', this);
				$hoverImg.hover(function () {
					//console.log($span);
					$span.css("display", "block");
					$span.stop().animate({
						opacity: 1,
						top: '-16',
					}, 750)
				}, function () {
					$span.stop().animate({
						opacity: 0,
						top: '16',
					}, 250, function() {
   								 // Animation complete.
									 $span.css("display", "none");
  								})
				});
		}); 
		
		//colorbox extenders
		$('.close').click(function(){
			$.colorbox.close();
		});	
		
		//Last-child hack
    $('ul.menu > li:last-child').addClass('last-child');
		
		
});//End Document Ready
























