/*
    Jared Bacik Last Update - 11/05/2009
    Hold JS events that can be used on any ABC Fire Page
*/

//Initialize each page with the same rules
function PageInit()
{
    //Set up the menu
    var myMenu = new MenuMatic({tweakInitial:{y:-2}});
	
	//Update the Copy Year on the page
    var tDay = new Date();
    if ($chk($('copyYear'))) {
        $('copyYear').set('html', tDay.getFullYear());
	}
	
	//Header image link back to home page.
	$('hdrABCIcon').setStyle('cursor','pointer');
	$('hdrABCIcon').addEvent('click', function() {
	    window.location.href = "index.html";
	});
}

//Initializes the product Bubbles and references for on hover display
//Used on the Products pages.
function ReferenceInit()
{
    if ($chk($('refWrap'))) {
        // Set product bubble opacity to zero so its hidden initially  
        // and toggle visibility on for the container back on  
	    $('productBubble').setStyle('opacity', 0); 
        $('bubbleWrap').setStyle('visibility','visible'); 
        
        //Set the left based on the number of references
        var refCount = $$('.productRef').length;
        var refLeft = parseInt(100/ refCount);
        if (refLeft < 100){
            $('refWrap').setStyle('left',refLeft.toString() + '%'); 
        }else{
            $('refWrap').setStyle('left','50%'); 
            $('refWrap').setStyle('margin-left','0px'); 
        }
    	
	    //Set the left based on the number of references
	    $$('.productRef a').each(function(el, i) { 
            //el.set('html', el.get('title'));
            /* Here we change the default 'link' property to 'cancel' for our morph effects, which 
               ensures effects are interrupted when the mouse is leaving and entering 
               to immediately begin the morph effect being called */
            el.set('morph', {link : 'cancel'}); 
            
            el.addEvents({ 
             'mouseenter': function() { 
                 $('productBubble').morph({ 
                     'opacity' : 1,  
                     'margin-top' : '-15px' 
                 }); 
                $('bubbleInfo').morph({ 
                     'opacity' : 1
                     //, 'margin-top' : '-15px'
                 }); 
                 el.getChildren('span').each(function(cEl, e){
                    if (cEl.className == "refInfo"){
                        $('bubbleInfo').set('html',cEl.get('title').replace('|','<br />'));
                    }
                 });
             }, 
             'mouseleave' : function() { 
                 $('productBubble').morph({ 
                     'opacity' : 0,  
                     'margin-top' : 0  
                 });
                 $('bubbleInfo').morph({ 
                     'opacity' : 0,  
                     'margin-top' : 0 
                 });  
                 $('bubbleInfo').set('html','');
             }  
            }); 
            
        });
    }else{
        //The Product Reference section is only holding images
        var refCount = $('imgWrap').getElements('a').length;
        var refLeft = parseInt(100/ refCount);
        if (refLeft < 100){
            $('imgWrap').setStyle('left',refLeft.toString() + '%'); 
            $('imgWrap').getElements('a')[0].setStyle('padding-left','0px'); 
        }else{
            $('imgWrap').setStyle('left','50%'); 
            $('imgWrap').setStyle('margin-left','0px'); 
        }    
    }
}


//Grab each link with the email class, take each link’s href and reformat the address so that it acts as a normal email link. 
//Use the new link to fill the anchor text as well, to help protect the email address from spammers.
function SetMailTo()
{
    $$('.email').each(function(el) {
        var properEmail = el.get('rel').replace('|','@');
		var anchor = new Element('a', {
			href: 'mailto:' + properEmail,
			'class': el.get('class'),
			'text': properEmail
		}).replaces(el);
	});
}

