/**
* ONLOAD HANDLER
* Desc  : Add anything you want to run onload, in here
**/
window.addEvent('domready', function() {
    myHoverEffect.start({
        id          : "topmenu",
        elements    : "#tpl_topmenu ul li a",
        enter       : {"background-position":"center -49px"},
        leave       : {"background-color":"transparent","background-position":"center 90px"},
        duration    : {"enter":250,"leave":500}
    });

    myHoverEffect.start({
        id          : "horizmenu",
        elements    : "#tpl_headmenu ul li a",
        enter       : {"background-color":"#88B126","border-color":"#9FD02D"},
        leave       : {"background-color":"#111111","border-color":"#555555"},
        duration    : {"enter":150,"leave":250}
    });

    $$(".clickable").each(function(el){
        elurl = el.getElements("a.clickable-backup")[0];
        elurl.setStyle("display","none");
        el.setStyle("cursor","pointer");
        el.addEvents({
            "mouseenter" : function(){
                this.removeClass("clickable");
                this.addClass("clickable_hover");
            },
            "mouseleave" : function(){
                this.removeClass("clickable_hover");
                this.addClass("clickable");
            },
            "mousedown" : function(){
                if(this.getProperty("onclick")){
                    this.removeEvents();
                    this.addEvent("click",this.onclick);
                    this.fireEvent("click");
                } else {
                    window.location.href=this.getProperty("href");
                }
            }.bind(elurl)
        });
    });

    fixTopMenu();
});

/** PLAY FLASH MOVIE (575 x 480)
This is recorded at 1024x768 and shrunk to fit within 640x480) **/
function myMovie(id,vidHeight){
	var rand = new Date().getTime();
    var movieFrame = "<div id='flashcontent'></div>";

    vidHeight = (typeof(vidHeight) == "undefined")?480:vidHeight;

    if(!myEnv.browserIE6){
        myPopup.open(movieFrame,'flash'+640+"x"+vidHeight);
    }

    myFlash.get({
        flashvars:'vidlink='+id,
        width:640,
        height:vidHeight,
        movie:'/video/movieplayer.swf?vidlink='+id+'&rand='+rand+"&vidheight="+vidHeight+"&vidwidth="+640
    },'flashcontent');
    return false;
}

var myFlash = new function(){
    //Create and return HTML for new flash object
    this.get = function(o,destinationId){
        if(!o.quality){o.quality='high';}
        if(!o.swliveconnect){o.swliveconnect='true';}
        if(!o.menu){o.menu='false';}
        if(!o.scale){o.scale='noscale';}
        if(!o.salign){o.salign='tl';}
        if(!o.wmode){o.wmode='transparent';}
        var ob = "<object type='application/x-shockwave-flash' data='"+o.movie+"' width='"+o.width+"' height='"+o.height+"'>";
        for(i in o){
            if(i != "id"){
                ob += "<param name='"+i+"' value='"+o[i]+"' />";
            }
        }
        ob += "</object>";

        if(myEnv.browserIE6){
            document.write("<strong>Your browser is over 10 years old and is the reason we have had to show you the movie this way.</strong><br /><br />&lt; <a href='"+document.location.href+"'>Previous Page</a><br />"+ob);
        } else {
            if(typeof(destinationId) != "undefined"){
                $(destinationId).setProperty("html",ob);
            } else {
                return ob;
            }
        }
    }
}

/**
* ENVIRONMENT HANDLER
* Desc        :    The core settings for the other functions within this script
*                It's basically so we can quickly set path names etc and we know
*                all other functions here will use them
**/
var myEnv = new function(){
    this.imgPath    = "/images"; // General images
    this.browser    = navigator.appName == "Microsoft Internet Explorer"?"IE":navigator.appName;
    this.ieVersion    = navigator.appVersion.indexOf("MSIE")?parseFloat(navigator.appVersion.substr((navigator.appVersion.indexOf("MSIE")+5),1)):null;
    this.browserIE6 = ((this.browser == "IE") && (this.ieVersion < 7))?true:false;
    this.docType    = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
                    + '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB" lang="en">';

    // Get Env Property
    this.get = function(id){
        if(typeof(this[id]) != "undefined" && typeof(this[id]) != "function"){
            return this[id];
        }
        return "";
    }

    // Get window height fix for 'webkit' engines.
    // This is required in instances where absolute positioning
    // has been used to create the layout. In the 'webkit' browser styles they only take into
    // account certain elements and it can damage mootools window.getScroll dimensions.
    this.fixWindowScrollHeight = function(param){
        if(Browser.Engine.webkit && $("webkit_height_fix")){
            return $("webkit_height_fix").getCoordinates().bottom;
        } else {
            return window.getScrollHeight();
        }
        return o;
    }
}

/**
* AJAX HANDLER
* Desc		:	Handles all types of ajax requests
*				It can be attached to form buttons, <a>links and can be called directly from other scripts.
*
*
* Usage		:	The following examples will place the returned HTML into the element with the id of "myDivId" (where specified)
* Params	:	@sourceObject		=	Is set to either 'this' if on submit button or <a> link. Otherwise it can be set to a path to a	url.
*				@destinationId		=	Either the physical object or the string id of the object.
*				@responseFunction	=	The function to use as the alternative response after the ajax call has been made
*				@loaderFunction		=	An additional function that can be run straight after the "loading" dialogue shows. This function
*										would run before the ajax call.
*
*				Example 01 - link	: <a href="/go/somewhere.com" onclick="return myAjax.doRequest(this,'myDivId')">My Link</a>
*				Example 02 - submit	: <input type="submit" value="Submit Form" onclick="return myAjax.doRequest(this,'myDivId')" />
*				Example 03 - script : myAjax.doRequest("/go/somewhere.com","myDivId");
*
*
*				What's the "onComplete function all about?
*				==========================================
*				well.. this function is used when you want to run javascript from the html content that was called.
*				So basically, aswell as returning HTML you can also return additional javascript that can run AFTER the HTML
*				has been placed in its final location. Have a look at the class "class.javascript.php" in the classes repository and
*				find the function myAjaxComplete() which you can run in order to apply additional script to run. It's good because
*				you don't have to bulk up your initial Javascript includes before making these kind of calls.
*
**/
var myAjax = new function ajaxObject(){

	// Turn on debugging
	this.debug = false;

	// On complete function
	// This is run at the very VERY end of any myAjax, even after
	// the doResponse() function is called. It is useful for running additional Javascript
	// that does something to the content AFTER it is placed into its destination.
	// This means you can set the Javascript on the loaded content side.
	this.onComplete = function(){}

	// The ajaxControl frame
	this.ajaxFrame = null;

	// Main request function
	this.doRequest = function(sourceObject,destinationId,responseFunction,loaderFunction){

        // Remove any existing ajax control frame
        this.removeAjaxControlFrame();

		// Reset finished
		// Shouldn't be set yet anyway
		this.onComplete = function(){}

		// Work out what type of object we've clicked on
		if(typeof(sourceObject) == "string" || sourceObject.tagName == "A"){
			this.requestType	= "get";
		} else {
			this.requestType	= "post";

			// Find form
			this.form = sourceObject.parentNode;
			while(this.form.tagName != "FORM"){
				this.form = this.form.parentNode;
			}

			// Did we find a form?
			if(this.form.tagName != "FORM"){
				alert("Unable to complete ajax request. Form was not found.");
				return;
			}
		}

		// Store generic values
		this.destinationLayer		= typeof(destinationId) == "string"?(destinationId=="self"?"self":document.getElementById(destinationId)):destinationId;
		this.sourceObject			= sourceObject;
		this.responseFunction		= responseFunction;

		// Do 'post' stuff
		if(this.requestType == "post"){
			this.createAjaxControlFrame();
			this.originalFormAction		= this.form.action;
			this.originalFormTarget		= this.form.target;
			this.form.target			= "ajaxFrame";

			// Insert a temporary postButton duplicate. This is needed because when the ajax event is attached directly to a
			// submit button it fails to include the submit button's name and value when submitting the form.
			this.ajaxTempButton			= document.createElement("input");
			this.ajaxTempButton.type	= "hidden";
			this.ajaxTempButton.name	= this.sourceObject.name;
			this.ajaxTempButton.value	= this.sourceObject.value;
			this.form.appendChild(this.ajaxTempButton);

            // Create hidden input to identifer that this form has been submitted through an ajax call
            this.createAjaxIdentifier("post");

			//Submit the form
			this.form.submit();

			//Revert form action and target to original values
			this.form.action = this.originalFormAction;
			this.form.target = this.originalFormTarget;

			//Remove temporary Button element
			if(this.ajaxTempButton){
				this.form.removeChild(this.ajaxTempButton);
			}
			return false;

		// Do 'get' stuff
		} else {

			// Show Ajax Loader
			this.startLoader();
			if(typeof(loaderFunction) == "function"){
				loaderFunction(this.loader,"loader");
			} else {
				if(this.destinationLayer){
					this.writeToDestination(this.loader);
				}
			}

			var url = this.createAjaxIdentifier(typeof(this.sourceObject) == "string"?this.sourceObject:this.sourceObject.href);
            if(url.substr(0,1) == "/"){
                url = "http://"+window.location.hostname+url;
            }
			this.createAjaxControlFrame(url);
			return false;
		}
	}

	// Response action after the form has been submitted to the iframe
	// If not destination has been selected then do nothing.
	this.doResponse= function(){
        if(this.ajaxFrame.contentWindow.document.body){

            // Get response
		    var responseHtml = this.ajaxFrame.contentWindow.document.body.innerHTML;

            // Fix a really stupid IE bug whereby it does not copy some/all of the PARAM tags properly.
            // A big problem is the "flashvars" attribute. It seems to just blank it. Possible something to
            // do with the case being used in the original object. Anyway, this rebuilds the first object it
            // finds.
            if(Browser.Engine.trident){
                var object = this.ajaxFrame.contentWindow.document.body.getElementsByTagName("OBJECT")[0];
                if(object){
                    var params  = object.getElementsByTagName("PARAM");
                    var phtml   = "";
                    for(i in params){
                        phtml += "<param name='"+params[i].name+"' value='"+params[i].value+"' />";
                    }
                    responseHtml2 = responseHtml.replace(/\<PARAM[^\>]*?\>/ig,"");
                    var c1 = responseHtml2.split("</OBJECT>");
                    responseHtml = c1[0]+phtml+"</OBJECT>"+c1[1]+"<br />";
                }
            }
            this.ajaxFrame.contentWindow.document.body.innerHTML = "";
        }

		// Have we asked to run a different response Function?
		if(typeof(this.responseFunction) == "function"){
			this.responseFunction(responseHtml);
		} else {
			// Should we update the destination element if it's been set?
			// If it has been set to "self" then return the value;
            // If a specific command has been returned then issue it..

            // If the content returned is requesting a location, go there!
            if(responseHtml.substr(0,9) == "location:"){
                responseHtml = responseHtml.replace("location:","");
                responseHtml = responseHtml.replace("&amp;","&");
                parent.location.href = "http://"+window.location.hostname+responseHtml;
            } else
            // Run appropriate response function
			if(this.destinationLayer){
				if(this.destinationLayer == "self"){
					return responseHtml;
				} else {
					this.writeToDestination(responseHtml);
				}
			}
		}

		// Run very last function and unflag as active
		this.onComplete();
	}

	// Write HTML to specificed destination
	this.writeToDestination = function(txt){
		this.destinationLayer.innerHTML = txt;
	}

    // Apply identifier to the URL so that PHP has something to work with too
    this.createAjaxIdentifier = function(url){
        if(url=="post"){
            this.ajaxIdentifier         = document.createElement("input");
            this.ajaxIdentifier.type    = "hidden";
            this.ajaxIdentifier.name    = "ajax";
            this.ajaxIdentifier.value    = new Date().getTime();
            this.form.appendChild(this.ajaxIdentifier);
        } else {
            var d = new Date();
            if(url.indexOf("?") > -1){
                url += "&ajax=1&ajaxrand="+d.getTime();
            } else {
                url += "?ajax=1&ajaxrand="+d.getTime();
            }
            return url;
        }
    }

	// Create Ajax controller iframe
	this.createAjaxControlFrame = function(url){
		if(this.debug == false || (this.debug == true && this.ajaxFrame == null)){
			this.canvasObject						= document.createElement("div");
			this.canvasObject.style.position		= "absolute";
			this.canvasObject.style.top				= "0px";
			this.canvasObject.style.left			= "0px";
			this.canvasObject.style.backgroundColor = "#ffffff";
			this.canvasObject.style.visibility		= this.debug == true?'visible':'hidden';
			this.canvasObject.style.width			= "100px";
			this.canvasObject.style.height			= "100px";
			this.canvasObject.id					= "canvasObjectFrame";

			if(document.addEventListener){
				this.canvasObject.innerHTML				+= "<iframe id='ajaxFrame' style='display width='100' height='100' name='ajaxFrame'"+(typeof(url)!="undefined"?" src='"+url+"'":"")+"></iframe>";
				document.body.appendChild(this.canvasObject);
				this.ajaxFrame			= document.getElementById("ajaxFrame");
				this.ajaxFrame.addEventListener("load",function(){myAjax.doResponse();},false);
			} else {
				if(typeof(url) != "undefined"){
					if(url.indexOf("about:blank")>-1){
						url2 = window.location.href.split("?");
						url = url.replace("about:blank",url2[0]);
					}
				}
				this.canvasObject.innerHTML	+= "<iframe id='ajaxFrame' name='ajaxFrame' width='100' height='100'"+(typeof(url)!="undefined"?" src='"+url+"'":"")+" onload='myAjax.doResponse();'></iframe>";
				document.body.appendChild(this.canvasObject);
				this.ajaxFrame	= document.getElementById("ajaxFrame");
			}
		}

		// Return false if 'get'
		if(this.requestType == "get"){
			return false;
		}
	}

	// Remove Ajax controller iframe
	// We remove it after the call to stop the browser's back button getting confused and going back through
	// pages of the iframe.
	this.removeAjaxControlFrame = function(){
		if(myAjax.ajaxFrame){
			myAjax.canvasObject.parentNode.removeChild(myAjax.canvasObject);
			myAjax.ajaxFrame = null;
		}
    }

	// Create Loading bar
	this.startLoader = function(){
		if(typeof(this.loader) == "undefined"){
			this.loader = "<span class='ajaxLoader' style=\"display:block;\"><span style=\"line-height:12px;display:block;font-size:11px;\">";
            this.loader+= "Please wait... loading... (please allow up to 15 seconds)<br />";
            this.loader+= "(If nothing loads, there may be a security/firewall issue at your location).<br />";
            this.loader+= "</span><span style=\"font-size:1px;display:block;width:120px;height:20px;margin-top:5px;background-image:url('"+myEnv.get("imgPath")+"/ajax_loader_bg.gif');\">&nbsp;</span></span>";
		}
	}
}

// Screen Brightness Control
var myScreenBrightness = new function(showLoader){
    this.layers= new Array();

    // Darken screen
    this.darken    = function(showLoader){

        // Check for windowHeight fix.
        var winScrollHeight = myEnv.fixWindowScrollHeight();

        var ds_id = this.layers.length+1;
        var ds = new Element('div', {
            'styles': {
                'background-color' : '#D5D6C5',
                'opacity' : 0.8,
                'top' : 0+"px",
                'left' : 0+"px",
                'position': 'absolute',
                'height' : winScrollHeight+"px",
                'width' : window.getScrollWidth()+"px",
                'z-index':500+myPopup.layers.length+ds_id,
                'visibility' : 'hidden'
            }
        });

        // Create Loader?
        if(showLoader === true){
            ds.setStyles({
                "background-image"        : "url("+myEnv.get("imgPath")+"/ajax_loader_bg.gif')",
                "background-repeat"        : "no-repeat",
                "background-position"    : ((window.getWidth()/2)-30)+window.getScrollLeft()+"px "+(window.getScrollTop()+(window.getHeight()/2)-15)+"px"
            });
        }

        ds.setProperty("id","darkenScreen"+ds_id);
        ds.inject(document.body);
        ds.setStyle("visibility","visible");

        // Add Darkened Screen layer to history
        this.layers.push("darkenScreen"+ds_id);
    }

    // Undarken screen
    this.undarken = function(){
        var id = this.layers.pop();
        if($(id)){
            $(id).empty();
            $(id).dispose();
        }
    }
}

var myPopup = new function(){
    this.layers     = new Array();
    this.objects    = new Object();

    this.getMostRecentObject = function(){
        id = this.layers[this.layers.length-1];
        return this.objects[id];
    }

    this.openWithCaption = function(content,popupClassName,showCloseButton){
        this.open(content,popupClassName,showCloseButton,true);
    }

    this.open = function(content,popupClassName,showCloseButton,showTitleAsCaption){

        // Create Unique Identifier
        var uniqueId = Math.ceil(Math.random()*6000);
        this.layers.push(uniqueId);
        this.objects[uniqueId]      = new Object();
        this.objects[uniqueId].id   = uniqueId;
        o = this.objects[uniqueId];

        // Create default settings
        o.showClose             = typeof(showCloseButton)=="boolean"?showCloseButton:true;
        o.popupClassName        = "popupBox_"+(popupClassName == null||popupClassName==""?"frame800":popupClassName);
        o.showTitleAsCaption    = typeof(showTitleAsCaption)=="boolean"?showTitleAsCaption:false;

        // Get Caption?
        if(o.showTitleAsCaption === true){
            o.theCaption = content.title?content.title:content.getProperty("title");
        }

        if(o.showClose === true){
            o.alertContent        = "<div id='popupClose"+uniqueId+"' class='popupClose'><a href='Javascript:void(0)' onclick='myPopup.close()'><img src='"+myEnv.get("imgPath")+"/iconsmall_close.png' width='32' height='32' alt='Close Window' title='Close' /></a></div>";
        } else {
            o.alertContent      = "";
        }

        // Darken Screen
        myScreenBrightness.darken();

        // Create main element
        o.popupBox = new Element('div', {
            'styles': {
                'visibility' : 'hidden',
                'position': 'absolute',
                'top':0+"px",
                'left':0+"px",
                'z-index'    : 500+(this.layers.length+myScreenBrightness.layers.length)
            },
            "id" : ("popupBox"+uniqueId),
            "class" : o.popupClassName+" popupBoxGlobal"
        });

        // Inject onto page
        o.popupBox.injectInside(document.body);

        // Set standard box HTML
        o.popupBox.set("html",
                "<div id='popupBoxInner"+uniqueId+"' class='popupInner'>"
            +    "<div id='popupBoxContentArea"+uniqueId+"' class='popupContent'></div>"
            +    "<div style='clear:both;height:1px;font-size:1px' class='clear'>&nbsp;</div>"
            +    "</div>"
            +    "<div class='popupBottomBar' style='clear:both'>"+o.alertContent+"</div>"
        );

        o.popupBox          = $("popupBox"+uniqueId);
        o.popupBoxContent   = $("popupBoxContentArea"+uniqueId);
        o.popupBoxInner     = $("popupBoxInner"+uniqueId);
        o.popupWidth        = o.popupBox.getStyle("width").toInt();
        o.emptyHeight       = o.popupBox.getCoordinates().height;
        o.contentBg         = o.popupBoxContent.getStyle("background-color");
        o.contentFg         = o.popupBoxContent.getStyle("color");
        o.contentPad        = o.popupBoxContent.getStyle("padding");
        delete o;
        this.fetchContent(content,false);
    }

    // Update content of currently active popup
    this.update = function(content){
        obj = this.getMostRecentObject();
        obj.popupBox.setStyle("height","auto");
        obj.popupBoxInner.setStyle("height","auto");
        this.fetchContent(content,true);
    }

    // Prepare show function
    this.showContent = function(content,isLoader){
        obj = myPopup.getMostRecentObject();

        // Write imported content first?
        if(typeof(content) == "string"){

            // Update content if it's a direct link to an image
            content = myPopup.updateIfJustImage(content);

            obj.popupBox.setStyle("top","0px");
            obj.popupBox.setStyle("height","auto");
            obj.popupBoxContent.setStyle("height","auto");
            obj.popupBoxContent.set("html",content);
        }

        // Calculate new size
        var newInner = myPopup.calculateNewSize(isLoader);
    }

    this.showUpdatedContent = function(content,isLoader){
        obj = myPopup.getMostRecentObject();
        myScroller.stop("popupBoxInner"+obj.id);

        // Write imported content first?
        if(typeof(content) == "string"){

            // Update content if it's a direct link to an image
            content = myPopup.updateIfJustImage(content);

            obj.popupBoxContent.setStyle("height","auto");
            obj.popupBoxContent.set("html",content);
        }

       // Calculate new size
        var newInner = myPopup.calculateNewSize(isLoader);
    }

    // Fetch content and show
    this.fetchContent = function(content,isUpdate){
        obj = myPopup.getMostRecentObject();

        // Get Content
        if(typeof(content) == "object"){

            // Are we getting content from an ajax call using the link on the A tag?
            if(content.tagName == "A"){
                myAjax.doRequest(content.href,this.popupBoxContent,(isUpdate?this.showUpdatedContent:this.showContent),(isUpdate?this.showUpdatedcontent:this.showContent));
            } else {
                // Must be getting content from inside an existing element so get its innerHTML
                $("popupBoxContentArea"+obj.id).innerHTML = content.innerHTML;
                if(isUpdate){
                    this.showUpdatedContent();
                } else {
                    this.showContent();
                }
            }
        } else
        if(content.charAt(0) == "/"){
            myAjax.doRequest(content,this.popupBoxContent,(isUpdate?this.showUpdatedContent:this.showContent),(isUpdate?this.showUpdatedcontent:this.showContent));
        } else {
            // Normal insert
            $("popupBoxContentArea"+obj.id).innerHTML = content;
            if(isUpdate){
                this.showUpdatedcontent();
            } else {
                this.showContent();
            }
        }
    }

    this.updateIfJustImage = function(content){
        obj = myPopup.getMostRecentObject();

        if(content.substr(0,5) == "<img " || content.substr(0,5) == "<IMG "){
            var geturl      = new RegExp(/src="([^"]+)/i);
            var url         = geturl.exec(content)[1];
            if(content.indexOf("?") > -1){
                url2 = url.split("?");
                url = url2[0];
            }

            var file = url.split("/");
            filename = file.pop();
            content = "<div style='text-align:center;min-height:300px;'><img src='"+url+"' /></div>";

            // Is there a caption?
            if(obj.theCaption != ""){
                content = "<div class='caption'><strong>What are you seeing?</strong><br />"+obj.theCaption+"</div>"+content;
            }
        }
        return content;
    }

    this.calculateNewSize = function(isLoader){

        obj = myPopup.getMostRecentObject();

        // Default height
        var boxHeight    = obj.popupBox.getSize().y;
        var newInner   = false;

        // Don't worry about this for load because the loader isn't doing anything drastic
        // to the height anyway!!
        if(isLoader != "loader"){

            if((boxHeight + 50) > window.getHeight()){
                newInner = true;
                boxHeight = window.getHeight()-100;
                obj.popupBox.setStyle("height",boxHeight+"px");
            }

            // Opera and > IE 7 don't like overflow
            if(myEnv.browserIE6){
                myPopup.overflowFix(boxHeight);
            } else {
                if(newInner === true){
                    obj.popupBoxInner.setStyle("height",(boxHeight-obj.emptyHeight)+"px");
                    obj.popupBoxInner.setStyle("overflow","auto");
                }
            }
        }

        var startTop    = window.getScrollTop()+((window.getHeight() - boxHeight) / 2);
        var startLeft    = (window.getWidth() - obj.popupWidth) / 2;

        // Re-position the popup box
        obj.popupBox.setStyles({
            "visibility"    : "visible",
            "top"            : (startTop)+"px",
            "left"            : startLeft+"px"
        });
        return newInner;
    }

    // Close last opened popup
    this.close = function(obj){
        obj = myPopup.getMostRecentObject();

        if(obj.showClose === true){
            $("popupClose"+obj.id).dispose();
        }

        myPopup.layers.pop();

        // This might not exist if the popup used an iframe (< IE 7) to get content
        if($("popupBoxContentArea"+obj.id)){
            $("popupBoxContentArea"+obj.id).empty();
            $("popupBoxContentArea"+obj.id).dispose();
            $("popupBoxInner"+obj.id).empty();
            $("popupBoxInner"+obj.id).dispose();
        }
        $("popupBox"+obj.id).empty();
        $("popupBox"+obj.id).dispose();
        myScreenBrightness.undarken();
        return true;
    }

    // Create iFrame for Opera and < IE7 to replicate "overflow:auto" command
    this.overflowFix = function(boxHeight){
        obj = myPopup.getMostRecentObject();

        var operaFrame = new Element('iframe', {
            'styles': {
                'width'        : "100%",
                'height'    : (boxHeight-obj.emptyHeight)+"px",
                'display'    : "none",
                'border'    : "none"
            },
            'frameborder'    : 0
        });
        var innerContent = obj.popupBoxContent.innerHTML;
        obj.popupBoxInner.innerHTML = "";

        obj.popupBoxInner.setStyle("padding","0px");
        operaFrame.injectInside(obj.popupBoxInner);
        if(operaFrame.contentDocument){
             doc = operaFrame.contentDocument; // For NS6
        }else if(operaFrame.contentWindow){
            doc = operaFrame.contentWindow.document; // For IE5.5 and IE6
        }
        var sSheets="";
        for(var i=0;i<document.styleSheets.length;i++){
            sSheets += "<link rel='stylesheet' type='text/css' href='"+document.styleSheets[i].href+"' /></head>";
        }
        doc.open();
        doc.write(myEnv.docType+"<head>"+sSheets+"</head><body style='margin:0px;padding:"+obj.contentPad+";width:90%;background-image:none;color:"+obj.contentFg+";background-color:"+obj.contentBg+"'>"+innerContent+"</body></html>");
        doc.close();
        operaFrame.setStyle("display","block");
    }
}

var myHoverEffect = new function(){
    this.c = 0;
    this.o = new Object();
    this.start = function(opts){
        //Check options
        if(typeof(opts.duration) == "undefined"){
            opts.duration = new Object();
            opts.duration.enter = 500;
            opts.duration.leave = 500;
        } else {
            opts.duration.enter = typeof(opts.duration.enter)=="undefined"?500:opts.duration.enter;
            opts.duration.leave = typeof(opts.duration.leave)=="undefined"?500:opts.duration.leave;
        }

        this.o[opts.id] = new Object();
        this.o[opts.id].opts = opts;
        $$(opts.elements).each(function(el){
            if(!el.hasClass("active")){
                this.c++;
                this.o[opts.id]["m"+this.c]          = new Object();
                this.o[opts.id]["m"+this.c].fx       = new Fx.Morph(el, {duration: opts.duration.enter, transition: Fx.Transitions.Sine.easeIn});
                this.o[opts.id]["m"+this.c].fx2      = new Fx.Morph(el, {duration: opts.duration.leave, transition: Fx.Transitions.Sine.easeIn});
                el.setProperty("id","m"+this.c);
                el.addEvents({
                    "mouseenter" : function(){
                        el.setStyles(this.opts.leave);
                        this[el.id].started = true;
                        this[el.id].fx.pause();
                        this[el.id].fx2.pause();
                        this[el.id].fx.start(this.opts.enter);
                    }.bind(this.o[opts.id]),

                    "mouseleave" : function(){
                        if(this[el.id].started === true){
                            this[el.id].fx.pause();
                            this[el.id].fx2.pause();
                            this[el.id].fx2.start(this.opts.leave);
                            this[el.id].started = false;
                        }
                    }.bind(this.o[opts.id])
                });
            }
        }.bind(this));
    }
}

// Do a fix to make all images contain same alt without ruining the
// accessibility side. (Duplicate alts inside same link would confuse readers).
function fixTopMenu(){
	return "";
	/*
    $$("#tpl_topmenu ul li a").each(function(el){
        var i = el.getElements("img");
        el.setProperty("title",i[1].getProperty("alt"));
        i[0].setProperty("alt",null);
        i[1].setProperty("alt",null);
    });
    */
}
