//variables
var mrFade = new Array(); //used for cancelling button border fades

//functions
function buttonHighlight(daElement)
{
	new Effect.Highlight(daElement,{startcolor:'#ffcc00',endcolor:'#ffffff',restorecolor:'#ffffff'})
}

function fileNameExtract(wholeurl)
{
	x = wholeurl.length;
	while((wholeurl.substring(x,x-1)) != "/" && x!=0){ x--; } clipstart = x;
	return wholeurl.substring(wholeurl.length,clipstart);
}

function initPageBio()
{
	//flashFramesBio();
	clearBorders();	
	checkBrowser();
}

function initPage()
{
	//flashFrames();
	clearBorders();	
	checkBrowser();
}

function checkBrowser()
{
	if(document.referrer.indexOf("gersic.com") == -1 || document.referrer.indexOf("gersic.com") > 15)
	{
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
		{ 
			var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
			if (ieversion<7)
				alert("Note: This page will not display correctly in IE6. Maybe give Firefox, Opera, or IE7 a try?");		
		}
	}
}

function flashFramesBio()
{
	//don't flash in IE, because IE will screw up the semi-transparent PNGs
	if (navigator.appName != 'Microsoft Internet Explorer')
	{
		if(fileNameExtract(document.referrer)=="index.html" || fileNameExtract(document.referrer)=="")
		{
			new Effect.Pulsate('mainUnderlay',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonHome',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonBio',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonMusic',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonProjects',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonAudio',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonWriting',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonContact',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonBlog',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('mainFrame',{duration:"1.0",pulses:"1"});
		}
	}
}

function flashFrames()
{
	//don't flash in IE, because IE will screw up the semi-transparent PNGs
	if (navigator.appName != 'Microsoft Internet Explorer')
	{
		if(fileNameExtract(document.referrer)=="index.html" || fileNameExtract(document.referrer)=="")
		{
			new Effect.Pulsate('headerButtonHome',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonBio',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonMusic',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonProjects',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonAudio',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonWriting',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonContact',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('headerButtonBlog',{duration:"0.5",pulses:"2"});
			new Effect.Pulsate('mainFrame',{duration:"1.0",pulses:"1"});
		}
	}
}

function clearBorders()
{
	new Effect.Opacity('headerHomeBorder',{duration:0.0, to:0.0});
	new Effect.Opacity('headerBioBorder',{duration:0.0, to:0.0});
	new Effect.Opacity('headerMusicBorder',{duration:0.0, to:0.0});
	new Effect.Opacity('headerProjectsBorder',{duration:0.0, to:0.0});
	new Effect.Opacity('headerAudioBorder',{duration:0.0, to:0.0});
	new Effect.Opacity('headerWritingBorder',{duration:0.0, to:0.0});
	new Effect.Opacity('headerContactBorder',{duration:0.0, to:0.0});	
	new Effect.Opacity('headerBlogBorder',{duration:0.0, to:0.0});
}
	
function headerButtonOver(buttonObject)
{
	if(mrFade[buttonObject])
			mrFade[buttonObject].cancel();
	new Effect.Opacity(buttonObject,{duration:0.0, from:0.0, to:1.0});
}

function headerButtonOut(buttonObject)
{
	mrFade[buttonObject] = new Effect.Opacity(buttonObject,{from:1.0, to:0.0});
}		


showCommentForm = function(daID)
{
	new Ajax.Request("commentForm.ajax", 
	{
	  	method: 'get',
	  	onSuccess: function(transport) 
	  	{
	    	var notice = $('daCommentFormDiv');
		    
	    	var newString=transport.responseText;
	    	newString += "\n<input type='hidden' name='daID' value='"+daID+"'>\n</form>";
	    	
    		notice.update(newString).setStyle({ background: '#ffffcc' });
		}
    
	});
}

submitCommentForm = function()
{
	$('commentForm').request({
  		onComplete: function(transport){
	  		var notice = $('daCommentAreaDiv');
	  		
	  		//remove form
	  		$('daCommentFormDiv').update("");
	  		
	  		//display results (all comments)
	  		notice.update(transport.responseText);	
	    }
	});
}

showPopupDiv = function(daContent,leftLocation,topLocation)
{	
	new Ajax.Request(daContent, 
	{
	  	method: 'get',
	  	onSuccess: function(transport) 
	  	{
		  	popupDiv.style.left=leftLocation;
		  	popupDiv.style.top=document.body.scrollTop; //just ignore topLocation for the time being...put the popup at the top of the window
		  	popupDiv.left=leftLocation;
		  	popupDiv.top=document.body.scrollTop; //just ignore topLocation for the time being...put the popup at the top of the window
		  	
	  		popupDiv.visibility='visible';
			popupDiv.style.visibility='visible';

	    	var notice = $('popupDiv');
		    
	    	var newString=transport.responseText;
	    	
    		notice.update(newString).setStyle({ background: '#ffffff' });
		}
    
	});
}

showPopupDivExplicit = function(daContent,leftLocation,topOffset,daWidth,daHeight)
{	
	new Ajax.Request(daContent, 
	{
	  	method: 'get',
	  	onSuccess: function(transport) 
	  	{
		  	popupDiv.style.left=leftLocation;
		  	popupDiv.style.top=document.body.scrollTop+topOffset; 
		  	popupDiv.left=leftLocation;
		  	popupDiv.top=document.body.scrollTop+topOffset; 
			popupDiv.style.width=daWidth;
			popupDiv.style.height=daHeight;
			popupDiv.width=daWidth;
			popupDiv.height=daHeight;

		  	
	  		popupDiv.visibility='visible';
			popupDiv.style.visibility='visible';

	    	var notice = $('popupDiv');
		    
	    	var newString=transport.responseText;
	    	
    		notice.update(newString).setStyle({ background: '#ffffff' });
		}
    
	});
}

hidePopupDiv = function()
{	
	new Ajax.Request("empty.ajax", 
	{
	  	method: 'get',
	  	onSuccess: function(transport) 
	  	{
	  		popupDiv.visibility='hidden';
			popupDiv.style.visibility='hidden';

	    	var notice = $('popupDiv');
		    
	    	var newString=transport.responseText;
	    	
    		notice.update(newString).setStyle({ background: '#ffffff' });
		}
    
	});
}

  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

  function showAttackTracker()
  {
	attackTrackerLayer.visibility='visible'
	attackTrackerLayer.style.visibility='visible'
	attackTrackerLayer.style.zIndex=1000;
	attackTrackerLayer.zIndex=1000;
  }
  function hideAttackTracker()
  {
	attackTrackerLayer.visibility='hidden'
	attackTrackerLayer.style.visibility='hidden' 
  }