var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;

function dropdown_open(){  
	dropdown_canceltimer();
	dropdown_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	
	//MAKES DROPDOWN SAME WIDTH AS BUTTON
	ddwidth = $(this).width() + "px";
	ddmenuitem.css('min-width', ddwidth)
}

function dropdown_close() { 
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden'); 
}

function dropdown_timer() { closetimer = window.setTimeout(dropdown_close, timeout); }

function dropdown_canceltimer() {  
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}
document.onclick = dropdown_close;

$(document).ready( function() {

	$('#dropdown > li').bind('mouseover', dropdown_open);
	$('#dropdown > li').bind('mouseout',  dropdown_timer);

	$('input[placeholder],textarea[placeholder]').placeholder();
	
	$('#sign-up').submit( function() {
		data = $('#sign-up').serialize();
		$.post("/wp-content/themes/cbc/email.php", data,
			function(feedback){
				alert(feedback);
				if(feedback=="Thank you!") $('#sign-up-form').reset();
			}
		);
		return false;
	});
	
	$("a.video").click(function() {
		$.fancybox({
			'padding'             : 0,
			'autoScale'   : false,
			'transitionIn'        : 'none',
			'transitionOut'       : 'none',
			'title'               : this.title,
			'width'               : 680,
			'height'              : 495,
			'overlayColor'		  : '#000',
			'href'                : this.href = this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
			'type'                : 'swf',
			'swf'                 : {'allowfullscreen':'true'}
		});
		return false;
	}); 
	
	$('#container').height($(document).height() + 'px');
	$(".column").equalHeights(670);
	var addon = 0;
	if($(".home .column").height() > 670 ) addon = 80;
	$('#index-content').height($('.column').height() + addon + 'px');
	$('body.home').height($('#index-content').height() + 795 + 'px');
	$('body:not(.home)').height($('#container').height() + 180 + 'px');
	$('#footer').css('top',$(document).height() - 33 + 'px');
	
	$('#facebook-sidebar').show();
});

jQuery.fn.reset = function () {
  $(this).each (function() { this.reset(); });
}

/*
CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

/**
 * jQuery.placeholder - Placeholder plugin for input fields
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2008/10/14
 *
 * @author Blair Mitchelmore
 * @version 1.0.1
 *
 **/
new function(a){a.fn.placeholder=function(b){b=b||{};var j=b.dataKey||"placeholderValue";var f=b.attr||"placeholder";var h=b.className||"placeholder";var k=b.values||[];var c=b.blockSubmit||false;var e=b.blankSubmit||false;var g=b.onSubmit||false;var i=b.value||"";var d=b.cursor_position||0;return this.filter(":input").each(function(l){a.data(this,j,k[l]||a(this).attr(f))}).each(function(){if(a.trim(a(this).val())===""){a(this).addClass(h).val(a.data(this,j))}}).focus(function(){if(a.trim(a(this).val())===a.data(this,j)){a(this).removeClass(h).val(i)}if(a.fn.setCursorPosition){a(this).setCursorPosition(d)}}).blur(function(){if(a.trim(a(this).val())===i){a(this).addClass(h).val(a.data(this,j))}}).each(function(l,m){if(c){new function(n){a(n.form).submit(function(){return a.trim(a(n).val())!=a.data(n,j)})}(m)}else{if(e){new function(n){a(n.form).submit(function(){if(a.trim(a(n).val())==a.data(n,j)){a(n).removeClass(h).val("")}return true})}(m)}else{if(g){new function(n){a(n.form).submit(g)}(m)}}}})}}(jQuery);

/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
})(jQuery);
