function popup(url,name,w,h){
	window.open(url,name,'width='+w+',height='+h+',location=0,menubar=0,resizable=1,scrollbars=1,status=1')
}


$(document).ready(function(){
	
	// Nav dropdown on Event Detail pages
	$("#dropdownNavLink span.trigger").hover(function(){
		$("#dropdownNav").css("display","block");
	},function(){
		$("#dropdownNav").css("display","none");
	});
});

/*====================================================
   CROSS DOMAIN GOOGLE ANALYTICS TRACKING
====================================================== */
$(function(){
	// Cross-domain tracking
	$('a[href*="tarheelfantravel.com"]').mouseup(function(){
		_gaq.push(['_link', $(this).attr('href'), true]);
		return false;
	});
	// Track External Sites and Downloads
	$('a').mouseup(function(){
		var href = $(this).attr('href').toLowerCase();
		if (href.substr(-3) == "pdf" || href.substr(-3) == "xls" || href.substr(-3) == "doc") { // Track Downloads
			_gaq.push(['_trackEvent', 'Document', 'Download', href]);
		}
		else if (href.substr(0, 4) == "http" && href.indexOf('tarheelfantravel.com') == -1) { // Track External Links
			_gaq.push(['_trackEvent', 'External_Link', 'Open', href]);
		}

	});
});

/*====================================================
Form Placeholder Fallback
====================================================== */
var formKeyPressed;
$(function(){
	$('input[placeholder]:not([type=file],[type=submit]), textarea[placeholder]').each(function(){
		if(Modernizr.input.placeholder==false){
			// Find label text
			var placeholder = $(this).attr('placeholder');
			// Apply label and class to field
			$(this).val(placeholder).addClass('placeholder');
			// Handle Removing Placeholder and Screening back Placeholder
			$(this).focus(function(){
				if( $(this).val() == placeholder){
					$(this).addClass('placeholder-reminder');
					setCaretPosition(this,0);
				}
			}).keydown(function(e){
				if($(this).val()==placeholder){
					$(this).removeClass('placeholder-reminder').removeClass('placeholder');
					formKeyPressed = (e.keyCode ? e.keyCode : e.which);
					$(this).val('');
				}
			}).blur(function(){
				var placeholder = $(this).attr('placeholder');
				$(this).removeClass('placeholder-reminder');
				if($(this).val()==''){
					$(this).val(placeholder).addClass('placeholder');
				}
			});
		} else {
			var placeholder = $(this).attr('placeholder');
			$(this).focus(function(){
				if( $(this).val()=='' ){
					$(this).val(placeholder).addClass('placeholder-reminder');
					setCaretPosition(this,0);
				}
			}).keydown(function(e){
				if($(this).val()==placeholder){
					$(this).removeClass('placeholder-reminder').removeClass('placeholder');
					formKeyPressed = (e.keyCode ? e.keyCode : e.which);
					$(this).val('');
				}
			}).blur(function(){
				$(this).removeClass('placeholder-reminder');
				if($(this).val()==placeholder){
					$(this).val('');
				}
			});
		}
	});
});
function setCaretPosition(ctrl, pos){
  if(ctrl.setSelectionRange){
		ctrl.focus();
		//ctrl.setSelectionRange(pos,pos);
		setTimeout(function () {
			ctrl.setSelectionRange(pos,pos);
		}, 0);
  } else if (ctrl.createTextRange) {
		var range = ctrl.createTextRange();
		range.collapse(true);
		range.moveEnd('character', pos);
		range.moveStart('character', pos);
		range.select();
  }
}
