//view all function	
$(document).ready(function() {
    $('.footer-link').hide();
    $('.button-expand a').click(function() {   
    if ($(".footer-link").is(":hidden")) {
    $('.footer-link').slideDown("fast");
	$('.button-expand').addClass('button-collapse');
    } else {
    $('.footer-link').slideUp("fast");
	$('.button-expand').removeClass('button-collapse');
    }
    });
});

jQuery(document).ready(function () {

    jQuery('a[rel^=lightbox]').lightBox({
        imageLoading: themePath + '/lightbox/images/lightbox-ico-loading.gif',
        imageBtnClose: themePath + '/lightbox/images/lightbox-btn-close.gif',
        imageBtnPrev: themePath + '/lightbox/images/lightbox-btn-prev.gif',
        imageBtnNext: themePath + '/lightbox/images/lightbox-btn-next.gif',
        fixedNavigation: true
    });

    var homeBannerLinkFormat = "<a href='#'>&nbsp</a>";
    var homeBannerLinks = jQuery("#home-banner-links");
    var banners = jQuery(".home-banner");
    var bannerCount = banners.size();
    var bannerTimer = null;
    var bannerTimeout = 6000;
    var bannerIndex = 0;
    var bannersInitialized = false;
    var suppressTimes = 0;

    var homeBannerClicked = function (event, param1) {
        if (bannerTimer != null) { clearTimeout(bannerTimer); }

        bannerIndex = jQuery(this).data("index");
        var offset = bannerIndex * 960;

        jQuery("#home-banners").animate({
            marginLeft: -offset + "px"
        });

        jQuery("#home-banner-links a").attr("class", "");
        jQuery(this).attr("class", "selected");

        if (!param1) {
            bannerTimer = setTimeout(rotateBanners, bannerTimeout * 5);
        }
        return false;
    };

    banners.each(function (index) {
        var link = jQuery(homeBannerLinkFormat);
        link.html("B" + index);
        link.data("index", index);
        link.attr("id", "home-banner-link-" + index)
        link.click(homeBannerClicked);
        link.appendTo(homeBannerLinks);
    });

    jQuery(".home-banners").css("width", (banners.size() * 960) + "px");
    var bannerLinks = jQuery("#home-banner-links a");

    var rotateBanners = function () {
        if (bannerTimer != null) { clearTimeout(bannerTimer); }
        bannerIndex++;
        if (bannerIndex >= bannerCount) {
            bannerIndex = 0;
        }
        bannerLinks.eq(bannerIndex).trigger("click", [true]);
        bannerTimer = setTimeout(rotateBanners, bannerTimeout);
    }

    bannerIndex = Math.ceil((Math.random() * bannerCount));
    bannerLinks.eq(bannerIndex).trigger("click", [true]);
    homeBannerLinks.css("display", "block");
    jQuery(".home-banners").css("display", "block");
    bannerTimer = setTimeout(rotateBanners, bannerTimeout);

    var tabLinkClicked = function () {
        var containers = jQuery(this).parent().next(".tab-containers");
        containers.find("div.tab-container").css("display", "none");
        containers.find("div." + jQuery(this).attr("rel")).css("display", "block");
        jQuery(this).parent().find("a").removeClass("tab-selected");
        jQuery(this).addClass("tab-selected");
        return false;
    };

    jQuery(".tab-links a").click(tabLinkClicked);
    jQuery(".tab-links a").eq(0).trigger("click");

    // login box	
    jQuery("#pre-header-login-username").focus(function () {
        if (jQuery(this).val() == "email or username") {
            //jQuery(this).val("");
        }
        //jQuery("#pre-header-login-password").trigger("blur");
    });

    jQuery("#pre-header-login-username").blur(function () {
        if (jQuery(this).val() == "") {
            //jQuery(this).val("email or username");
        }
    });

    jQuery("#pre-header-login-password-fake").focus(function () {
        jQuery(this).hide();
        jQuery("#pre-header-login-password").show();
        jQuery("#pre-header-login-password").focus();
    });

    jQuery("#pre-header-login-password").blur(function () {
        if (jQuery(this).val() == "") {
            jQuery(this).hide();
            jQuery("#pre-header-login-password-fake").val("password");
            jQuery("#pre-header-login-password-fake").show();
        }
    });

    jQuery('#pre-header-login-password,#pre-header-login-username').keypress(function (event) {
        if (event.keyCode == '13') {
            jQuery("#pre-header-login-button").trigger("click");
        }
    });


    jQuery("#pre-header-login-button").click(function () {
        var msg = jQuery("#pre-header-message");
        msg.removeClass("");
        msg.html('');
        var username = jQuery.trim(jQuery("#pre-header-login-username").val());
        var password = jQuery.trim(jQuery("#pre-header-login-password").val());
        if (username == "" || username == "email or username" || password == "") {
            msg.addClass("error");
            msg.html('Username/email and password are required fields.');
        } else {
            var notDefined;
            var url = (basePath == notDefined) ? "" : basePath;

            jQuery.ajax({
                type: "POST",
                url: url + "/demonz-ahah/login",
                dataType: "text",
                data: "username=" + username + "&password=" + password,
                beforeSend: function (XMLHttpRequest) {
                    jQuery("#pre-header-login-form,#pre-header-links").hide();
                    msg.addClass("wait");
                    msg.html('Logging in...Please wait.');
                },
                success: function (data, textStatus) {
                    if (data != "ok") {
                        jQuery("#pre-header-login-form,#pre-header-links").show();
                        msg.addClass("error");
						msg.removeClass("wait")
                        msg.html('Incorrect Username/email or password &ndash; please try again.');
                    } else {
                        msg.addClass("success");
                        msg.html("Login successful. Refreshing page...");
                        location.reload();
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    jQuery("#pre-header-login-form,#pre-header-links").show();
                    msg.addClass("error");
					msg.removeClass("wait")
                    msg.html('Error logging in &ndash; please try again.');
                }
            });

        }

        return false;
    });

    // movie

    var playIntro = function () {

        jQuery.cookie("movie", "true");

        if (bannerTimer != null) { clearTimeout(bannerTimer); }

        jQuery("#header-movie").html('<div id="flashcontainer"><div id="flashcontent">&nbsp;</div><a id="flashcontentclose">Close</a></div>');

        jQuery("#flashcontentclose").click(function () {
            jQuery("#flashcontainer").animate({
                "height": "0px"
            }, 250, "swing", function () {
                jQuery("#header-movie").empty();
                if (bannerTimer != null) { clearTimeout(bannerTimer); }
                bannerTimer = setTimeout(rotateBanners, bannerTimeout);
            });
            return false;
        });

        jQuery("#flashcontainer").animate({
            "height": "489px"
        }, 500, "swing", function () {

            var flashvars = {};
            var params = {};
            var attributes = {};

            params.codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0';
            params.width = '800';
            params.height = '464';
            params.quality = 'high';
            params.align = 'middle';
            params.play = 'true';
            params.loop = 'true';
            params.scale = 'showall';
            params.wmode = 'transparent';
            params.devicefont = 'false';
            //params.bgcolor='#2e2e2e',
            params.allowFullScreen = 'true';
            params.allowScriptAccess = 'sameDomain';
            params.salign = '';

            // SETUP
            /* <![CDATA[ */
            flashvars.forcewidth = '800';
            flashvars.forceheight = '464';
            flashvars.skin = 'black';
            flashvars.fullscreenbutton = 'on';
            flashvars.infobutton = 'on';
            flashvars.startphoto = themePath + '/swf/presentation.jpg';
            flashvars.videopath = 'http://data.imodify.com.au/presentation.flv';
            flashvars.playonload = 'on';
            flashvars.initialvolume = '100';
            flashvars.startbufferonload = 'on';
            // stretch type, choose between 'original size', 'zoom to fit', 'stretch to fit'
            flashvars.defaultstretch = 'stretch to fit';
            flashvars.buffersize = '5';
            flashvars.infotext = "";

            attributes.id = 'video-player';
            /* ]]> */

            swfobject.embedSWF(themePath + '/swf/preview.swf', 'flashcontent', '100%', '100%', '9.0.0', '/js/expressInstall.swf', flashvars, params, attributes);

        });

        return false;
    };

    var playLink = jQuery('<div id="movie-play-link" class="movie-play-link-default">Play Movie</div>');
    playLink.appendTo("#home-banner-links");
    playLink.mouseover(function () {
        jQuery(this).removeClass();
        jQuery(this).addClass('movie-play-link-over');
    });

    playLink.mouseout(function () {
        jQuery(this).removeClass();
        jQuery(this).addClass('movie-play-link-default');
    });

    playLink.click(playIntro);

    if (!jQuery.cookie("movie")) {
        playLink.trigger("click");
    }

    /*	
	
    playLink.mouseleave(function() {
    jQuery(this).removeClass();
    jQuery(this).addClass('movie-play-link-default');
    });
	
    */
    
    
    
    /* GAExtended */
    var GAPageTracker = "UA-13020652-1";
    ////////////////////////////
     
          var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
         
          //use jQuery to call the Google Analytics JavaScript
          jQuery.getScript(gaJsHost + "google-analytics.com/ga.js", function(){
         
                //tell Analytics about the current page load using standard _trackPageview method
                try {
                      var pageTracker = _gat._getTracker(GAPageTracker);
                      pageTracker._trackPageview();
                } catch(err) {}
               
                //loop though each anchor element
                jQuery('a[href]').each(function(){
                     
                      var href = jQuery(this).attr('href');
                      var filetypes = /\.(zip|exe|pdf|vcs|txt|rtf|doc*|xls*|ppt*|mp3)jQuery/i;
                     
                      //check for links starting with http or https, making sure that links to our own domain are excluded
                      if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
                            jQuery(this).click(function() {
                                  var extLink = href.replace(/^https?\:\/\//i, '');
                                  pageTracker._trackEvent('External', 'Click', extLink);
                            });
                      }
                      //check for links starting with mailto:
                      else if (href.match(/^mailto\:/i)){
                            jQuery(this).click(function() {
                                  var mailLink = href.replace(/^mailto\:/i, '');
                                  pageTracker._trackEvent('Email', 'Click', mailLink);
                            });
                      }
                      //check for links with file extension that match the filetypes regular expression:
                      else if (href.match(filetypes)){
                            jQuery(this).click(function() {
                                  var extension = (/[.]/.exec(href)) ? /[^.]+jQuery/.exec(href) : undefined;
                                  var filePath = href.replace(/^https?\:\/\/(www.)imodify\.com\.au\//i, '');
                                  pageTracker._trackEvent('Download', 'Click - ' + extension, filePath);
                            });
                      }
     
                });
               
          });

    ////////////////////////////
    /* End: GAExtended */
    
    
    

}); 

function showText(text) {
	return unescape(text);
}





(function($){
	/* hoverIntent by Brian Cherne */
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
	
})(jQuery);



/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: false,
		dropShadows : false,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);


// initialise plugins
$(document).ready(function() { 
        $('ul.sf-menu').superfish(); 
}); 

