jQuery(document).ready(function($) {

	//Speakers Bureau Collection Form
	$('#audienceFocus input').mouseover(function(){
		alert('hi');
/*
		$(this).stop().animate({
			borderTopColor: #FF0000,
			borderBottomColor: #FF0000,
			borderLeftColor: #FF0000,
			borderRightColor: #FF0000
		}, 'slow');
*/
	}, function(){
//		alert('out');
/*
		$(this).stop().animate({
			borderTopColor: #FFF,
			borderBottomColor: #FFF,
			borderLeftColor: #FFF,
			borderRightColor: #FFF
		}, 'slow');
*/
	});

	//Share this page
	if($('a.shareThisPage').length > 0){
		$('a.shareThisPage').click(function(){
			return false;
		});
		$.prettySociable();
	}
	if($('button').length > 0) $('button').button();
	if($('a.button').length > 0) $('a.button').button();

	$('#header-nav> li,#header-nav> .sub-menu> li').hover(function(){  
		//show its submenu  
		$(this).className='hover';
		$(this).addClass('hover');  
	},function() {
		//hide its submenu
		$(this).removeClass('hover');
	});
	
	//Make all external links open in new tab
	$('#header-nav a').each(function(){
		var siteRoot = $('#header-nav a:first').attr('href');
		var aURL = $(this).attr('href');
		if(aURL.indexOf(siteRoot) < 0){
			$(this).attr('target','_blank');
		}
	});

	//Custom CAP footer menu
	$('#footer-nav li:first').css('border-left','none');
	$('#footer-nav a').each(function(){
		if($(this).text() == 'Store'){
			$(this).attr('target','_blank');
		}
	});
	
	//Live chat support icon code
	var d=new Date();

	$.get(siteURL+'/getchatstatus.php?unique=' + d.getTime(), function(data){
		if(data.indexOf("Online") != -1){
			$('.liveSupport').css('background-position','-186px 0px');
			$('.liveSupport').unbind('hover');
			$('.liveSupport').mouseover(function(){
				$(this).css('background-position', $(this).css('background-position').replace('0px', '-38px'));
			});
			$('.liveSupport').mouseout(function(){
				$(this).css('background-position', $(this).css('background-position').replace('-38px', '0px'));
			});
		}
	});


	//Calendar features
	$('#editEvent input[name=eventAllDay]').click(function(){
		$(this).parent().parent().next().fadeToggle();
		$(this).parent().parent().next().next().fadeToggle();
	});		

/*
	$('#editEvent input[type=radio]').unbind('mousedown').unbind('click').unbind('mouseup').bind('mousedown mouseup', function(e) {
		// Code to allow disabling of radio options in recurrence.
		if(e.type == 'mousedown') {
			if($(this)[0].checked==true) {
				setTimeout("removeIT('"+$(this).attr('id')+"')", 150);
			}else{
				$('#editEvent input[type=radio]').removeAttr('checked');
			}
		}
	});
*/
	
	$('#editEvent button[name=submitEventChanges]').click(function(){
		var id = ($('#editEvent input[name=eventID]').val().length > 0) ? $('#editEvent input[name=eventID]').val() : false;
		var title = $('#editEvent input[name=eventTitle]').val();
		var startDate = $('#editEvent input[name=eventStart]').val();
		var endDate = $('#editEvent input[name=eventEnd]').val();
		var url = $('#editEvent input[name=eventURL]').val();
		var description = $('#editEvent textarea[name=eventDesc]').val();
		var featured = ($('#editEvent input[name=eventFeatured]').is(':checked')) ? 1 : 0;
		var allDay = $('#editEvent input[name=eventAllDay]').is(':checked');
		if(!allDay){
			var startTime = $('#editEvent input[name=eventStartTime]').val();
			var endTime = $('#editEvent input[name=eventEndTime]').val();
		}
		var groups = '';
		var recurrence = '';
		$('#editEvent .calgroup:checked').each(function(){
			groups += (groups.length == 0) ? $(this).attr('id').replace('group','') : '|' + $(this).attr('id').replace('group','');
		});
		$('#editEvent input[type=radio]:checked').each(function(){
			recurrence = ($(this).attr('id').replace('recur','').length > 0) ? $(this).attr('id').replace('recur','') : 'd';
		});
		
		var postArray = new Array();
		postArray.push(id,title,startDate,endDate,allDay,startTime,endTime,groups,recurrence);

		$.post(theroot+'/updateEvent.php', {
			ID: id,
			title: title,
			startDate: startDate,
			endDate: endDate,
			description: description,
			url: url,
			startTime: startTime,
			endTime: endTime,
			groups: groups,
			featured: featured,
			recurrence: recurrence
		}, function(data){
			if(data >= 1) window.parent.location.reload();
		});

	});
	
	$('#editEvent button[name=deleteEvent]').click(function(){
		var id = ($('#editEvent input[name=eventID]').val().length > 0) ? $('#editEvent input[name=eventID]').val() : false;
		if(confirm('Are you sure you want to delete this event?') && id.length > 0){
			$.post(theroot+'/deleteEvent.php', {
				ID: id
			}, function(data){
				if(data >= 1) window.parent.location.reload();
			});
		}
	});
		
});

function removeIT(id){
	jQuery('input[id='+id+']').removeAttr('checked');
}

function popUpchat(URL){
	$('#livechat').hide();
	
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=475,height=370');");
}
function closelivechat(){
	$('#livechat').hide();
}


