globalJSObject = {

	// SHOW the LOGIN FORM + HIDE the REST of ALERTS BAR ----->

	login: function() {
		
		if ( $("#login_bar").length ) {
			var alerts = $("#alerts");
		
			$(".showLoginForm").click(function (){
				alerts.animate({top:'31px',opacity:'0'});
				$(".username").focus();
				return false;
			});

			$(".hideLoginForm").click(function () {
				alerts.animate({'top':'0',opacity:'1'});
				return false;
			});
			
			/* return state if master navbar is clicked */
			$("#nav a, #nav input").click(function(){
				alerts.animate({'top':'0',opacity:'1'},150);
			});
		}
	},

	// DROPNAVS ----->

	dropNavs: function(){
	
		$('#nav a.toggleDropNav').bind('click', function(e) {
		
			var master = $(this).closest("li");	
			var href = $(this);
			var target = $(this).parent().siblings("ul");
									
			href.addClass('active');
			
			target.slideToggle('fast');
							
			e.preventDefault();
				
			master.mouseleave(function() {
				setTimeout(function() {
					target.slideUp(200);
					href.removeClass('active');
				}, 300);
			});
		});
	},
	
	// HOME PAGE GRID TABS
	
	gridTabs: function(){
	
		$("#home #galleries.grid").hide();
	
		var stories_href = $("#page-nav .next a").attr("href");
		var stories_text = $("#page-nav .next a").text();
		
		var host = top.location.host;
		if ( host === "www.jaunted.com" ) { host = '/travel-photos' }
		else if ( host === "www.hotelchatter.com" ) { host = '/hotel-photos' }
		else if ( host === "www.vegaschatter.com" ) { host = '/vegas-photos' }

		$(".gridheader .nav a").click(function(){
		
			var index = $(".nav a").index(this),
				nav = $(".gridheader li"),
				thisNav = $(this).parent(),
				gridView = $(".gridcontainer > ul");
			
			if( !thisNav.data("active") )
			{
				nav.removeClass("active");
				$(this).parent().addClass("active");
				
				gridView
					.css('display','none')
					.eq(index).css('display','block');
			}

			if( $(this).parent().attr("id") === "image-galleries" ) {
				$("#page-nav .next a")
					.attr({ href: host })
					.text("More Galleries")
			} else if( $(this).parent().attr("id") === "more-recent-stories" ) {
				$("#page-nav .next a").attr("href", stories_href).text(stories_text);
			}

			return false;
		});
	},

	// DISALLOW NAVBAR SEARCH CLICK THROUGH WITHOUT FIRST ENTERING SEARCH TERM

	searchTermIsEntered: function(){
		$('#nav form').submit(function(){
				
				var navInput = $('#nav input[type="text"]');
				
	        	if ( navInput.val() === '') {
	        		 navInput.focus();
	        		 return false;
	       		}
	    });
	},
	
	// HIDE REF_TAG BAR ( incoming from sibling ) ----->
	
	refTag: function(){
		if ( $("#ref_tag").length ) {
			$("#ref_tag .close a").click(function () {
				$("#ref_tag").animate({'height':'0',opacity:'0'});
				return false;
			});
		}
	},
	
	// FOCUS on COMMENT FORM after CLICKING 'POST A COMMENT' ----->
	
	focusCommentInput: function(){
			$("#post-a-comment").click(function () {
				$("#standard-login-box input").focus();
			});
	},
	
	// MAKE GRID STORIES FULL ROLLOVERS ----->
	
	gridHover: function(){
		
		$(".grid a.more em").hide();
	
		$(".grid li.hentry").hover(function() {
				$(this).addClass('hover');
			}, function() { 
				$(this).removeClass('hover');
		});
	},
	
	// ADD #SECTION2 HOVER EFFECTS FOR IE6. THIS IS ONLY REQUIRED FOR IE6. OTHER BROWSERS HAVE FULL CSS SUPPORT ----->
	
	sidebarHoverIE: function(){
		if($.browser.msie && /6.0/ || /7.0/.test(navigator.userAgent)){
			
			var sidebarHover = $("#section2 li.hentry");
			
			sidebarHover.css('margin-bottom',1);
			sidebarHover.hover(function() {
					$(this).addClass('ie6-hover');
				}, function() {
					$(this).removeClass('ie6-hover');
			});
		}
	}
};

$(document).ready(function(){	

	globalJSObject.login();
	globalJSObject.dropNavs();
	globalJSObject.gridTabs();
	globalJSObject.gridHover();
	globalJSObject.sidebarHoverIE();
	globalJSObject.refTag();
	globalJSObject.focusCommentInput();
	globalJSObject.searchTermIsEntered();
	
	/* vegaschatter lightbox */
	if ( $(".colorbox").length ) {		
		$.fn.colorbox.settings.bgOpacity = "0.5";
		$("a[href='http://www.vegaschatter.com/vegasmaponly']").colorbox({fixedWidth:"1000px", fixedHeight:550, iframe:true});
	}

});
