


// faq's script


var ddaccordion={

	

	contentclassname:{}, //object to store corresponding contentclass name based on headerclass



	expandone:function(headerclass, selected){ //PUBLIC function to expand a particular header

		this.toggleone(headerclass, selected, "expand")

	},



	collapseone:function(headerclass, selected){ //PUBLIC function to collapse a particular header

		this.toggleone(headerclass, selected, "collapse")

	},



	expandall:function(headerclass){ //PUBLIC function to expand all headers based on their shared CSS classname

		var $=jQuery

		var $headers=$('.'+headerclass)

		$('.'+this.contentclassname[headerclass]+':hidden').each(function(){

			$headers.eq(parseInt($(this).attr('contentindex'))).trigger("evt_accordion")

		})

	},



	collapseall:function(headerclass){ //PUBLIC function to collapse all headers based on their shared CSS classname

		var $=jQuery

		var $headers=$('.'+headerclass)

		$('.'+this.contentclassname[headerclass]+':visible').each(function(){

			$headers.eq(parseInt($(this).attr('contentindex'))).trigger("evt_accordion")

		})

	},



	toggleone:function(headerclass, selected, optstate){ //PUBLIC function to expand/ collapse a particular header

		var $=jQuery

		var $targetHeader=$('.'+headerclass).eq(selected)

		var $subcontent=$('.'+this.contentclassname[headerclass]).eq(selected)

		if (typeof optstate=="undefined" || optstate=="expand" && $subcontent.is(":hidden") || optstate=="collapse" && $subcontent.is(":visible"))

			$targetHeader.trigger("evt_accordion")

	},



	expandit:function($targetHeader, $targetContent, config, useractivated){

		ddaccordion.collapseall('toggler');

		$targetContent.slideDown(config.animatespeed, function(){config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), useractivated)})

		this.transformHeader($targetHeader, config, "expand")

	},



	collapseit:function($targetHeader, $targetContent, config, isuseractivated){

		$targetContent.slideUp(config.animatespeed, function(){config.onopenclose($targetHeader.get(0), parseInt($targetHeader.attr('headerindex')), $targetContent.css('display'), isuseractivated)})

		this.transformHeader($targetHeader, config, "collapse")

	},



	transformHeader:function($targetHeader, config, state){

		$targetHeader.addClass((state=="expand")? config.cssclass.expand : config.cssclass.collapse) //alternate btw "expand" and "collapse" CSS classes

		.removeClass((state=="expand")? config.cssclass.collapse : config.cssclass.expand)

		if (config.htmlsetting.location=='src'){ //Change header image (assuming header is an image)?

			$targetHeader=($targetHeader.is("img"))? $targetHeader : $targetHeader.find('img').eq(0) //Set target to either header itself, or first image within header

			$targetHeader.attr('src', (state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse) //change header image

		}

		else if (config.htmlsetting.location=="prefix") //if change "prefix" HTML, locate dynamically added ".accordprefix" span tag and change it

			$targetHeader.find('.accordprefix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse)

		else if (config.htmlsetting.location=="suffix")

			$targetHeader.find('.accordsuffix').html((state=="expand")? config.htmlsetting.expand : config.htmlsetting.collapse)

	},



	urlparamselect:function(headerclass){

		var result=window.location.search.match(new RegExp(headerclass+"=((\\d+)(,(\\d+))*)", "i")) //check for "?headerclass=2,3,4" in URL

		if (result!=null)

			result=RegExp.$1.split(',')

		return result //returns null, [index], or [index1,index2,etc], where index are the desired selected header indices

	},



	getCookie:function(Name){ 

		var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair

		if (document.cookie.match(re)) //if cookie found

			return document.cookie.match(re)[0].split("=")[1] //return its value

		return null

	},



	setCookie:function(name, value){

		document.cookie = name + "=" + value + "; path=/"

	},



	init:function(config){

	document.write('<style type="text/css">\n')

	document.write('.'+config.contentclass+'{display: none}\n') //generate CSS to hide contents

	document.write('<\/style>')

	jQuery(document).ready(function($){

		ddaccordion.urlparamselect(config.headerclass)

		var persistedheaders=ddaccordion.getCookie(config.headerclass)

		ddaccordion.contentclassname[config.headerclass]=config.contentclass //remember contentclass name based on headerclass

		config.cssclass={collapse: config.toggleclass[0], expand: config.toggleclass[1]} //store expand and contract CSS classes as object properties

		config.revealtype=/^(click)|(mouseover)$/i.test(config.revealtype)? config.revealtype.replace(/mouseover/i, "mouseenter") : "click"

		config.htmlsetting={location: config.togglehtml[0], collapse: config.togglehtml[1], expand: config.togglehtml[2]} //store HTML settings as object properties

		config.oninit=(typeof config.oninit=="undefined")? function(){} : config.oninit //attach custom "oninit" event handler

		config.onopenclose=(typeof config.onopenclose=="undefined")? function(){} : config.onopenclose //attach custom "onopenclose" event handler

		var lastexpanded={} //object to hold reference to last expanded header and content (jquery objects)

		var expandedindices=ddaccordion.urlparamselect(config.headerclass) || ((config.persiststate && persistedheaders!=null)? persistedheaders : config.defaultexpanded)

		if (typeof expandedindices=='string') //test for string value (exception is config.defaultexpanded, which is an array)

			expandedindices=expandedindices.replace(/c/ig, '').split(',') //transform string value to an array (ie: "c1,c2,c3" becomes [1,2,3]

		var $subcontents=$('.'+config["contentclass"])

		if (expandedindices.length==1 && expandedindices[0]=="-1") //check for expandedindices value of [-1], indicating persistence is on and no content expanded

			expandedindices=[]

		if (config["collapseprev"] && expandedindices.length>1) //only allow one content open?

			expandedindices=[expandedindices.pop()] //return last array element as an array (for sake of jQuery.inArray())

		if (config["onemustopen"] && expandedindices.length==0) //if at least one content should be open at all times and none are, open 1st header

			expandedindices=[0]

		$('.'+config["headerclass"]).each(function(index){ //loop through all headers

			if (/(prefix)|(suffix)/i.test(config.htmlsetting.location) && $(this).html()!=""){ //add a SPAN element to header depending on user setting and if header is a container tag

				$('<span class="accordprefix"></span>').prependTo(this)

				$('<span class="accordsuffix"></span>').appendTo(this)

			}

			$(this).attr('headerindex', index+'h') //store position of this header relative to its peers

			$subcontents.eq(index).attr('contentindex', index+'c') //store position of this content relative to its peers

			var $subcontent=$subcontents.eq(index)

			var needle=(typeof expandedindices[0]=="number")? index : index+'' //check for data type within expandedindices array- index should match that type

			if (jQuery.inArray(needle, expandedindices)!=-1){ //check for headers that should be expanded automatically (convert index to string first)

				if (config.animatedefault==false)

					$subcontent.show()

				ddaccordion.expandit($(this), $subcontent, config, false) //Last Boolean value sets 'isuseractivated' parameter

				lastexpanded={$header:$(this), $content:$subcontent}

			}  //end check

			else{

				$subcontent.hide()

				config.onopenclose($(this).get(0), parseInt($(this).attr('headerindex')), $subcontent.css('display'), false) //Last Boolean value sets 'isuseractivated' parameter

				ddaccordion.transformHeader($(this), config, "collapse")

			}

		})

		$('.'+config["headerclass"]).bind("evt_accordion", function(){ //assign custom event handler that expands/ contacts a header

				var $subcontent=$subcontents.eq(parseInt($(this).attr('headerindex'))) //get subcontent that should be expanded/collapsed

				if ($subcontent.css('display')=="none"){

					ddaccordion.expandit($(this), $subcontent, config, true) //Last Boolean value sets 'isuseractivated' parameter

					if (config["collapseprev"] && lastexpanded.$header && $(this).get(0)!=lastexpanded.$header.get(0)){ //collapse previous content?

						ddaccordion.collapseit(lastexpanded.$header, lastexpanded.$content, config, true) //Last Boolean value sets 'isuseractivated' parameter

					}

					lastexpanded={$header:$(this), $content:$subcontent}

				}

				else if (!config["onemustopen"] || config["onemustopen"] && lastexpanded.$header && $(this).get(0)!=lastexpanded.$header.get(0)){

					ddaccordion.collapseit($(this), $subcontent, config, true) //Last Boolean value sets 'isuseractivated' parameter

				}

 		})

		$('.'+config["headerclass"]).bind(config.revealtype, function(){

			if (config.revealtype=="mouseenter"){

				clearTimeout(config.revealdelay)

				var headerindex=parseInt($(this).attr("headerindex"))

				config.revealdelay=setTimeout(function(){ddaccordion.expandone(config["headerclass"], headerindex)}, config.mouseoverdelay || 0)

			}

			else{

				$(this).trigger("evt_accordion")

				return false //cancel default click behavior

			}

		})

		$('.'+config["headerclass"]).bind("mouseleave", function(){

			clearTimeout(config.revealdelay)

		})

		config.oninit($('.'+config["headerclass"]).get(), expandedindices)

		$(window).bind('unload', function(){ //clean up and persist on page unload

			$('.'+config["headerclass"]).unbind()

			var expandedindices=[]

			$('.'+config["contentclass"]+":visible").each(function(index){ //get indices of expanded headers

				expandedindices.push($(this).attr('contentindex'))

			})

			if (config.persiststate==true){ //persist state?

				expandedindices=(expandedindices.length==0)? '-1c' : expandedindices //No contents expanded, indicate that with dummy '-1c' value?

				ddaccordion.setCookie(config.headerclass, expandedindices)

			}

		})

	})

	}

}


//Initialize FAQ Accordian:
ddaccordion.init({
	headerclass: "question", //Shared CSS class name of headers group
	contentclass: "answer", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: false, //persist state of opened contents within browser session?
	toggleclass: ["closedquestion", "openquestion"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

//porfolio effects
	$(document).ready(function($){
				
				$('.circle').mosaic({
					opacity		:	0.8			//Opacity for overlay (0-1)
				});
				
				$('.fade').mosaic();
				
				$('.bar').mosaic({
					animation	:	'slide'		//fade or slide
				});
				
				$('.bar2').mosaic({
					animation	:	'slide'		//fade or slide
				});
				
				$('.bar3').mosaic({
					animation	:	'slide',	//fade or slide
					anchor_y	:	'top'		//Vertical anchor position
				});
				
				$('.cover').mosaic({
					animation	:	'slide',	//fade or slide
					hover_x		:	'400px'		//Horizontal position on hover
				});
				
				$('.cover2').mosaic({
					animation	:	'slide',	//fade or slide
					anchor_y	:	'top',		//Vertical anchor position
					hover_y		:	'80px'		//Vertical position on hover
				});
				
				$('.cover3').mosaic({
					animation	:	'slide',	//fade or slide
					hover_x		:	'400px',	//Horizontal position on hover
					hover_y		:	'300px'		//Vertical position on hover
				});

		    
		    });

// Remove the title tag pop up on hover images

jQuery(document).ready(function(){
 
                jQuery("li.cat-item a").each(function(){
                    jQuery(this).removeAttr('title');
                })                
 
                jQuery("li.page_item a").each(function(){
                    jQuery(this).removeAttr('title');
                })
				
				 jQuery("img").each(function(){
                    jQuery(this).removeAttr('title');
                })
 
        });
        
// Jquery slow scroll to the top of the page        
       
$(document).ready(function() {
    $('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });

});



// Twitter functions
 
(function($){$.fn.tweetable=function(options){var defaults={limit:5,username:'philipbeel',time:false};var options=$.extend(defaults,options);return this.each(function(options){var act=$(this);var api="http://twitter.com/statuses/user_timeline/";var count="?count=";$.getJSON(api+defaults.username+".json"+count+defaults.limit+"&callback=?",act,function(data){$.each(data,function(i,item){if(i==0){$(act).prepend('<ul class="tweetList"><li class="tweet_content_'+i+'">')}else{$('.tweetList').append('<li class="tweet_content_'+i+'">')}$('.tweet_content_'+i+'').append('<span class="tweet_link_'+i+'">'+item.text.replace(/#(.*?)(\s|$)/g,'<span class="hash">#$1 </span>').replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,'<a href="$&">$&</a> ').replace(/@(.*?)(\s|\(|\)|$)/g,'<a href="http://twitter.com/$1">@$1 </a>$2'));if(defaults.time==true){$('.tweet_content_'+i).append('<small> '+item.created_at.substr(0,20)+'</small>')}})})})}})(jQuery);

	$(function(){
	 $('#tweets').tweetable({username: 'ashercharles', time: false, limit: 3});
	});

// Live validation

(function (jQuery) {
    var ValidationErrors = new Array();
    jQuery.fn.validate = function (options) {
        options = jQuery.extend({
            expression: "return true;",
            message: "",
            error_class: "ValidationErrors",
            error_field_class: "ErrorField",
            live: true
        }, options);
        var SelfID = jQuery(this).attr("id");
        var unix_time = new Date();
        unix_time = parseInt(unix_time.getTime() / 1000);
        if (!jQuery(this).parents('form:first').attr("id")) {
            jQuery(this).parents('form:first').attr("id", "Form_" + unix_time)
        }
        var FormID = jQuery(this).parents('form:first').attr("id");
        if (!((typeof (ValidationErrors[FormID]) == 'object') && (ValidationErrors[FormID] instanceof Array))) {
            ValidationErrors[FormID] = new Array()
        }
        if (options['live']) {
            if (jQuery(this).find('input').length > 0) {
                jQuery(this).find('input').bind('blur', function () {
                    if (validate_field("#" + SelfID, options)) {
                        if (options.callback_success) options.callback_success(this)
                    } else {
                        if (options.callback_failure) options.callback_failure(this)
                    }
                });
                jQuery(this).find('input').bind('focus keypress click', function () {
                    jQuery("#" + SelfID).next('.' + options['error_class']).remove();
                    jQuery("#" + SelfID).removeClass(options['error_field_class'])
                })
            } else {
                jQuery(this).bind('blur', function () {
                    validate_field(this)
                });
                jQuery(this).bind('focus keypress', function () {
                    jQuery(this).next('.' + options['error_class']).fadeOut("fast", function () {
                        jQuery(this).remove()
                    });
                    jQuery(this).removeClass(options['error_field_class'])
                })
            }
        }
        jQuery(this).parents("form").submit(function () {
            if (validate_field('#' + SelfID)) return true;
            else return false
        });

        function validate_field(id) {
            var self = jQuery(id).attr("id");
            var expression = 'function Validate(){' + options['expression'].replace(/VAL/g, 'jQuery(\'#' + self + '\').val()') + '} Validate()';
            var validation_state = eval(expression);
            if (!validation_state) {
                if (jQuery(id).next('.' + options['error_class']).length == 0) {
                    jQuery(id).after('<span class="' + options['error_class'] + '">' + options['message'] + '</span>');
                    jQuery(id).addClass(options['error_field_class'])
                }
                if (ValidationErrors[FormID].join("|").search(id) == -1) ValidationErrors[FormID].push(id);
                return false
            } else {
                for (var i = 0; i < ValidationErrors[FormID].length; i++) {
                    if (ValidationErrors[FormID][i] == id) ValidationErrors[FormID].splice(i, 1)
                }
                return true
            }
        }
    };
    jQuery.fn.validated = function (callback) {
        jQuery(this).each(function () {
            if (this.tagName == "FORM") {
                jQuery(this).submit(function () {
                    if (ValidationErrors[jQuery(this).attr("id")].length == 0) callback();
                    return false
                })
            }
        })
    }
})(jQuery);
jQuery(function () {
    jQuery("#ValidFirstName").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidLastName").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidCompany").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidIndustry").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidAddress").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidSuburb").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidState").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidPostcode").validate({
        expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
        message: "Not a valid number"
    });
    jQuery("#ValidEnquiry").validate({
        expression: "This field is required"
    });
    jQuery("#ValidNumber").validate({
        expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
        message: "Not a valid number"
    });
    jQuery("#ValidEmail").validate({
        expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
        message: "Email address is not valid"
    });
    jQuery("#ValidFindus").validate({
        expression: "if (VAL != '0') return true; else return false;",
        message: "You haven't made a selection"
    });
    jQuery("#ValidEnquiryType").validate({
        expression: "if (VAL != '0') return true; else return false;",
        message: "You haven't made a selection"
    });
    jQuery("#ValidTitle").validate({
        expression: "if (VAL != '0') return true; else return false;",
        message: "You haven't made a selection"
    });
    jQuery("#ValidField").validate({
        expression: "if (VAL) return true; else return false;",
        message: "This field is required"
    });
    jQuery("#ValidNumber").validate({
        expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
        message: "Please enter a valid number"
    });
      jQuery("#ValidMultiSelection").validate({
        expression: "if (VAL) return true; else return false;",
        message: "Please make a selection"
    });
    jQuery("#ValidRadio").validate({
        expression: "if (isChecked(SelfID)) return true; else return false;",
        message: "Please select a radio button"
    });
    jQuery("#ValidCheckbox").validate({
        expression: "if (isChecked(SelfID)) return true; else return false;",
        message: "Please check at least one checkbox"
    });
    jQuery("#ValidPassword").validate({
        expression: "if (VAL.length > 5 && VAL) return true; else return false;",
        message: "Please enter a valid Password"
    });
    jQuery("#ValidConfirmPassword").validate({
        expression: "if ((VAL == jQuery('#ValidPassword').val()) && VAL) return true; else return false;",
        message: "Confirm password field doesn't match the password field"
    });
    jQuery("#ValidSelection").validate({
        expression: "if (VAL != '0') return true; else return false;",
        message: "Please make a selection"
    });
    jQuery("#ValidInteger").validate({
        expression: "if (VAL.match(/^[0-9]*$/) && VAL) return true; else return false;",
        message: "Please enter a valid integer"
    });
    jQuery("#ValidDate").validate({
        expression: "if (!isValidDate(parseInt(VAL.split('-')[2]), parseInt(VAL.split('-')[0]), parseInt(VAL.split('-')[1]))) return false; else return true;",
        message: "Please enter a valid Date"
    });
    jQuery('.AdvancedForm').validated(function () {
        alert("Use this call to make AJAX submissions.")
    })
});

/*
	Mosaic - Sliding Boxes and Captions jQuery Plugin
	Version 1.0.1
	www.buildinternet.com/project/mosaic
	
	By Sam Dunn / One Mighty Roar (www.onemightyroar.com)
	Released under MIT License / GPL License
*/

(function(a){if(!a.omr){a.omr=new Object()}a.omr.mosaic=function(c,b){var d=this;d.$el=a(c);d.el=c;d.$el.data("omr.mosaic",d);d.init=function(){d.options=a.extend({},a.omr.mosaic.defaultOptions,b);d.load_box()};d.load_box=function(){if(d.options.preload){a(d.options.backdrop,d.el).hide();a(d.options.overlay,d.el).hide();a(window).load(function(){if(d.options.options.animation=="fade"&&a(d.options.overlay,d.el).css("opacity")==0){a(d.options.overlay,d.el).css("filter","alpha(opacity=0)")}a(d.options.overlay,d.el).fadeIn(200,function(){a(d.options.backdrop,d.el).fadeIn(200)});d.allow_hover()})}else{a(d.options.backdrop,d.el).show();a(d.options.overlay,d.el).show();d.allow_hover()}};d.allow_hover=function(){switch(d.options.animation){case"fade":a(d.el).hover(function(){a(d.options.overlay,d.el).stop().fadeTo(d.options.speed,d.options.opacity)},function(){a(d.options.overlay,d.el).stop().fadeTo(d.options.speed,0)});break;case"slide":startX=a(d.options.overlay,d.el).css(d.options.anchor_x)!="auto"?a(d.options.overlay,d.el).css(d.options.anchor_x):"0px";startY=a(d.options.overlay,d.el).css(d.options.anchor_y)!="auto"?a(d.options.overlay,d.el).css(d.options.anchor_y):"0px";var f={};f[d.options.anchor_x]=d.options.hover_x;f[d.options.anchor_y]=d.options.hover_y;var e={};e[d.options.anchor_x]=startX;e[d.options.anchor_y]=startY;a(d.el).hover(function(){a(d.options.overlay,d.el).stop().animate(f,d.options.speed)},function(){a(d.options.overlay,d.el).stop().animate(e,d.options.speed)});break}};d.init()};a.omr.mosaic.defaultOptions={animation:"fade",speed:150,opacity:1,preload:0,anchor_x:"left",anchor_y:"bottom",hover_x:"0px",hover_y:"0px",overlay:".mosaic-overlay",backdrop:".mosaic-backdrop"};a.fn.mosaic=function(b){return this.each(function(){(new a.omr.mosaic(this,b))})}})(jQuery);


/**
 * LavaLamp - A menu plugin for jQuery with cool hover effects.
 * @requires jQuery v1.1.3.1 or above
 *
 * http://gmarwaha.com/blog/?p=7
 *
 * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 0.2.0
 * Requires Jquery 1.2.1 from version 0.2.0 onwards. 
 * For jquery 1.1.x, use version 0.1.0 of lavalamp
 */

/**
 * Creates a menu with an unordered list of menu-items. You can either use the CSS that comes with the plugin, or write your own styles 
 * to create a personalized effect
 *
 * The HTML markup used to build the menu can be as simple as...
 *
 *       <ul class="lavaLamp">
 *           <li><a href="#">Home</a></li>
 *           <li><a href="#">Plant a tree</a></li>
 *           <li><a href="#">Travel</a></li>
 *           <li><a href="#">Ride an elephant</a></li>
 *       </ul>
 *
 * Once you have included the style sheet that comes with the plugin, you will have to include 
 * a reference to jquery library, easing plugin(optional) and the LavaLamp(this) plugin.
 *
 * Use the following snippet to initialize the menu.
 *   $(function() { $(".lavaLamp").lavaLamp({ fx: "backout", speed: 700}) });
 *
 * Thats it. Now you should have a working lavalamp menu. 
 *
 * @param an options object - You can specify all the options shown below as an options object param.
 *
 * @option fx - default is "linear"
 * @example
 * $(".lavaLamp").lavaLamp({ fx: "backout" });
 * @desc Creates a menu with "backout" easing effect. You need to include the easing plugin for this to work.
 *
 * @option speed - default is 500 ms
 * @example
 * $(".lavaLamp").lavaLamp({ speed: 500 });
 * @desc Creates a menu with an animation speed of 500 ms.
 *
 * @option click - no defaults
 * @example
 * $(".lavaLamp").lavaLamp({ click: function(event, menuItem) { return false; } });
 * @desc You can supply a callback to be executed when the menu item is clicked. 
 * The event object and the menu-item that was clicked will be passed in as arguments.
 */
(function($) {
$.fn.lavaLamp = function(o) {
    o = $.extend({ fx: "linear", speed: 500, click: function(){} }, o || {});

    return this.each(function() {
        var me = $(this), noop = function(){},
            $back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
            $li = $("li", this), curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];

        $li.not(".back").hover(function() {
            move(this);
        }, noop);

        $(this).hover(noop, function() {
            move(curr);
        });

        $li.click(function(e) {
            setCurr(this);
            return o.click.apply(this, [e, this]);
        });

        setCurr(curr);

        function setCurr(el) {
            $back.css({ "left": el.offsetLeft+"px", "width": el.offsetWidth+"px" });
            curr = el;
        };

        function move(el) {
            $back.each(function() {
                $(this).dequeue(); }
            ).animate({
                width: el.offsetWidth,
                left: el.offsetLeft
            }, o.speed, o.fx);
        };

    });
};
})(jQuery);


$(function() { $(".lavaLamp").lavaLamp({ fx: "backout", speed: 700}) });

