/*
  * Normalized hide address bar for iOS & Android
  * (c) Scott Jehl, scottjehl.com
  * MIT License
*/
(function( win ){
	var doc = win.document;

	// If there's a hash, or addEventListener is undefined, stop here
	if( !location.hash && win.addEventListener ){

		//scroll to 1
		window.scrollTo( 0, 1 );
		var scrollTop = 1,
			getScrollTop = function(){
				return win.pageYOffset || doc.compatMode === "CSS1Compat" && doc.documentElement.scrollTop || doc.body.scrollTop || 0;
			},

			//reset to 0 on bodyready, if needed
			bodycheck = setInterval(function(){
				if( doc.body ){
					clearInterval( bodycheck );
					scrollTop = getScrollTop();
					win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
				}	
			}, 15 );

		win.addEventListener( "load", function(){
			setTimeout(function(){
				//at load, if user hasn't scrolled more than 20 or so...
				if( getScrollTop() < 20 ){
					//reset to hide addr bar at onload
					win.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
				}
			}, 0);
		} );
	}
})( this );


$(function() {
	
	if($('#mainnav > ul ul').css('display') != "none"){		
		$('#mainnav > ul').supersubs({ 
				minWidth:    10,   // minimum width of sub-menus in em units 
				maxWidth:    18,   // maximum width of sub-menus in em units 
				extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
								   // due to slight rounding differences and font-family 
			}).superfish({
			autoArrows:  false,
			dropShadows: false 
		});	
	}
	
	
	$("a#bookmarklink").click(function(){
	   var bookmarkUrl = this.href;
	   var bookmarkTitle = this.title;
		 
	   if ($.browser.mozilla) // For Mozilla Firefox Bookmark
	   { 
		window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
	   } 
	   else if($.browser.msie) // For IE Favorite
	   { 
		window.external.AddFavorite( bookmarkUrl, bookmarkTitle); 
	   }
	   else if($.browser.opera ) // For Opera Browsers
	   { 
		$(this).attr("href",bookmarkUrl);
		$(this).attr("title",bookmarkTitle);
		$(this).attr("rel","sidebar");
		$(this).click();
	   } 
	   else // for other browsers which does not support
	   { 
			alert('Your browser does not support this action. Please add this page to your favorites/bookmarks list manually.');
	   }
	   return false; 
	});
	
	var scopedata = '\
		<img src="img/scope.png" class="thescope">\
		<div class="cycle">\
			<img src="img/scopepic_1.gif">\
			<img src="img/scopepic_2.gif">\
			<img src="img/scopepic_3.gif">\
			<img src="img/scopepic_4.gif">\
		</div>\
		<div class="controls"></div>';
	
	$('#scope').eABI({
		'data' : scopedata,
		
		condition : function(){
			return $('#scope').css('display') != "none";	
		},
		
		callback: function(){
			$('#scope .cycle').cycle({ 
				speed:  1000,
				timeout: 6000,
				pager:  '#scope .controls', 
				cleartype: true,
				cleartypeNoBg: true,
				 
				// callback fn that creates a thumbnail to use as pager anchor 
				pagerAnchorBuilder: function(idx, slide) {
					return '<a href="#" class="dot" id="scopedot-' + idx + '"><img src="/img/cycledot.png"></a>';
				}
			});
		}
	});
	
	var extradata = '\
		<img src="img/welcome-to-texas-hunting-lease.png" alt="Welcome to Texas Hunting Lease" class="welcome">\
		<div class="redesign"><strong>We hope you enjoy our newly REDESIGNED home page!</strong> We will be updating the rest of our site, so don\'t be surprised by the new look!</div>\
		<div class="cyclecont">\
			<div class="controls"></div>\
			<div class="cycle">\
				<img src="img/slide_1.jpg">\
				<img src="img/slide_2.jpg">\
				<img src="img/slide_3.jpg">\
				<img src="img/slide_4.jpg">\
				<img src="img/slide_5.jpg">\
				<img src="img/slide_6.jpg">\
			</div>\
		</div>';
	
	$('#main .extra').eABI({
		'data' : extradata,
		
		condition : function(){
			return $('#main .extra').css('display') != "none";	
		},
		
		callback: function(){
			$('#main .extra .cycle').cycle({ 
				speed:  1000,
				timeout: 8000,
				pager:  '#main .extra .controls', 
				 
				// callback fn that creates a thumbnail to use as pager anchor 
				pagerAnchorBuilder: function(idx, slide) {
					return '<a href="#" class="dot" id="scopedot-' + idx + '"><img src="/img/cycledot.png"></a>';
				}
			});
		}
	});
	
});
