// Shore Consulting Group
//
// Site Javascript


// drop down menu

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open(){	
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function jsddm_close(){	
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer(){	
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {	
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

$(document).ready(function(){
	// for drop down
	$('#mainNav > li').bind('mouseover', jsddm_open);
	$('#mainNav > li').bind('mouseout',  jsddm_timer);
	
	// for flash
	// onclicks
	// need to move bgtab image and change class active
	$("#consultingTab").live('click',function(event){
		event.preventDefault();
		if(!$(this).parent().hasClass("active")){
			// show section
			$(this).parent().parent().find("li").removeClass("active");
			$(this).parent().addClass("active");
			$(this).parent().parent().css("backgroundPosition","left top");
			//
			$("#featureBox").empty().append('<a class="media {width: 900, height: 292, type:\'swf\'}" href="i/feature_consulting.swf"></a>');
			$("#featureBox a").media();
		}
		else {
			// do nothing
		}								 
	})
	if($("body").attr("id") == "index"){
		$("#featureBox a").media();
	}
	$("#solutionsTab").live('click',function(event){
		event.preventDefault();
		if(!$(this).parent().hasClass("active")){
			// show section
			$(this).parent().parent().find("li").removeClass("active");
			$(this).parent().addClass("active");
			$(this).parent().parent().css("backgroundPosition","left -220px");
			//
			$("#featureBox").empty().append('<a class="media {width: 900, height: 292, type:\'swf\'}" href="i/feature_solutions.swf"></a>');
			$("#featureBox a").media();
		}
		else {
			// do nothing
		}								 
	})
	$("#staffingTab").live('click',function(event){
		event.preventDefault();
		if(!$(this).parent().hasClass("active")){
			// show section
			$(this).parent().parent().find("li").removeClass("active");
			$(this).parent().addClass("active");
			$(this).parent().parent().css("backgroundPosition","left -110px");
			//
			$("#featureBox").empty().append('<a class="media {width: 900, height: 292, type:\'swf\'}" href="i/feature_staffing.swf"></a>');
			$("#featureBox a").media();
		}
		else {
			// do nothing
		}								 
	})
	$("#trainingTab").live('click',function(event){
		event.preventDefault();
		if(!$(this).parent().hasClass("active")){
			// show section
			$(this).parent().parent().find("li").removeClass("active");
			$(this).parent().addClass("active");
			$(this).parent().parent().css("backgroundPosition","left -330px");
			//
			$("#featureBox").empty().append('<a class="media {width: 900, height: 292, type:\'swf\'}" href="i/feature_training.swf"></a>');
			$("#featureBox a").media();
		}
		else {
			// do nothing
		}								 
	})
	$("#creativeTab").live('click',function(event){
		event.preventDefault();
		if(!$(this).parent().hasClass("active")){
			// show section
			$(this).parent().parent().find("li").removeClass("active");
			$(this).parent().addClass("active");
			$(this).parent().parent().css("backgroundPosition","left -440px");
			//
			$("#featureBox").empty().append('<a class="media {width: 900, height: 292, type:\'swf\'}" href="i/feature_creative.swf"></a>');
			$("#featureBox a").media();
		}
		else {
			// do nothing
		}								 
	})	
	//
	// 
	// calendar (grab current post dates first)
	//
	if($("#entryform #date").length > 0) {
		dateStr = $("#entryform #date").val();
		dateStrr = dateStr.split("-");
		curDate = dateStrr[0] + "," + dateStrr[1] + "," + dateStrr[2];
	} else {
		curDate = "";
	}
	$.ajax({
		type: "POST",
		url: "getpostdates.php",
		data: "y=2009&m=07",
		success: function(dataBack){
			postDays = eval(dataBack),
			$("#datepicker")
				.datepicker({
					inline: true,
					changeMonth: true,
					changeYear: true,
					dateFormat: "yy-mm-dd", 
					defaultDate: new Date(curDate),
					onChangeMonthYear: function(year, month) { 
						$.ajax({
						   type: "POST",
						   url: "getpostdates.php",
						   data: "y="+year+"&m="+month,
						   success: function(dataBack){
							 postDays = eval(dataBack);
							 $("#datepicker").datepicker("refresh"); 
						   }
						});
					}, 
					beforeShowDay: function(thedate) {
						var theday = thedate.getDate();
						if( $.inArray(theday,postDays) == -1 ){
							return [true,""];
						} else {
							return [true, "ui-postOnDay"];
						}
					},
					onSelect: function(dateText, inst) {
						window.location = "muteme.php?ladat="+dateText;
					}
			});
		}
	});
});

document.onclick = jsddm_close;

// flash functions

var movieName = "FlashID";

function thisMovie(movieName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
	return window[movieName]
  }	else {
	return document[movieName]
  }
}

function movieIsLoaded (theMovie) {
  if (typeof(theMovie) != "undefined") {
	return theMovie.PercentLoaded() == 100;
  } else {
	return false;
  }
}

function goConsulting() {
	thisMovie(movieName).TGotoLabel("_level0/","consulting");
}

function goStaffing() {
	thisMovie(movieName).TGotoLabel("_level0/","staffing");
}

function goSolutions() {
	thisMovie(movieName).TGotoLabel("_root/","solutions");
 }

function goTraining() {
	thisMovie(movieName).TGotoLabel("_level0/","training");
}

function goCreative() {
	thisMovie(movieName).TGotoLabel("_level0/","creative");
}

