

jQuery.fn.initMenu = function() {  
    return this.each(function(){
							//map functions
							jQuery('.map1').live('mouseover mouseout', function(event) {
							jQuery('.mapimg1').stop();
							jQuery('.mapimg2').stop();
							jQuery('.mapimg3').stop();
							jQuery('.mapimg1').css({'display': 'inline'});
							jQuery('.mapimg2').animate({ opacity: 0.0 }, { duration: 100}, {queue: false});
							jQuery('.mapimg3').animate({ opacity: 0.0 }, { duration: 100}, {queue: false});
							jQuery('.mapimg1').animate({ opacity: 1.0 }, { duration: 300}, {queue: false});

							});
							
							jQuery('.map2').live('mouseover mouseout', function(event) {
							jQuery('.mapimg1').stop();
							jQuery('.mapimg2').stop();
							jQuery('.mapimg3').stop();
							jQuery('.mapimg2').css({'display': 'inline'});
							jQuery('.mapimg1').animate({ opacity: 0.0 }, { duration: 100}, {queue: false});
							jQuery('.mapimg3').animate({ opacity: 0.0 }, { duration: 100}, {queue: false});
							jQuery('.mapimg2').animate({ opacity: 1.0 }, { duration: 300}, {queue: false});

							});
								
							jQuery('.map3').live('mouseover mouseout', function(event) {
							jQuery('.mapimg1').stop();
							jQuery('.mapimg2').stop();
							jQuery('.mapimg3').stop();
							jQuery('.mapimg3').css({'display': 'inline'});
							jQuery('.mapimg1').animate({ opacity: 0.0 }, { duration: 100}, {queue: false});
							jQuery('.mapimg2').animate({ opacity: 0.0 }, { duration: 100}, {queue: false});
							jQuery('.mapimg3').animate({ opacity: 1.0 }, { duration: 300}, {queue: false});

							});
	
							//if a brandname is clicked, load the brandpage in lowerbody
							$('.branditem a').die('click').live('click', function(event) {
							event.stopImmediatePropagation();
							  event.preventDefault();
							  
								
								var url = jQuery(this).attr('href');
								
										jQuery('#lowerbody').stop();
										jQuery('#lowerbody').animate({ opacity: 0.0 }, { duration: 200});
										jQuery('#rightcol').load(url+ ' #body2', function() { jQuery('#lowerbody').stop(); jQuery('#lowerbody').animate({ opacity: 1.0 }, { duration: 400 }); }); 
										window.location.hash = url.slice(0, -4);
									event.preventDefault();
								if ( jQuery.browser.msie ) {
							 jQuery('.branditem').css('backgroundPosition', '-181px center');
							 }

							});

							//brand hover ani
							jQuery('.branditem').live('mouseover mouseout', function(event) {

								var thewidth = jQuery(this).find('.brandlink').width(); 
								var theheight = jQuery(this).find('.brandlink').height(); 
							if (event.type == 'mouseover') {
														if ( jQuery.browser.msie ) {
							 jQuery(this).find('.brandlink').css('backgroundPosition', '-181px center');
							 }
								thewidth = (-180 + thewidth + 5) +'px center';
										if (theheight < 28) {
								
									jQuery(this).addClass('brandlinkJS');
									jQuery(this).find('.brandlink').stop();
									jQuery(this).find('.brandlink').animate({backgroundPosition: thewidth}, { duration: 200, easing:'easeOutCubic' });
									}
							} else {
								if (theheight < 28) {
									jQuery(this).removeClass('brandlinkJS');
									jQuery(this).find('.brandlink').stop();
									jQuery(this).find('.brandlink').animate({backgroundPosition: '-181px center'}, { duration: 200, easing:'easeOutCubic' });
								}
							}	
						});

							//left menu hover ani
							jQuery('ul.menu li').live('mouseover mouseout', function(event) {
							if (event.type == 'mouseover') {
							if ( jQuery.browser.msie ) {
							 jQuery(this).find('.menutext').css('backgroundPosition', '-181px center');
							 }
							var thewidth = jQuery(this).find('.menutext').width(); 

							thewidth = (-180 + thewidth + 5) +'px center';
							jQuery(this).addClass('brandlinkJS');
							jQuery(this).find('.menutext').stop();
							jQuery(this).find('.menutext').animate({backgroundPosition: thewidth}, { duration: 200, easing:'easeOutCubic' });
							} else {
							jQuery(this).removeClass('brandlinkJS');
							jQuery(this).find('.menutext').stop();
							jQuery(this).find('.menutext').animate({backgroundPosition: '-181px center'}, { duration: 200, easing:'easeOutCubic' });
							}
							});



	
	
        var theMenu = $(this).get(0);
        $('.acitem', this).hide();
        $('li.expand > .acitem', this).show();
        $('li.expand > .acitem', this).prev().addClass('active');
        $('li a', this).click( function(e) {
			
			//var oldloc = window.location.hash.substring(1, window.location.hash.length);
			//if (oldloc.length <3){oldloc="home";}
			//if (oldloc != "brand" && oldloc != "location" && oldloc != "careers" && oldloc != "contact" && oldloc != "home"){oldloc="brand";}
			
			//jQuery('#flashContent div').animate({ opacity: 0.0 }, { duration: 200} , function(){});
			//jQuery('#flashContent').flash().remove();
			//console.log("removed "+ "#swf"+oldloc);
			
			//var oldurl = oldloc + '.swf';		
			//swfobject.removeSWF("#swf"+oldloc);
			//$('#flashContent').prepend("<div id='swf" + oldloc + "'></div>");
			
			

			var url = jQuery(this).attr('href');
						//var newloc = url.slice(0, -4);
			var newloc = url.slice(0, -4);

			if (url.substring(0, 4) == 'http'){window.location = url;} else {
			$('#flashContent').animate({ opacity: 0.0 }, { duration: 200}, {queue: false},  function(){});
			jQuery('#rightcol').animate({ opacity: 0.0 }, { duration: 100}, {queue: false});
			$('#flashContent').flash().remove();
			$('#flashContent').flash({swf: "assets/" + newloc +".swf", quality: 'low',   width: '100%', height: '100%', wmode: 'transparent'});
			$('#flashContent').animate({ opacity: 1.0 }, { duration: 200},  function(){});
			if (newloc.length <3){newloc="home";}
			window.location.hash = newloc;
			jQuery('#rightcol').load(url+ ' #body2', function() { jQuery('#rightcol').stop(); jQuery('#rightcol').animate({ opacity: 1.0 }, { duration: 200 });Recaptcha.create("6LeT8c0SAAAAAPa-DMfZ2W2b0xeudaurCL37UHi-", "recaptcha_div", {theme: "white"});}); 
				

				e.preventDefault();
                e.stopImmediatePropagation();
			


                var theElement = $(this).next();
                var parent = this.parentNode.parentNode;
                if($(parent).hasClass('noaccordion')) {
                    if(theElement[0] === undefined) {
                        window.location.href = this.href;
                    }
                    $(theElement).slideToggle('normal', function() {
                        if ($(this).is(':visible')) {
                            $(this).prev().addClass('active');
                        }
                        else {
                            $(this).prev().removeClass('active');
                        }    
                    });
                    return false;
                }
                else {
                    if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                        if($(parent).hasClass('collapsible')) {
                            $('.acitem:visible', parent).first().slideUp('normal', 
                            function() {
                                $(this).prev().removeClass('active');
                            }
                        );
                        return false;  
                    }
                    return false;
                }
                if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                    $('.acitem:visible', parent).first().slideUp('normal', function() {
                        $(this).prev().removeClass('active');
                    });
                    theElement.slideDown('normal', function() {
                        $(this).prev().addClass('active');
                    });
                    return false;
                }
            }
        }
		}
    );
	
});
}



$(document).ready(function() {


		
//run slidemenu eventhandlers
$('.menu').initMenu();
//jQuery('#body2').stop();
//jQuery('#body2').animate({ opacity: 1.0 }, { duration: 300 });

BGload();
//check the hashpage is loaded 
var pathname = window.location.pathname;
var tester = pathname.substring(pathname.length-1, pathname.length);
//console.log(tester);
if (tester !="/" || tester !="#" || tester != ""){
var loc = window.location.hash;
var url = loc.substring(1, loc.length) + '.php';
jQuery('#mainframe').stop();
jQuery('#mainframe').animate({ opacity: 0.0 }, { duration: 100});
jQuery('#mainframe').load(url+ ' .wrapper', function() { jQuery('#mainframe').stop();jQuery('#mainframe').css("opacity","0.0"); jQuery('#mainframe').animate({ opacity: 1.0 }, { duration: 200 });$('.menu').initMenu(); }); 
							if ( jQuery.browser.msie ) {
							 jQuery('.branditem').css('backgroundPosition', '-181px center');
							 }

//load form recaptcha
   Recaptcha.create("6LeT8c0SAAAAAPa-DMfZ2W2b0xeudaurCL37UHi-", "recaptcha_div", {
             theme: "white"});

}

function BGload() {


var loc = window.location.hash.substring(1, window.location.hash.length);
			if (loc.length <3){loc='home';}
			if (!loc){loc='home';}
			var url = loc + '.swf';
			
										if ( jQuery.browser.msie ) {
							 $('#noscriptBG').remove();
							 $('#flashContent').flash({swf: 'assets/home.swf' , quality: 'low',   width: '100%', height: '100%', wmode: 'transparent'});
							 } else {
$('#flashContent').css('opacity', '0.0');
		$('#noscriptBG').remove();
		$('#flashContent').flash({swf: "assets/" + url, quality: 'low',   width: '100%', height: '100%', wmode: 'transparent'});

$('#flashContent').animate({ opacity: 1.0 }, { duration: 300},  function(){});

  
}

}



});

