var ggUI = {
	
	vars:{
		contactFormHeight:530,
		contactFormWidth:700
	},
	
	ie6:function(){
		return $.browser.msie && typeof document.body.style.maxHeight == 'undefined' ? true : false
	},
   
	init:function(){
		
		$('#top-nav ul>li>a').each(
			function(){	
				var loc = window.location.pathname.replace(/^\/|\/$/g,'');
				var re  = new RegExp(loc+'$','i');
			
				if(loc != ''){
					if (re.test($(this).attr('href')) ) {
						$(this).addClass('active');
					}
				}
			});
		
		
		$('.sales-gallery').hover(function(){
			$(this).css({backgroundImage:ggUI.ie6() ? 'url(/images/salesbg.gif)' : 'url(/images/salesbg.png)'}).stop().animate({height:175},function(){
				$(this).find('blockquote').show();
			});			
		},function(){
			$(this).find('blockquote').stop().fadeOut('fast')
			$(this).stop().animate({height:40},function(){$(this).css({backgroundImage:ggUI.ie6() ? 'url(/images/salesbgdefault.gif)': 'url(/images/salesbgdefault.png)'}).animate({height:50})});
		});
		
		$('.video>a').click(function(e){
			e.preventDefault();
			var wh = this.href.match(/width=\d+&height=\d+/);
			var vidWin = window.open(this.href,'vwin', wh[0].replace(/\&/,','));  
		
			return false;
		})
		
		$('a.new-win').click(function(e){
			var w = window.open(this.href,'vwin','width=980,height=650,scrollbars=yes,toolbar=yes,location=yes,resizable=yes');
			e.preventDefault();
			return false;			
		});
		
		$('img.hoverable').each(function(){
			$(this).hover(function(){
				var s = $(this).attr('src');
				$(this).attr('src', s.replace(/\.gif/,'-on.gif'));
			},function(){
				var s = $(this).attr('src');
				$(this).attr('src', s.replace(/-on\.gif/,'.gif'));				
			});			
		});
	},
	loadContactForm:function(){
		
		$('object,embed').hide();

	   $(document.documentElement).css('overflow','hidden');

	   var st = document.documentElement.scrollTop||document.body.scrollTop;
	   var wh = $(window).height();
	   var ww = $(window).width();

		if(wh < ggUI.vars.contactFormHeight){
			if(!confirm("The form you are about to load is larger than your viewable area and controls may not be visible.\n\nYou may have to click your browser's reload or refresh button to close the form.")){
				return;
			}			
		}

	   var d = $('<div>').addClass('lightbox-window').css({zIndex:8000,background:'#000',opacity:0.80,position:'absolute',top:0,left:0,width:ww,height:wh+st});	   
	   var ifr = $('<iframe>').addClass('content-iframe').attr({scrolling:'no',border:'0','frameBorder':'none',src:'/contact'}).css({
			background:'#214762',
			border:'20px solid #FFF',
			zIndex:8001,
			position:'absolute',
			top:(wh/2-ggUI.vars.contactFormHeight/2)+st,
			width: ggUI.vars.contactFormWidth,
			height: ggUI.vars.contactFormHeight,
			left:(ww/2-ggUI.vars.contactFormWidth/2)
		});	 
		
		if(ggUI.ie6()){
			ifr.css({borderRight:'none',borderBottom:'none'})
		}

	   $('body').append(d);	   
	   $('body').append(ifr);

	   $(window).bind('resize', ggUI.redrawContactForm);	
	
	},
	redrawContactForm:function(){
	   if($('.lightbox-window').length > 0){
	      setTimeout(function(){
      	   var st = document.documentElement.scrollTop||document.body.scrollTop;
      	   var wh = $(window).height();
      	   var ww = $(window).width();
      	   $('.lightbox-window').css({top:0,left:0,width:ww,height:wh+st});   
      	   $('.content-iframe').css({top:(wh/2-ggUI.vars.contactFormHeight/2)+st,left:(ww/2-ggUI.vars.contactFormWidth/2)});
      	},10);
	   }
	},
	closeContactForm:function(){
	 	$('.lightbox-window, .content-iframe').remove();
	 	$(document.documentElement).css('overflowY','auto');
	 	$(window).unbind('resize', ggUI.redrawContactForm);
		$('object,embed').show();		
	}
}

function showVideo(path){
	if(typeof path == 'undefined') var path = '/flash/video.php?v=/flash/video/DiamondBeachRound2_Final.flv';
	var vidwin = window.open(path,'widWin','height=486,width=864,scrollbars=no,resizable=no,toolbar=no,location=no');	
	return false;
}

$(function(){
	ggUI.init();
});