// JavaScript Document
var mobile=false;
var lastDate=false;
var dateIndex=false;
var pageHeight;
var scrollAmt = 375;
var boxScroll = 985;
var clickStyle; 
$(document).ready(function() {
	$("body#submitevent #pagecont").load("/elements/event_submission_form.php");
//	$("#header").click(function() {
//		window.open('/','_self');
//	});
	pageHeight=$(document).height();
	lastDate=$("#dateselect>div:eq(0)");
	dateIndex=lastDate.index();
	$("#dateselect>div:eq(0)").css('background','url(/images/pick-over.png) center center no-repeat');
	$("#dateselect>div").click(function() {
		$("#eventList>div").css('margin-left', ($("#dateselect>div").index(this)*(-460)));
		if(lastDate) {
			lastDate.css('background','url(/images/pick.png) center center no-repeat');
		}
		lastDate=$(this);
		dateIndex=lastDate.index();
		lastDate.css('background','url(/images/pick-over.png) center center no-repeat');
		checkWindow();
//		alert($("#eventList").children());
//		alert($("#dateselect>div").index(this));
	});
	checkWindow();
	$(window).scroll(function() {
		if(!mobile) {
			if($(window).scrollTop()>scrollAmt) {
				if($(".skyscraper").css('position')=='relative') $(".skyscraper").css('position','fixed');
			} else {
				$(".skyscraper").css('position','relative')
			}
			if($(window).scrollTop()>boxScroll) {
				if($(".slidebox").css('position')=='relative') $(".slidebox").css('position','fixed');
			} else {
				$(".slidebox").css('position','relative');
			}
		}
	});

/*	$("#rightnav li").click(function() {
		if($(this).html()=="Arts &amp; Culture") clickStyle='ArtsCulture';
		if($(this).html()=="Athletic") clickStyle='Athletic';
		if($(this).html()=="Business") clickStyle='Business';
		if($(this).html()=="Community") clickStyle='Community';
		if($(this).html()=="Education") clickStyle='Education';
		if($(this).html()=="Fairs &amp; Festivals") clickStyle='FairsFestivals';
		if($(this).html()=="Fundraisers") clickStyle='Fundraisers';
		if($(this).html()=="Government") clickStyle='Government';
		if($(this).html()=="Health &amp; Wellness") clickStyle='Health';
		if($(this).html()=="Kids &amp; Family") clickStyle='KidsFamily';
		if($(this).html()=="Music &amp; Nightlife") clickStyle='MusicNightlife';
		if($(this).html()=="Parks &amp; Recreation") clickStyle='ParksRec';

		if($(this).hasClass('nope')) { // is turned on
			$.ajax({
				url:"/elements/remember.php",
				dataType: 'html',
				data: { cat: clickStyle,
					stat: 'off' }
			});
			$(this).removeClass('nope');
			$(this).css('background','rgba(55, 117, 25, 0.7)');
			$(this).css('text-decoration','none');
			$(this).css('color','#fff');
			$(this).mouseleave(function () {
				$(this).css('background','');
				$(this).css('text-decoration','');
				$(this).css('color','');
			});
//			$("."+clickStyle).show(3000);
		} else { // is turned off
			$.ajax({
				url:"/elements/remember.php",
				dataType: 'html',
				data: { cat: clickStyle,
						stat: 'off' }
			});
			$(this).addClass('nope');
//			$("."+clickStyle).hide(3000);
		}
		$('body').toggleClass('hide'+clickStyle);
	}); */
	$("input[name=Date_Text]").live('blur',function() {
		if($(this).val()!="") {
		$.ajax({
			url:"/elements/datecheck.php",
			dataType: 'json',
			data: { date: $(this).val() },
			complete: function(data) {
				myData=eval("("+data.responseText+")");
//				$("input[name=Event_Start_Date]").val(myData.eventStartDate);
//				$("input[name=Event_End_Date]").val(myData.eventEndDate);
				$("input[name=Date_Text]").val(myData.eventField);
			}
		});
		}
	});
	$("input[name=Owner]").live('focus',function(){
		if($(this).val()=="Your Name or Company") $(this).val("");
	});
	$("input[name=Owner]").live('blur',function(){
		if($(this).val()=="") $(this).val("Your Name or Company");
	});
	$("input[name=Event_Name]").live('focus',function(){
		if($(this).val()=="My Great Event") $(this).val("");
	});
	$("input[name=Event_Name]").live('blur',function(){
		if($(this).val()=="") $(this).val("My Great Event");
	});
	$("input[name=URL]").live('focus',function(){
		if($(this).val()=="http://example.com/") $(this).val("");
	});
//	$("input[name=URL]").live('blur',function(){
//		if($(this).val()=="") $(this).val("http://example.com/");
//	});

	try { initialize_gmap(); } catch(err) {}
/*	$("#minical li").live('click',function() {
		$.ajax({
			url:"/content/",
			dataType: 'html',
			data: { date: $(this).attr("id") },
			complete: function(data) {
				tempVar = data.responseText;
//				alert(tempVar);
				$("#pagecont").html(tempVar);
			}
		});
		window.open('/'+$(this).attr("id"),'_self');
	});
//	$("#prevmon").live('click',window.open('','_self'))
*/
});

function initialize_gmap() {

}
function checkWindow() {
	$("#eventList").height('auto');
//	alert("#eventList>div>div:eq("+dateIndex+")");
	if($("#eventList").height() != $("#eventList>div>div:eq("+dateIndex+")").height()) {
		$("#eventList").height($("#eventList>div>div:eq("+dateIndex+")").height());
	} 
}

