//!!!!!!!! all javascript enclosed is (c)2010 Clarence "exoboy" Bowman. All rights reserved.          !!!!!!!!
//!!!!!!!! http://www.clarencebowman.com       !!!!!!!!

//****************************************************************************************************
// DEFINE GLOBALS BELOW
//****************************************************************************************************
//this is the current browser name that the page is being displayed in. values are [safari, opera, flock, chrome, explorer, firefox, and other]
// don;t forget, this is an object with { name:"name", version:"vers" }



//****************************************************************************************************
// DEFINE FUNCTIONS BELOW
//****************************************************************************************************

// ----------------------------------------------------------------
// what browser am I running in?
// ----------------------------------------------------------------
function getBrowserInfo()
{
	var browser = new Object();
	
	browser.version = navigator.appVersion;
	browser.name = navigator.userAgent;//appName;
	
	//alert( navigator.userAgent );
	
	if(browser.version.indexOf("MSIE 8") >-1)
	{
		browser.name = "explorer";
		browser.version = 8;
	} else if(browser.version.indexOf("MSIE 7") >-1)
	{
		browser.name = "explorer";
		browser.version = 7;
		_speed = 15;
		_delay = 0;
		
	} else if(browser.version.indexOf("MSIE 6") >-1)
	{
		browser.name = "explorer";
		browser.version = 6;
		_speed = 15;
		_delay = 0;
		
	} else if(browser.version.indexOf("MSIE 5") >-1)
	{
		browser.name = "explorer";
		browser.version = 5;
		
	} else if(browser.name.indexOf("Opera") >-1)
	{
		browser.name = "opera";
		browser.version = Math.floor(parseFloat(browser.version));
		_speed *= 2;
		_defaultSpeed = _speed;
		
	} else if(browser.name.indexOf("Netscape") >-1)
	{
		browser.name = "netscape";
		browser.version = Math.floor(parseFloat(browser.version));
		
	} else if(browser.name.indexOf("Firefox") >-1)
	{
		browser.name = "firefox";
		browser.version = Math.floor(parseFloat(browser.version));
		_speed *= 2;
		_defaultSpeed = _speed;
		
	} else {
		browser.name = "unknown";
		browser.version = 99;
	}
	
	// if the browser is too old, send them to an alternate page since some newer features will not work for this user
	if(browser.version <=6 && browser.name == "explorer")
	{
		document.location = "http://www.clarencebowman.com";
	}
	
	// otherwise, return the browwser object to the object that called this function
	return browser;
	
}

// ----------------------------------------------------------------
// resize the border elements to fit any stage
// ----------------------------------------------------------------
function refreshStage()
{
	var viewSize = document.viewport.getDimensions();	
	var height = viewSize.height;
	var width = viewSize.width;
	var baseHeight = $('base_panel').getHeight();
	
	var margin = ( height - baseHeight ) * .5;
	
	$('top_grad').setStyle({ height:String( margin + "px" ) });
	$('bottom_grad').setStyle({ height:String( margin + "px" ) });
	
	updateMask();
}

// ----------------------------------------------------------------
// calculate the correct width for the content_holder div
// ----------------------------------------------------------------
function setWidth(target,buffer)
{
	// get all the elements of class type: content_btn
	// add their widths
	// set the width of content_holder to that +5
	var target;
	var buffer;
	var targetKids = $( target ).select('[class="content_btn"]');
	var targetWidth = 0;
	
	for(var index=0;index<targetKids.length;++index )
	{
		targetWidth += $( targetKids[index] ).getWidth();
	}
	// now add buffer and assign the new width!
	targetWidth += buffer;
	target.setStyle({ width:String( targetWidth + "px" ) });
}

// ----------------------------------------------------------------
// create a date string of the current date
// ----------------------------------------------------------------
function currentDate()
{
		var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		var d_names = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		var d = new Date();
		var curr_date = d.getDate();
		var curr_month = d.getMonth();
		var curr_year = d.getFullYear();
		var curr_day = d.getDay();
		var dateString = String( d_names[curr_day] + " - " + m_names[curr_month]+" "+curr_date+", "+curr_year ); 
		return dateString;
}

// --------------------------------------------------------------------------------------------------------
// turn our page_mask on
// --------------------------------------------------------------------------------------------------------
function showMask(sender,myEvent)
{
	var sender,myEvent;

	var height = document.body.clientHeight || window.body.clientHeight;
	var width = document.body.clientWidth || window.body.clientWidth;
	
	// add a little extra to account for any elements that spill out of the body element
	//height += (height * .3);
	//width += (width * .3);
	var mask = _pageMask;
	
	mask.setStyle( { width:String( width + "px" ), height:String( height + "px" ), visibility:'visible' } );
	
	var view = document.viewport.getDimensions();
	
	var endWidth = view.width * .75;//show.getWidth();
	var endHeight = view.height * .75;//show.getHeight();
	
	var endTop = ( parseFloat( view.height ) - endHeight ) * .5;
	var endLeft = ( parseFloat( view.width ) - endWidth ) * .5;
	
	var show = _contentBase;
	
	// if no popup is showing, show the new one
	if( show.getStyle('visibility') != "visible") {
		
		try {
			
			var startX = Event.pointerX(myEvent);
			var startY = Event.pointerY(myEvent);
			
			// move tou our starting psition and size!
			show.setStyle({ width:"80px", height:"80px", left:String( startX + "px" ), top:String( startY + "px" ) }); 
			$('top_white_block').setStyle({ width:"80px" });
			$('middle_white_block').setStyle({ width:"80px", height:"80px" });
			$('bottom_white_block').setStyle({ width:"80px" });
		
			//make the menu BASE fade in
			show.setStyle({ visibility:'visible', opacity:'0.25', left:String( startX + 'px' ), top:String( startY + 'px' ), zindex:'256', width:"10px", height:"10px" });
			show.morph({ top:String( endTop + "px" ), left:String( endLeft + "px" ), opacity:"1.0", width:String( endWidth + "px" ), height:String( endHeight + "px" ) }, { duration:0.5 });
			
			$('top_white_block').morph({ width:String( (endWidth - 60) + "px" ) }, { duration:0.5, beforeUpdate:"" });
			$('middle_white_block').morph({ width:String( endWidth + "px" ), height:String( (endHeight - 60) + "px") }, { duration:0.5, beforeUpdate:"" });
			$('bottom_white_block').morph({ width:String( (endWidth - 60) + "px" ) }, { duration:0.5, beforeUpdate:"" });
			
			// save the name of the content panel to show.....
			mask._show = $(String(sender.id + "_content")).innerHTML;
			
			_contentData.update( mask._show );
			
			// now get the title of the section
			var array = sender.id.split("_");
			_contentTitle.update( String(array[0]) );
			
		} catch (e) {
			// there was a problem, so just open up the window at its final size....
			//alert("we had an error: "+e);
			show.setStyle({ top:String( endTop + "px" ), left:String( endLeft + "px" ), opacity:"1.0", width:String( endWidth + "px" ), height:String( endHeight + "px" ) });
			$('top_white_block').setStyle({ width:String( (endWidth - 60) + "px" ) });
			$('middle_white_block').setStyle({ width:String( endWidth + "px" ), height:String( (endHeight - 60) + "px") });
			$('bottom_white_block').setStyle({ width:String( (endWidth - 60) + "px" ) });
			
			// save the name of the content panel to show.....
			mask._show = $(String(sender.id + "_content")).innerHTML;
			
			_contentData.update( mask._show );
			
			// now get the title of the section
			var array = sender.id.split("_");
			_contentTitle.update( String(array[0]) );
			//return;
		}
	} else {
		// try and resize the already-open window!
		try {
			
			show.setStyle({ top:String( endTop + "px" ), left:String( endLeft + "px" ), width:String( endWidth + "px" ), height:String( endHeight + "px" ) });
			
			$('top_white_block').setStyle({ width:String( (endWidth - 60) + "px" ) });
			$('middle_white_block').setStyle({ width:String( endWidth + "px" ), height:String( (endHeight - 60) + "px" ) });
			$('bottom_white_block').setStyle({ width:String( (endWidth - 60) + "px" ) });
			
		} catch (e) {}
	}
	
}

// --------------------------------------------------------------------------------------------------------
// update the page_mask's size if the user resizes the window....
// --------------------------------------------------------------------------------------------------------
function updateMask()
{
	if(_pageMask.getStyle( "visibility" ) == "visible")
	{
		showMask();
	}
}

// --------------------------------------------------------------------------------------------------------
// hide the page_mask
// --------------------------------------------------------------------------------------------------------
function hideMask()
{
	var mask = _pageMask;
	var show = _contentBase;
	
	mask.setStyle( { visibility:"hidden", width:String( 0 + "px" ), height:String( 0 + "px" ) } );

	// if there is an associated popup, hide it
	try {
		show.setStyle({ visibility:'hidden' });
		//mask._show = null;
	} catch (e) {}
}


// --------------------------------------------------------------------------------------------------------
// enlarges any image into its own holder (above all other content)
// --------------------------------------------------------------------------------------------------------
function zoomImage(image)
{
	var image;
	var imageSuff = "_big.png";

	// open the link into a new window....
	var imageURL = String( _thisDomain + "photos/" + image.id + imageSuff);
	var photoWindow = window.open(imageURL,'photo','scrollbars=no,menubar=no,height=800,width=800,resizable=no,titlebar=yes,toolbar=no,location=no,status=no,id=photo,name=photo');
	
}
