// JavaScript Document

///////////////////////////////
//// DECLARE ALL FUNCTIONS ////
///////////////////////////////

//// Slide Show transition ////
function f_slideShow(imageNumber){
	var v_imageNum = imageNumber;
	var v_fadeTime = 700;
	var v_active = $("#divSlideshow_"+v_imageNum+" IMG.active");
	var v_next =  v_active.next().length ? v_active.next()
        : $("#divSlideshow_"+v_imageNum+" IMG:first");
	
	if (v_active.length == 0) v_active = $("#divSlideshow_"+v_imageNum+" IMG:last");
	v_active.addClass("last-active");
	
	v_next.css({opacity: 0.0})
		.addClass("active")
		.animate({opacity:1.0}, v_fadeTime, function() {
			v_active.removeClass("active last-active");
			});	
}
//// f_slideShow Interval Timer ////
function f_slideTimer(ssNumber){
	var v_ssNum = ssNumber;
	var v_holdTime = 2000;
	setInterval(function(){
		f_slideShow(v_ssNum)}, v_holdTime);
}

//////////////////////////////////////////////////////////////////////////////////////
//PAGE LOAD
//////////////////////////////////////////////////////////////////////////////////////
$(function() {

// DECLARE VARIABLES //
//Set the first value to show content when page loads
var v_newSection = null;
var v_curSection = "#divIntro";	
var v_portfolio = null;
// Set initial image source link var blank
var v_popoverStatus = 0;
var v_imageLink = null;
var v_slideShowName = null;

//Hide and show content at start
$("div.content").hide();
$(v_curSection).show();
$(".popup").hide();
$("#closemsg").hide();

//Hide Slideshows
$("#divSlideshow_1").hide();
$("#divSlideshow_2").hide();
$("#divSlideshow_3").hide();
// Hide the Tool Tips
$("div.tooltip").hide();
 
// CONTENT MENU FADING EFFECTS //
//Set the v_newSection variable
$("#divMenu a").mouseover(
	function(event){
	v_newSection = ("#div" + this.id);
	});
	
//The click effect	
$("#divMenu a").click(
	function(event){	
	//Check visibility of current 'v_curSection'
	if ($(v_curSection).is(":visible") && v_curSection != v_newSection){
		$(v_curSection).fadeOut("slow");	
		}			
	//Fade in the new 'v_newSection' and reset v_curSection value
	$(v_newSection).fadeIn("slow");
	v_curSection = v_newSection;	
 });
 
// TOOL TIP STYLE DESCRIPTION EFFECT //
$("a.tip").mouseover(
		function(event){
		$("#div" +this.id).fadeIn("fast");
		}).mousemove(
		function(kmouse){
			var border_top = $(window).scrollTop();
    		var border_right = $(window).width();
			var left_pos;
    		var top_pos;
    		var side_offset = 15;
			var top_offset = 40;
			
			if(border_right - (side_offset *2) >= $("#div" +this.id).width() + kmouse.pageX){
					left_pos = kmouse.pageX+side_offset;
					} else{
					left_pos = border_right-$("#div" +this.id).width()-side_offset;
					}

				if(border_top + (top_offset *2)>= kmouse.pageY - $("#div" +this.id).height()){
					top_pos = border_top +top_offset;
					} else{
					top_pos = kmouse.pageY-$("#div" +this.id).height()-top_offset;
					}	

				$("#div" +this.id).css({left:left_pos, top:top_pos});
		});
				
 $("a.tip").mouseout(
		function(event){
		$("#div" +this.id).fadeOut("fast");
		});
 
 
// PORTFOLIO POPOVER Functions// 
// Declare the functions that control the large portfolio image popover
// Decide if it shows an image or a slideshow
f_showPopover = function(){	
	if(v_popoverStatus==0){
			if(v_curSection== "#divVis"){
				$(v_slideShowName).fadeIn("slow");
				$("#popoverBoxBG").css({"opacity":"0.8"});
				$("#popoverBoxBG").fadeIn("slow");
				$("#closemsg").fadeIn("slow");
				v_popoverStatus = 1;
			}
			else{
				$("#popoverBox img").attr("src", v_imageLink);
				$("#popoverBoxBG").css({"opacity":"0.8"});
				$("#popoverBoxBG").fadeIn("slow");
				$("#popoverBox").fadeIn("slow");
				$("#closemsg").fadeIn("slow");
				v_popoverStatus = 1;
			}
		}	
 }
 
f_centerPopover = function(){
	var winHeight = document.documentElement.clientHeight;
	var winWidth = document.documentElement.clientWidth;
	var popupHeight = 800;
	var popupWidth = 800;	
	$("#popoverBox").css({
							 "position":"absolute",
							 "top": winHeight/2 - 280,
							 "left": winWidth/2 - popupWidth/2,
							 });
	$(".slideshow").css({
							 "position":"absolute",
							 "top": winHeight/2 - 280,
							 "left": winWidth/2 - 350,
							 });
	$("#closemsg").css({
							 "position":"absolute",
							 "top": winHeight/2 - 320,
							 "left": winWidth/2 - popupWidth/2 + 720,
							 });	
	
} 
 
f_hidePopover = function(){
	if (v_popoverStatus==1){
		$("#popoverBoxBG").fadeOut("slow");
		$("#popoverBox").fadeOut("slow");
		$("#closemsg").fadeOut("slow");
		$(v_slideShowName).fadeOut("slow");
		$("#popoverBox").css({"display":"hide"});
		v_popoverStatus = 0;		
	}
}

// Enable the mouse commands on Portfolio galleries
 $(".thumb img").mouseover(
		function(event){					
			v_imageLink = $(this).attr("src");
			v_slideShowName = "#div" + $(this).attr("id");
			$(".popup img").attr("src",v_imageLink);
     	 	$(".popup").show();
		}).mousemove(
			function(kmouse){
			$(".popup").css({left:kmouse.pageX-165, top:kmouse.pageY-240});
		}).mouseout(
			function(event){
			$(".popup").hide();
		}).click(
			function(event){
				f_showPopover();
				f_centerPopover();
		});

// Mouse Commands for closing the large popovers		
$("#popoverBoxBG").click( 		
 		function(event){
			if(v_popoverStatus==1){
			f_hidePopover();	
			}
		});
$("#closemsg").click(
		function(event){
			if(v_popoverStatus==1){
			f_hidePopover();	
			}
		});

//START SLIDE SHOWS
f_slideTimer(1);
f_slideTimer(2);
f_slideTimer(3);
});
