/* Ouformations Scripts
 * Dependant on the 1.1.3.1 version of jQuery <http://jquery.com/>
 * jQuery Plugins:
 * 	hoverIntent r5 <http://cherne.net/brian/resources/jquery.hoverIntent.html>
 */

/*
 * hoverIntent r5 // 2007.03.27 // jQuery 1.1.2
 * <http://cherne.net/brian/resources/jquery.hoverIntent.html>
 * 
 * @param  f  onMouseOver function || An object with configuration options
 * @param  g  onMouseOut function  || Nothing (use configuration options object)
 * @return    The object (aka "this") that called hoverIntent, and the event object
 * @author    Brian Cherne <brian@cherne.net>
 */
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:300};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){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;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/*
 * jQuery pngfix plugin
 * Version 1.5  (23/07/2007)
 * @requires jQuery v1.1.3
 *
 * Examples at: http://khurshid.com/jquery/iepnghack/
 * Copyright (c) 2007 Khurshid M.
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
 /**
  *
  * @example
  *
  * $('img[@src$=.png], #panel').pngfix();
  *
  * @apply hack to all png images and #panel which icluded png img in its css
  *
  * @name pngfix
  * @type jQuery
  * @cat Plugins/Image
  * @return jQuery
  * @author jQuery Community
  */
 
(function($) {
	/**
	 * helper variables and function
	 */
	var hack = {
		ltie7 : $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
		pixel : '/img/design/x.gif',
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		}
	};
	/**
	 * Applies ie png hack to selected dom elements
	 *
	 * $('img[@src$=.png]').pngfix();
	 * @desc apply hack to all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').pngfix();
	 * @desc apply hack to element #panel and all images with png extensions
	 *
	 * @name pngfix
	 * @type jQuery
	 * @cat Plugins/pngfix
	 */
	$.fn.pngfix = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var base = $('base').attr('href'); // need to use this in case you are using rewriting urls
			if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
				if ($$.attr('src').match(/.*\.png$/i)) { // make sure it is png image
					// use source tag value if set 
					var source = (base && $$.attr('src').substring(0,1)!='/') ? base + $$.attr('src') : $$.attr('src');
					// apply filter
					$$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})
					  .attr({src:hack.pixel})
					  .positionFix();
				}
			} else { // hack png css properties present inside css
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
					image = RegExp.$1;
					$$.css({backgroundImage:'none', filter:hack.filter(image)})
					  .positionFix();
				}
			}
		});
	} : function() { return this; };
	/**
	 * Removes any png hack that may have been applied previously
	 *
	 * $('img[@src$=.png]').pngunfix();
	 * @desc revert hack on all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').iepnghack();
	 * @desc revert hack on element #panel and all images with png extensions
	 *
	 * @name pngunfix
	 * @type jQuery
	 * @cat Plugins/iepnghack
	 */
	$.fn.pngunfix = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["']?(.*\.png)["']?/i)) { // get img source from filter
				src = RegExp.$1;
				if ($$.is('img') || $$.is('input')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}
			}
		});
	} : function() { return this; };
	/**
	 * positions selected item relatively
	 */
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};

})(jQuery);

/* Initalize the Page */

$(document).ready(function() {
	initPage();
});

function initPage() {
	// fix the png transparency for IE6;
	$('img[@src$=.png]').pngfix();
	$('img[@src$=.png]').pngfix().pngunfix();	
	// set up the menus
	$('#nav > div.nav').hoverIntent(showMenu,hideMenu);
	
	// set up the buttons - TODO: this could be optimized
	$('#btn_search').hoverIntent(function() {
		$(this).attr('src','/img/design/btn_search-on.png')
	},function() {
		$(this).attr('src','/img/design/btn_search.png')
	});
	
	$('#btn_estimate').hoverIntent(function() {
		$(this).attr('src','/img/design/btn_estimate-on.png')
	},function() {
		$(this).attr('src','/img/design/btn_estimate.png')
	});

	$('#btn_login').hoverIntent(function() {
		$(this).attr('src','/img/design/btn_login-on.png')
	},function() {
		$(this).attr('src','/img/design/btn_login.png')
	});

}


/* Menu Functions */


function showMenu(){ 
	if ($(this).children('a').attr('class') != 'selected') {
		var img = $(this).children('a').children('img');
		$(img).attr('src',menuImage($(img).attr('name'),true));
	}
	$(this).children('div.menu').css('display','block');
}

function hideMenu(){ 
	if ($(this).children('a').attr('class') != 'selected') {
		var img = $(this).children('a').children('img');
		$(img).attr('src',menuImage($(img).attr('name'),false));
	}
	$(this).children('div.menu').css('display','none');
}

function menuImage(menu_name,litUp) {
	var on = (litUp) ? '-on' : '';
	return '/img/design/' + menu_name + on + '.png';
}

/* Search Box Functions */

function toggleBoxWidth(big) {
	var boxWidth = (big) ? "16em" : "10em" ;
    $("#search input").css('width',boxWidth);
}