/******** Cufon ********/

Cufon.replace('h3', {color: '#000'});



/******** theme drawer hider *********/
function hideDrawer() {
	$("#theme-drawer #theme-container").slideToggle("normal", function () {
		if ($("#theme-drawer #theme-container").is(':visible')) {
			$("#footer").css("margin-bottom", "150px");
		} else {
		$("#footer").css("margin-bottom", "20px");
		}
	});
}

function hideSign() {
	$("#the-sign-container #the-sign").hide("normal");
}

/******** easing call ********/
jQuery.easing.def = 'easeOutQuint';

/******** clear field ********/
function clearText(field){
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;
}


/*********** Theme selector ***********/
var currentPosition = 0;
var slowScrollSpeed = 0;
var timer;
var totalWidth = 2000;
var outerWidth = 1000;
var leftLimit = outerWidth - totalWidth;

/** uncomment this after holidays

function updateLimits() {				
	totalWidth = document.getElementById("theme-carousel").clientWidth;
	outerWidth = document.getElementById("theme-housing").clientWidth;
	
	leftLimit = outerWidth - totalWidth + 160;
}


function themeScroll(number) {
	updateLimits();
	currentPosition += number;

	// Clamp
	if(currentPosition > 0) {
		currentPosition = 0;
	}
	
	//alert("currentPosition: " + currentPosition + ", leftLimit: " + leftLimit + ", totalWidth: " + totalWidth + ", outerWidth: " + outerWidth);
	
	$("#theme-carousel").animate({left: currentPosition + "pt"}, 500)
	
	updateButtons();
	return;
}

function scrollPrevious() {
	themeScroll(133);
	return;
}


function scrollNext() {
	themeScroll(-133);
	return;
}


function setSlowScroll(amount) {
	//updateLimits();
	
	//slowScrollSpeed = amount;
}


function slowScroll()
{
	if(slowScrollSpeed) {
		currentPosition += slowScrollSpeed;
		document.getElementById("theme-carousel").style.left = currentPosition + "pt";
		updateButtons();
	}
}


function updateButtons()
{				
	if(currentPosition < 0) {
		document.getElementById("theme-previous").style.visibility = "visible";
	} else {
		document.getElementById("theme-previous").style.visibility = "hidden";
	}
						
	if(currentPosition > leftLimit) {
		document.getElementById("theme-next").style.visibility = "visible";
	} else {
		document.getElementById("theme-next").style.visibility = "hidden";
	}
	return;
}


window.onresize = function()
{
	updateLimits();
	updateButtons();
}

 all of this */

/* Konami Code */
konami.load("http://files.anidea.com/ANidea-Wallpapers.zip");


/******** let the fun begin.... ********/
$(document).ready(function(){

	$('#theme-drawer #theme-container').hide();

	/* pngfix */
	$(document).pngFix();

	$('#categories-preview ul').equalHeights(true);
	
	// class call to make links have target="_blank" and still validate
	blanks = ".new-window, #hp-flickr ul li a, .comment-list li h4 a, #stuff-we-love ul li a, #blog-roll ul li a"
	
	$(blanks).attr({target: '_blank'});
	
	// for the facebook connect
	$('#submit').attr({value: ''})
	
	// disabling links on lifestream [11,12,13,14,6 ]
	lifestreams = ".lifestream_feedid_11 .lifestream_events a, .lifestream_feedid_12 .lifestream_events a, .lifestream_feedid_13 .lifestream_events a, .lifestream_feedid_14 .lifestream_events a, .lifestream_feedid_6 .lifestream_events a"
	$(lifestreams).click(function() { return false; });
	$(lifestreams).mouseover(function(){window.status='Done';return true;});
	$(lifestreams).css("color","#222222");
	$(lifestreams).css("cursor","text");
	
	// clear the search form
	$('.searchtxt').attr ({
		onFocus: 'clearText(this)',
		onBlur: 'clearText(this)'
	})
	
	/* tooltip call */
	tooltip();
	
	/* Homepage Tabs */
	$('#hp-popular').tabs({ fx: { opacity: 'toggle' } });
	$('#contact-options > ul').tabs({ fx: { opacity: 'toggle' } });

	/* main nav drop down */
	var timers = new Array();
	
	$('#main-nav ul li.dropdown').each(function (i) {
		$(this).hover(
			function() {
				clearTimeout(timers[i*2]);
				clearTimeout(timers[i*2+1]);
				var elem = $(this);
				elem.addClass('current');
				if (elem.find('.ro-container').is(':visible')) return;
				timers[i*2] = setTimeout(function() {
					elem.find('.ro-container').show();
				}, 200);
			},
			function() {
				clearTimeout(timers[i*2]);
				clearTimeout(timers[i*2+1]);
				var elem = $(this);
				elem.removeClass('current');
				if (elem.find('.ro-container').is(':hidden')) return;
				timers[i*2+1] = setTimeout(function() {
					elem.find('.ro-container').fadeOut("def");
				}, 200);
			}
		);
	});


	/* Theme switcher madness */
	/* This is for the drawer */
	$("a.theme-thumb").click(function() {
		var themename = $(this).attr("rel");
		$("#anet-theme").attr({ href: "http://files.anidea.com/themes/" + themename + "/style.css"});
		hideDrawer();
		$.cookie('user_theme', themename, { path: '/', expires: 7 });
		return false;
	});

	/* this is for the post itself */
	$("a.theme-post").click(function() {
		alert("Enjoy the Holiday Theme in the time being!")
		/* hide for the mean time */
		var themename = $(this).attr("rel");
		$("#anet-theme").attr({ href: "http://files.anidea.com/themes/" + themename + "/style.css"});
		$.cookie('user_theme', themename, { path: '/', expires: 7 });
		return false;
	});
	
	$(".theme-toggle").click(function() {
		hideDrawer();
	});
	
	$("#the-sign").click(function() {
		hideSign();
	});
	
	
	$("#archives ul li:nth-child(odd)").addClass("odd");
	
	function killIt(){
			$(function(){
				$('#IE6-alert').fadeOut(1000);
			});
		};
	
	/* Form Validation */
	$("#commentform").validate({
		rules: {
			author: "required",
			email: "required"
		}
	});
	
	$("#commentform").validate ({
		messages: {
			author: "Oops, you forgot your Name!",
			email: "Please write down your e-mail. We won't display it."
		}
	}) 
	
	//timer = window.setInterval("slowScroll()", 50);
	
	/*if("2010.agencynet.com" == window.location.hostname){
		$('#back-to-anet').css('display', 'none');
	}*/
	
});	/****** ...and the fun ends ******/