/**
* 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)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};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);

function init()
{
    if ($('#glossary')) {
	$('#glossary dd').css('display', 'none');
	$('#glossary dt').click(function(){
		if ($(this).next().css('display') == 'none')
		{
			$(this).next().css('display', 'block');
		}
		else
		{
			$(this).next().css('display', 'none');
		}
	});
    };

    if ($('#model_configuration')) {
	$('#model_configuration .configuration ul li a').click(function(){
		img = $(this).children('img:first');
		url = $(img).attr('src').substring(0, $(img).attr('src').lastIndexOf('/')) + '/original.jpg';
		window.open(url, 'model_configuratin', 'resizable=no,status=no,location=no,menubar=no,width=690,height=515');
		return false;
	});
	$('#model_configuration .configuration ul img').mouseover(function(){
		$('#large_image').attr('src', $(this).attr('src').substring(0, $(this).attr('src').lastIndexOf('/')) + '/thumb.jpg');
	});
	
	$('#model_configuration_new .configuration ul li a').click(function(){
		$('#model_configuration_new .configuration ul li a').removeClass('current');
		$(this).addClass('current');
		$('#large_image').attr('src', $(this).attr('href'));
		$('#colour_name').text($(this).attr('title'));
		return false;
	});
	$('#model_configuration .configuration ul img').hover(
	function(){
		$('#colour_name').text($(this).attr('title'));
	},
	function(){
		$('#colour_name').text($('#model_configuration_new .configuration ul li a.current').attr('title'));
	});	
    };
    
    if ($('#content')) {
	$('#content .main a.popup').each(function(){
		$(this).append('<span>' + $(this).prevAll('h4:first').text() + '</span>');
		$(this).wrap('<div class="popup"></div>');
		$(this).parent().css('height', $(this).height());
		$(this).click(function(){
			if ($(this).parent().is('.active'))
			{
				$(this).parent().removeClass('active');
				$(this).css('z-index', 1000);
			}
			else
			{
				$('#content .main div.popup').removeClass('active');
				$('#content .main div.popup a.popup').css('z-index', 1000);
				$(this).parent().addClass('active');
				$(this).css('z-index', 10000);
			}
			return false;
		});
	});
	
	$('#content .faq .inquirer').each(function(){
		$(this).height($(this).next().height());
	});
	
	$('#content .sitemap > li').equalizeCols();
    };

    if ($('#team')) {
	$('#team .team').equalizeCols();
    };
    
    if ($('#sitemap')) {
	$('#sitemap #content .main p a:first').click(function(){
		$('#sitemap #content .sitemap > li > ul > li > ul').css('display', 'none');
		$('#content .sitemap > li').equalizeCols();
		return false;
	});
	$('#sitemap #content .main p a:eq(1)').click(function(){
		$('#sitemap #content .sitemap > li > ul > li > ul').css('display', 'block');
		$('#content .sitemap > li').equalizeCols();
		return false;
	});
	$('#sitemap #content .sitemap > li >  ul > li > ul').css('display', 'none');
	$('#content .sitemap > li').equalizeCols();
    
	$('a[rel="popup"]').click(function(){
		window.open($(this).attr('href'), 'model_configuratin', 'resizable=no,status=no,location=no,menubar=no,width=690,height=515');
		return false;
	});
	
	$('#gallery #content .main ul li a').click(function(){
		$('#gallery #content .main ul li').removeClass('active');
		$(this).parent().addClass('active');
		img = $(this).children('img:first');
		path = $(img).attr('src').substring(0, $(img).attr('src').lastIndexOf('/'));
		$('#large_image').attr('src', path + '/large.jpg');
		
		$('.gallery .controlls .download').attr({href: path + '/original.jpg', target: '_blank'});
		
		if ($(this).parent().next().is('li'))
		{
			next = $(this).parent().next().children('a:first');
			
			$('.gallery .controlls .next').css('visibility', 'visible').unbind('click').click(function(){
				$(next).click();
				return false;
			});
		}
		else
		{
			$('.gallery .controlls .next').css('visibility', 'hidden');
		}
		
		if ($(this).parent().prev('li:last').is('li'))
		{
			prev = $(this).parent().prev('li:first').children('a:first');
			
			$('.gallery .controlls .previous').css('visibility', 'visible').unbind('click').click(function(){
				$(prev).click();
				return false;
			});
		}
		else
		{
			$('.gallery .controlls .previous').css('visibility', 'hidden');
		}
		
		return false;
	});
	$('#gallery #content .main ul li a:first').click();
	
	if ($.browser.msie == true && $.browser.version == '7.0')
	{
		$('#gallery #content .main ul li a').click(function(){$(this).parent().parent().css('position', 'relative').css('left', '8px');});
		$('#gallery #content .main ul li a').hover(function(){$(this).parent().parent().css('position', 'relative').css('left', '8px');},function(){$(this).parent().parent().css('position', 'relative').css('left', '8px');});
	}
	
	$('a[rel="external"]').attr('target', '_blank');
	
        $("#menu > li").hoverIntent(
	    function()
	    {
		$(this).addClass('hovered');
		$('ul', this).slideDown();
	    },
	    function()
	    {
		var li = this;
	        $('ul', this).slideUp('fast', function(){
		    $(li).removeClass('hovered');
	        });
	    }
	);
        
    $('.pgallery li a').click(function(e){
    	e.preventDefault();
    	$('.pgallery img.img').attr('src', $(this).attr('href'));
    });
    $('.pgallery li a').hover(function(e){$(this).click();},function(){})
    $('.used_cars li').css('cursor', 'pointer').css('cursor', 'hand').click(function(){
    	window.location.href = $('a', $(this)).attr('href');    	
    });

    };

}

$(init);

function dcsTrk(a,b,c){} //dummy for innovaton flashes
