jQuery(document).ready(function($){
	
	//Enable external links
	$('a[rel~=external]').attr('target','_blank');
	
	//Enable pretty photo images
	$('a[rel^="prettyPhoto"]').prettyPhoto({
		showTitle:false
	});
	
	//Homepage slideshow
	$('#slideshow').cycle({
		timeout:6000
	});
	
	//Setup form field with default value
	function setFieldValue(id,value){
		$('#'+id).val(value).focus(function(){
			if( $(this).val() == value)
				$(this).val('');
		}).blur(function(){
			if( $(this).val() == '')
				$(this).val(value);
		});
	}
	
	//IE dropdowns
	if( $.browser.msie && parseFloat($.browser.version) < 7.0 ){
		$('#header li,#sidebar li').hover(
			function(){
				$('ul:first',this).show();
			},
			function(){
				$('ul:first',this).hide();
			}
		);
		$('#sidebar #menu-upcoming-events + ul').css('left','122px');
		$('#sidebar #menu-faqs + ul').css('left','116px');
		$('#sidebar #menu-support-harc + ul').css('left','111px');
	}
	
	//Homepage Video Popup
	 if ( $('.home').length ) videoPopup();
	 
	 function videoPopup(){
		if(readCookie('popuped') == 'yes') return;
		
		$.prettyPhoto.open('http://www.herkimerarc.org/video/index.html?iframe=true&width=490&height=340');
		
		createCookie('popuped','yes',0);
	}
	
	function createCookie(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
});

