/* Web design by First Coast Creative design@firstcoastcreative.net */

/* Browser Sniffer Class object

Read Article at http://www.firstcoastcreative.net/index.php?p=22
To use this as a means to style page based on browser type.

*/

  


function ini() {
	
	
  var t = setTimeout("Effect.Appear('promo')",3000) ;
  
  var h = setTimeout("Effect.DropOut('promo')",8000) ;
  
   var h2 = setTimeout("Effect.Grow('promo')",12000) ;
   
    
	  
	   var h5 = setTimeout("Effect.Shake('promo')",20000) ;
	   
	   
	    var h6 = setTimeout("Effect.Shake('promo')",25000) ;
		
		var h7 = setTimeout("Effect.Shake('promo')",30000) ;
	   
	   
  
  if( Element.hasClassName('bodywrap', 'ff') )
  {

  	try{
  	Effect.Grow('content');
	
	
	
	
  	}catch(err){};
  
  
  
  }else{
	  
	$('content').style.display='block';  
	  
	  
  }


};



function BrowserType() {}

BrowserType.isAppleWebKit = function()
{
    var kitName = "applewebkit/";
    var tempStr = navigator.userAgent.toLowerCase();
    var pos = tempStr.indexOf(kitName);
    var isAppleWebkit = (pos != -1);

    return isAppleWebkit;
}

BrowserType.isInternetExplorer = function()
{
    if( document.all )
    {
		var agt = navigator.userAgent.toLowerCase();
		return agt.indexOf( "opera" ) == -1;
    }
    else
    {
        return false;
    }
}

BrowserType.isInternetExplorerMac = function()
{
    return navigator.appName.indexOf( "Microsoft Internet Explorer" ) > -1
        && navigator.appVersion.indexOf( "Macintosh" ) > -1;
}

BrowserType.isGecko = function()
{
    var ua = navigator.userAgent.toLowerCase();
    return ua.indexOf( 'gecko' ) > - 1;
}

BrowserType.getBrowserType = function()
{
    if( BrowserType.isInternetExplorerMac() )
    {
        return "iemac";
    }
    else if( BrowserType.isInternetExplorer() )
    {
        return "ie";
    }
    else if( BrowserType.isAppleWebKit() )
    {
        return "safari";
    }
    else if( BrowserType.isGecko() )
    {
        return "ff";
    }
    else
    {
        return "";
    }
}


// End Browser Sniffer Class


//pop up window

function openWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

//pop up image window
function openImageWindow(image) {
var w = window.open("","", "resizable,status, width=800,height=600");
var d = w.document;
d.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
d.write('<html xmlns="http://www.w3.org/1999/xhtml">');
d.write('<head>');
d.write('<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />');
d.write('<title>Image Viewer</title>');
d.write('</head>');
d.write('<body style="text-align:center; padding: 50px;">');
d.write('<img name="image" src=" ');
d.write(image);
d.write('"  style="border:1px solid #000;margin: 20px;"/>');
d.write('<br /><form><input type=button value="Close Window" onClick="javascript:window.close();"></form> </body></html> ');
d.close();
}	


///Dropdown Menu

var currentMenu = null;

if (!document.getElementById)
    document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) return;


    actuator.onmouseover = function() {
        if (currentMenu) {
            currentMenu.style.visibility = "hidden";
            this.showMenu();
        }
    }
  
    actuator.onclick = function() {
        if (currentMenu == null) {
            this.showMenu();
        }
        else {
            currentMenu.style.visibility = "hidden";
            currentMenu = null;
        }

        return false;
    }

    actuator.showMenu = function() {
        menu.style.left = this.offsetLeft + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }
}

/// Function to dynamically add a class to an element on a page by page basis, pick the div then make and assign new class with overrides
/* example: 

<script language="JavaScript">
change('front_promo', 'longpage');
</script>

*/

function change(id, newClass) {

	if (document.getElementById(id)) 
	{

	identity=document.getElementById(id);

	identity.className=newClass;
	}

}


/// Function to help long page layouts, pick the div then set the new height, no extra css needed
/* example: 

<script language="JavaScript">
change('content', '1200px');
</script>

*/

function changeHeight(id,newHeight) {
	if (document.getElementById(id)) 
	{
	element=document.getElementById(id);

	element.style.height=newHeight;
	}
}



//////////////////////////////////////////
// Max Length Functions for textarea
//
//////////////////////////////////////////


function addEvent(obj, evType, fn, useCapture){
        if (obj.addEventListener){
                obj.addEventListener(evType, fn, useCapture);
                return true;
        } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
        }
        return false;
}
function removeEvent(obj, evType, fn, useCapture){
        if (obj.removeEventListener){
                obj.removeEventListener(evType, fn, useCapture);
                return true;
        } else if (obj.detachEvent){
                var r = obj.detachEvent("on"+evType, fn);
                return r;
        }
        return false;
}

// Declare the namespace
var fdTextareaController;

// Define anonymous function
(function() {

        // Create object private to the anonymous function
        function fdTextareaMaxlength(inp, maxlength) {
                this._inp       = inp;
                this._max       = Number(maxlength);
                var self        = this;

                self.maxlength = function() {
                        if(self._inp.disabled) return false;

                        if(self._inp.value.length > self._max) {
                                self._inp.value = self._inp.value.substring(0,self._max);
                                return false;
                        }

                        return true;
                }
                addEvent(self._inp, 'keypress', self.maxlength, false);
                addEvent(self._inp, 'blur',     self.maxlength, false);
                addEvent(self._inp, 'focus',    self.maxlength, false);

                // IE only event 'onpaste'

                // conditional compilation used to load only in IE win.

                /*@cc_on @*/
                /*@if (@_win32)
                addEvent(self._inp, 'paste', function(){ event.returnValue = false; self._inp.value = window.clipboardData.getData("Text").substring(0,self._max); }, true);
                /*@end @*/
        };

        // Construct the previously declared namespace
        fdTextareaController = {
                textareas: [],

                _construct: function( e ) {

                        var regExp_1 = /fd_max_([0-9]+){1}/ig;

                        var textareas = document.getElementsByTagName("textarea");

                        for(var i = 0, textarea; textarea = textareas[i]; i++) {
                                if(textarea.className && textarea.className.search(regExp_1) != -1) {
                                        max = parseInt(textarea.className.match(regExp_1)[0].replace(/fd_max_/ig, ''));
                                        if(max) fdTextareaController.textareas[fdTextareaController.textareas.length] = new fdTextareaMaxlength(textarea, max);
                                }
                        }

                },

                _deconstruct: function( e ) {
                        /* TODO: Clean up for IE memory leaks.. */
                }
        }
// Complete the anonymous function and call it immediately.
})();


addEvent(window, 'load', fdTextareaController._construct, false);
addEvent(window, 'unload', fdTextareaController._deconstruct, false);







///// AJAX Page Laoder

function FccAjaxLoader(el,url,id,parent)
{
    
	try {
	var current = document.getElementsByClassName('selected' , parent);
    current[0].className='';
	
	}catch(err) {
	
	};
    
	new Effect.Appear('loading');	
	new Ajax.Updater(el,url,{onComplete:function(){ 
	new Effect.Highlight(el);
    new Effect.Fade('loading');
    $(id).className='selected';
    
	}
	,asynchronous:true});
	
	
}

