/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);


/*

jQuery Browser Plugin
	* Version 1.1.0
	* URL: http://jquery.thewikies.com/browser
	* Description: jQuery Browser Plugin extends browser detection capabilities and implements CSS browser selectors.
	* Author: Nate Cavanaugh, Minhchau Dang, & Jonathan Neal
	* Copyright: Copyright (c) 2008 Jonathan Neal under dual MIT/GPL license.

*/

var jQueryBrowser = function() {
	
	// Define whether Browser Selectors will be added automatically; set as false to disable.
	var addSelectors = true;

	// Define Navigator Properties.
	var pl = navigator.platform;
	var ua = navigator.userAgent;

	// Define Browser Properties.
	var ob = {

		// Define the rendering client
		gecko: /Gecko/.test(ua) && !/like Gecko/.test(ua),
		webkit: /WebKit/.test(ua),

		// Define the browser
		aol: /America Online Browser/.test(ua),
		camino: /Camino/.test(ua),
		firefox: /Firefox/.test(ua),
		flock: /Flock/.test(ua),
		icab: /iCab/.test(ua),
		konqueror: /KDE/.test(ua),
		mozilla: /mozilla/.test(ua),
		msie: /MSIE/.test(ua),
		netscape: /Netscape/.test(ua),
		opera: /Opera/.test(ua),
		safari: /Safari/.test(ua),
		browser: /(MSIE|Firefox|Opera|Safari|KDE|iCab|Flock)/.exec(ua)[0],

		// Define the opperating system
		win: /Win/.test(pl),
		mac: /Mac/.test(pl),
		linux: /Linux/.test(pl),
		iphone: /iPhone/.test(pl),
		OS: /(Win|Mac|Linux|iPhone)/.exec(pl)[0],

		// Define the classic navigator properties
		platform: pl,
		agent: ua,

		// Define the 'addSelectors' function which adds Browser Selectors to a tag; by default <HTML>.
		addSelectors: function() {
			jQuery(arguments[0] || 'html').addClass([this.renderer,this.browser,this.browser+this.version.major,this.OS,'js'].join(' ').toLowerCase());
		},

		// Define the 'removeSelectors' function which removes Browser Selectors to a tag; by default <HTML>.
		removeSelectors: function() {
			jQuery(arguments[0] || 'html').removeClass([this.renderer,this.browser,this.browser+this.version.major,this.OS,'js'].join(' ').toLowerCase());
		}

	};

	// Redefine the Rendering Client.
	ob.renderer = (ob.gecko) ? 'gecko' : (ob.webkit) ? 'webkit' : '';

	// Redefine the Browser Client Version.
	ob.version = {};
	ob.version.string  = (ob.msie)
		? /MSIE ([^;]+)/.exec(ua)[1]
		: (ob.firefox)
			? /Firefox\/(.+)/.exec(ua)[1]
			: (ob.safari)
				? /Version\/([^\s]+)/.exec(ua)[1]
				: (ob.opera)
					? /Opera\/([^\s]+)/.exec(ua)[1]
					: '';
	ob.version.number = parseFloat(ob.version.string);
	ob.version.major = /([^\.]+)/.exec(ob.version.string)[1];

	// Run the 'addSelectors' Function if the 'addSelectors' Variable is set as true.
	if (addSelectors) {
		ob.addSelectors();
	}

	// Define the jQuery 'browser' Object.
	jQuery.browser = ob;

}();


// JQUERY FLASH

(function(){var B;B=jQuery.fn.flash=function(G,F,D,I){var H=D||B.replace;F=B.copy(B.pluginOptions,F);if(!B.hasFlash(F.version)){if(F.expressInstall&&B.hasFlash(6,0,65)){var E={flashvars:{MMredirectURL:location,MMplayerType:"PlugIn",MMdoctitle:jQuery("title").text()}}}else{if(F.update){H=I||B.update}else{return this}}}G=B.copy(B.htmlOptions,E,G);return this.each(function(){H.call(this,B.copy(G))})};B.copy=function(){var F={},E={};for(var G=0;G<arguments.length;G++){var D=arguments[G];if(D==undefined){continue}jQuery.extend(F,D);if(D.flashvars==undefined){continue}jQuery.extend(E,D.flashvars)}F.flashvars=E;return F};B.hasFlash=function(){if(/hasFlash\=true/.test(location)){return true}if(/hasFlash\=false/.test(location)){return false}var E=B.hasFlash.playerVersion().match(/\d+/g);var F=String([arguments[0],arguments[1],arguments[2]]).match(/\d+/g)||String(B.pluginOptions.version).match(/\d+/g);for(var D=0;D<3;D++){E[D]=parseInt(E[D]||0);F[D]=parseInt(F[D]||0);if(E[D]<F[D]){return false}if(E[D]>F[D]){return true}}return true};B.hasFlash.playerVersion=function(){try{try{var D=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");try{D.AllowScriptAccess="always"}catch(E){return"6,0,0"}}catch(E){}return new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/\D+/g,",").match(/^,?(.+),?$/)[1]}catch(E){try{if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){return(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g,",").match(/^,?(.+),?$/)[1]}}catch(E){}}return"0,0,0"};B.htmlOptions={height:240,flashvars:{},pluginspage:"http://www.adobe.com/go/getflashplayer",src:"#",type:"application/x-shockwave-flash",width:320};B.pluginOptions={expressInstall:false,update:true,version:"6.0.65"};B.replace=function(D){this.innerHTML='<div class="alt">'+this.innerHTML+"</div>";jQuery(this).addClass("flash-replaced").prepend(B.transform(D))};B.update=function(E){var D=String(location).split("?");D.splice(1,0,"?hasFlash=true&");D=D.join("");var F='<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+D+'">Click here.</a></p>';this.innerHTML='<span class="alt">'+this.innerHTML+"</span>";jQuery(this).addClass("flash-update").prepend(F)};function A(){var E="";for(var D in this){if(typeof this[D]!="function"){E+=D+'="'+this[D]+'" '}}return E}function C(){var E="";for(var D in this){if(typeof this[D]!="function"){E+=D+"="+encodeURIComponent(this[D])+"&"}}return E.replace(/&$/,"")}B.transform=function(D){D.toString=A;if(D.flashvars){D.flashvars.toString=C}return"<embed "+String(D)+"/>"};if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){}})}})();

/*
 * Thickbox 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
		  

// var tb_pathToImage = "/img/site/loading.gif";
var tb_pathToImage = "/img/site/l.gif";

function tb_init(domChunk) {
    $(domChunk).click(function() {
        var t = this.title || this.name || null;
        var a = this.href || this.alt;
        var g = this.rel || false;
        tb_show(t, a, g);
        this.blur();
        return false;
    });
}
function tb_show(caption, url, imageGroup) {
    try {
        if (typeof document.body.style.maxHeight === "undefined") {
            $("body", "html").css({
                height: "100%",
                width: "100%"
            });
            $("html").css("overflow", "hidden");
            if (document.getElementById("TB_HideSelect") === null) {
                $("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
                $("#TB_overlay").click(tb_remove);
            }
        } else {
            if (document.getElementById("TB_overlay") === null) {
                $("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
                $("#TB_overlay").css("overflow", "hidden");
                $("#TB_overlay").click(tb_remove);
            }
        }
        if (tb_detectMacXFF()) {
            $("#TB_overlay").addClass("TB_overlayMacFFBGHack");
        } else {
            $("#TB_overlay").addClass("TB_overlayBG");
        }
        if (caption === null) {
            caption = "";
        }
        $("body").append("<div id='TB_load'><img src='" + imgLoader.src + "' /></div>");
        $('#TB_load').show();
        var baseURL;
        if (url.indexOf("?") !== -1) {
            baseURL = url.substr(0, url.indexOf("?"));
        } else {
            baseURL = url;
        }
        var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
        var urlType = baseURL.toLowerCase().match(urlString);
        if (urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp') {
            TB_PrevCaption = "";
            TB_PrevURL = "";
            TB_PrevHTML = "";
            TB_NextCaption = "";
            TB_NextURL = "";
            TB_NextHTML = "";
            TB_imageCount = "";
            TB_FoundURL = false;
            if (imageGroup) {
                TB_TempArray = $('a[rel="' + imageGroup + '"]');
                n = TB_TempArray.length;
                for (TB_Counter = 0; ((TB_Counter < n) && (TB_NextHTML === "")); TB_Counter++) {
                    var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
                    if (! (TB_TempArray[TB_Counter].href == url)) {
                        if (TB_FoundURL) {
                            TB_NextCaption = TB_TempArray[TB_Counter].title;
                            TB_NextURL = TB_TempArray[TB_Counter].href;
                            TB_NextHTML = "<span id='TB_next'><a href='#'>Next</a></span>";
                        } else {
                            TB_PrevCaption = TB_TempArray[TB_Counter].title;
                            TB_PrevURL = TB_TempArray[TB_Counter].href;
                            TB_PrevHTML = "<span id='TB_prev'><a href='#'>Prev</a></span>";
                        }
                    } else {
                        TB_FoundURL = true;
                        TB_imageCount = "Image " + (TB_Counter + 1) + " of " + n;
                    }
                }
            }
            imgPreloader = new Image();
            imgPreloader.onload = function() {
                imgPreloader.onload = null;
                var pagesize = tb_getPageSize();
                var x = pagesize[0] - 50;
                var y = pagesize[1] - 50;
                var imageWidth = imgPreloader.width;
                var imageHeight = imgPreloader.height;
                if (imageWidth > x) {
                    imageHeight = imageHeight * (x / imageWidth);
                    imageWidth = x;
                    if (imageHeight > y) {
                        imageWidth = imageWidth * (y / imageHeight);
                        imageHeight = y;
                    }
                } else if (imageHeight > y) {
                    imageWidth = imageWidth * (y / imageHeight);
                    imageHeight = y;
                    if (imageWidth > x) {
                        imageHeight = imageHeight * (x / imageWidth);
                        imageWidth = x;
                    }
                }
                TB_WIDTH = parseInt(imageWidth);
                TB_HEIGHT = parseInt(imageHeight);
                TB_BOX = "<div id='TB_nav'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div><div id='TB_closeWindow'><a href='#' id='TB_closeWindowButton' title='Close or Esc Key'>close</a></div><div style=\"background:url("+url+") center center no-repeat;height:"+TB_HEIGHT+"px;width:"+TB_WIDTH+"px;overflow:hidden;\"></div>";
                $("#TB_window").append(TB_BOX);
                $("#TB_closeWindowButton").click(tb_remove);
                
                if (! (TB_PrevHTML === "")) {
                    function goPrev() {
                        if ($(document).unbind("click", goPrev)) {
                            $(document).unbind("click", goPrev);
                        }
                        $("#TB_window").remove();
                        $("body").append("<div id='TB_window'></div>");
                        tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
                        return false;
                    }
                    $("#TB_prev").click(goPrev);
                }
                if (! (TB_NextHTML === "")) {
                    function goNext() {
                        $("#TB_window").remove();
                        $("body").append("<div id='TB_window'></div>");
                        tb_show(TB_NextCaption, TB_NextURL, imageGroup);
                        return false;
                    }
                    $("#TB_next").click(goNext);
                }
                document.onkeydown = function(e) {
                    if (e == null) {
                        keycode = event.keyCode;
                    } else {
                        keycode = e.which;
                    }
                    if (keycode == 27 || keycode == 46 || keycode == 13) {
                        tb_remove();
                    } else if (keycode == 190 || keycode == 39) {
                        if (! (TB_NextHTML == "")) {
                            document.onkeydown = "";
                            goNext();
                        }
                    } else if (keycode == 188 || keycode == 37) {
                        if (! (TB_PrevHTML == "")) {
                            document.onkeydown = "";
                            goPrev();
                        }
                    }
                };
                tb_position();
                $("#TB_load").remove();
                $("#TB_ImageOff").click(tb_remove);
                $("#TB_window").css({
                    display: "block"
                });
                // $("#TB_window").fadeIn("fast");
            };
            imgPreloader.src = url;
        }
    } catch(e) {}
}

function tb_remove() {
    $("#TB_imageOff").unbind("click");
    $("#TB_closeWindowButton").unbind("click");
    $("#TB_window").fadeOut("fast",
    function() {
        $('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();
    });
    $("#TB_load").remove();
    if (typeof document.body.style.maxHeight == "undefined") {
        $("body", "html").css({
            height: "auto",
            width: "auto"
        });
        $("html").css("overflow", "");
    }
    document.onkeydown = "";
    document.onkeyup = "";
    return false;
}
function tb_position() {
    $("#TB_window").css({
        marginLeft: '-' + parseInt((TB_WIDTH / 2), 10) + 'px',
        width: TB_WIDTH + 'px'
    });
    if (! (jQuery.browser.msie && jQuery.browser.version < 7)) {
        document.documentElement.scrollTop = 0;
        // var targetOffset = $('body').offset().top;
        //         $('html').animate({scrollTop: targetOffset}, 0);
        $("#TB_window").css({
            marginTop: '-' + parseInt((TB_HEIGHT / 2)+10, 10) + 'px'
        });
    }
}
function tb_getPageSize() {
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
    arrayPageSize = [w, h];
    return arrayPageSize;
}
function tb_detectMacXFF() {
    var userAgent = navigator.userAgent.toLowerCase();
    if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox') != -1) {
        return true;
    }
}

// APP

function arr_clean(arr){
   newArr = new Array();
   for (k in arr) if(arr[k]) newArr.push(arr[k]);
   return newArr;
}

if (!$.browser.iphone) {
  tb_init('a[@rel^="shadowbox"]');
  imgLoader = new Image();
  imgLoader.src = tb_pathToImage;

  var mna = $('#mn p a');
  var smli = $('#section_menu > ul > li');
  var path = arr_clean(location.pathname.split('/'));
  var plast = path[path.length-1];

    // $("#model_menu").bind("mouseenter",function(){
    //     mm.animate({height: 'show', opacity: 'show'}, 200);
    // }).bind("mouseleave",function(){
    //   mm.hide();
    //   // mm.animate({height: 'hide'}, "fast");
    // });

  mna.each(function () {
    $$ = $(this);
    if($$.attr("href").split('/')[1] == path[0]){
      $$.addClass('current')
    }
  });

  $('#section_menu li a').each(function () {
    $$ = $(this);
    m = arr_clean($$.attr("href").split('/'));
    mlast = m[m.length-1];
    if(mlast == plast){
      $$.parent().addClass('current')
    }
  });

  if (!($.browser.msie && $.browser.version.number < 7)){
    mna.hover(function(){
      $$ = $(this);
      if($$.hasClass('current')){return false;}
      if ($$.is(':animated')) {
        $$.stop().css({color:'#f00'});
      } else {
        $$.animate({color:'#f00'}, "fast");
      }
    },function(){
      $$ = $(this);
      if($$.hasClass('current')){return false;}
      $$.animate({color:'#fff' }, "slow");
    });

    smli.hover(function(){
      if($(this).hasClass('current')){return false;}
      $$ = $(this).find('a')
      if ($$.is(':animated')) {
        $$.stop().css({color:'#c00',backgroundColor:"#fff"});
      } else {
        $$.animate({color:'#c00',backgroundColor:"#fff"}, "fast");
      }
    },function(){
      if($(this).hasClass('current')){return false;}
      $$ = $(this).find('a')
      $$.animate({color:'#222',backgroundColor:"#ccc"}, "slow");
    });
    
    $('#model_menu ul a').hover(function(){
      $$ = $(this);
      if ($$.is(':animated')) {
        $$.stop().css({color:'#fff',backgroundColor:"#555"});
      } else {
        $$.animate({color:'#fff',backgroundColor:"#555"}, "fast");
      }
    },function(){
      $(this).animate({color:'#ccc',backgroundColor:"#666"}, "fast");
    });
  
    $('a.pdf,a.jump,a.minisite,a.email,a.print,a.back,p.pagination,.action')
    .hover(function(){
      $$ = $(this);
      if ($$.is(':animated')) {
        $$.stop().css({color:'#c00',backgroundColor:"#fff"});
      } else {
        $$.animate({color:'#c00',backgroundColor:"#fff"}, "fast");
      }
    },function(){
        $(this).animate({color:'#333',backgroundColor:"#ddd"}, "slow");
    });

    $('#front h4 a').hover(function(){
      $(this).animate({color:'#f00'}, "fast");
    },function(){
      $(this).animate({color:'#ddd'}, "fast");
    });
  }
}

$('.print,.minisite,.popup').click( function() { 
  window.open( $(this).attr('href') ); 
  return false; 
}); 

$('.back').click( function() { 
  history.back();
  return false; 
}); 

if($('table')){$('table tbody tr:even').addClass('even')}

var preload = [];
$('a[@rel^="shadowbox"]').each(function(index) {preload.push($(this).attr("href"));});
$(document.createElement('img')).bind('load',function() {if (preload[0]) this.src = preload.shift();}).trigger('load');
