$(document).ready(function() {
	
	/*$("#content").idle(
		function() { 
			$("#content .line, .copy .inner").fadeTo("slow",.001);							  
		},
		function() {
			$("#content .line, .copy .inner").fadeTo("fast",1);						  						
		},
		{after:1500}
	);*/
	
	$(".lines").css({opacity:0,right:"-2%"});
	$("#more").css({opacity:0});
	$("#footer").css({opacity:0,position:"relative",top:20});
	$("#content .bucket").fadeOut(0);
	
	$("#more").live("click",function() {
		$(".group-1").fadeOut();
		$(this).addClass('active');
		$(".group-2").fadeIn();
	 });
	
	$("#more.active").live("click",function() {
		$(".group-2").fadeOut();
		$(this).removeClass('active');
		$(".group-1").fadeIn();
	 });

	$("#content .bucket").live("click",function() {
		cl = this;
		indx = $(this).index();
		if($(this).parent().is(".group-2")) { indx+=3};
		$("#content .bucket img:not(eq(" + indx + "))").css({border:"1px solid #1B1A1A"})
		$(this).find("img").css({border:"1px solid #fff"});
		$("#backstretch img").fadeOut(500,function() {
			$("#backstretch img").attr("src",$(cl).find("img").attr("src").replace(".jpg","_full.jpg"));
			$("#backstretch img").fadeIn();
		});
	});
	
	// cheap preloader
	$("body").append("<div style='visibility:hidden' id='preload'><img height='1' src='media/images/img_featured1_full.jpg'><img height='1' src='media/images/img_featured2_full.jpg'><img height='1' src='media/images/img_featured3_full.jpg'><img height='1' src='media/images/img_featured4_full.jpg'><img height='1' src='media/images/img_featured5_full.jpg'><img height='1' src='media/images/img_featured6_full.jpg'></div>");
	
	$("#header .lines").prepend("<div class='navHighlight' style='position:absolute; background:#0072BC; width:0px; height:35px; zIndex:-1'></div>");
	$(".top-nav a:not(a:last)").hover(function() {
		$(".navHighlight").stop().animate({width:$(this).width()+15,left:$(this).position().left,top:0});
		},function() {
	});
	$("#aboutLink").live("click",function() {
		$("#about").slideDown();
		whatMoves = $.browser.safari ? "body" : "html,body";
		$(whatMoves).animate({scrollTop:$("#about").position().top});
	});
	
	$("#close").live("click",function() {
		$("#about").hide();
		//whatMoves = $.browser.safari ? "body" : "html,body";
		//$(whatMoves).animate({scrollTop:$("#about").position().top});
	});
	
	setTimeout(function() {	
		$(".lines").animate({right:"0%",opacity:1},1000); 
		$("#more").animate({opacity:1},1000); 
		$("#footer").animate({top:0,opacity:1},1000,undefined,function() {		
			$("#content .bucket").each(function() {
				$(this).delay(($(this).index()+1)*500).fadeIn();													  
		  });
		});
	},1000);
	
	$(".ticker .items p:gt(0)").hide();
	tickerItem = 0;
	setInterval(function() {
		$(".ticker .items p:not(" + tickerItem + ")").hide();								
		$(".ticker .items p").eq(tickerItem).show();
		tickerItem++;
		if(tickerItem == $(".ticker .items p").length) { tickerItem=0; }
	},4000);
	
	// CONTACT US DIALOG
	$("#contactForm").dialog ({
		bgiframe: true,
		autoOpen: false,
		modal: true,
		width: 634,
		height: 'auto',
		minHeight: 386
	});
	
	// PROMO
	/*$("#promo").dialog ({
		bgiframe: true,
		autoOpen: false,
		modal: true,
		width: 827,
		height: 'auto',
		minHeight: 411
	});*/
	
	// OPEN CONTACT US DIALOG
	$('#contact').click(function() {
		$("#contactForm").dialog('open');
	});
	
	// OPEN PROMO US DIALOG
	//$("#promo").dialog('open');
	
	// IE6 IS DUMB
	$(document).pngFix(); 
	
	$("#btnJoin").live("click",function() {
		err = "";
		if($("#name").val() <= "" || $("#name").val()=="Name") {	err = err + "Name\n"; } 
		if($("#email").val() <= "" || $("#email").val()=="Email" || $("#email").val().indexOf("@")<=-1 || $("#email").val().indexOf(".")<=-1) {	err = err + "Email\n"; } 	
		if(err>"") { alert("You are missing the following fields\n" + err); } else {
			$.ajax({
				url: "do.newsletter.php",
				data: {name:$("#name").val(),email:$("#email").val()},
				success: function(msg){
					if(parseInt(msg)==1) {
						$(".newsletter").css({width:358}).html("<div style='color:#fff; margin-top:'>Thanks for joining the mailing list</div>");
						$("#email, #name, #btnEmail").fadeOut();						
					}
				}
			});	
		}
	});
	
	$("#btnSubmit").live("click",function() {
		err = "";
		if($("#contactName").val() <= "" || $("#contactName").val()=="Name") {	err = err + "Name\n"; } 
		if($("#contactEmail").val() <= "" || $("#contactEmail").val()=="Email" || $("#contactEmail").val().indexOf("@")<=-1 || $("#contactEmail").val().indexOf(".")<=-1) {	err = err + "Email\n"; } 	
		if(err>"") { alert("You are missing the following fields\n" + err); } else {
			$.ajax({
				url: "do.contact.php",
				data: {name:$("#contactName").val(),email:$("#contactEmail").val(),message:$("#contactMessage").val()},
				success: function(msg){
					if(parseInt(msg)==1) {
						$("#form2 tbody").remove()
						$("#form2").append("<div style='color:#000; height:208px;'>Thanks for the E-mail</div>");
//						$("#contactEmail, #contactName, #contactName, #btnSubmit").fadeOut();						
					}
				}
			});	
		}
	});
	
});
