 $(function(){
    var body = document.body,
        root = this,
        i = 0,
        numRan = 0,
        bodyClasses = body.className.split(" "),
        pageScripts = {
            init:function(){
                var dropdowns = $('.nav-dd').not('.gall'),
                    obsEmail = $('a.obs'),
                    clickable = $('.clickable').not('.forbidden');
                    
                jQuery.fx.interval = 5;
                
                if(dropdowns.length) { 
                    if(body.className.indexOf('mediaDownloads') > -1) {
                    	
                    	var galleries = $('.a_gallery_wrap'),
                    		drop = $('.nav-dd.gall'),
                    		location = window.location;
                    	if(drop.length) {
	                    	drop.find('select').change(function() {
	                    	    $(this.parentNode).siblings('.txt').html(this.options[this.selectedIndex].innerHTML);
	                    	    if(this.className.indexOf('link-off') > -1) {
	                    	        if(this.options[this.selectedIndex].value != '#' && this.options[this.selectedIndex].value != '') {
	                    	            galleries.addClass("gallery-hide");
	                    	            $('#'+this.options[this.selectedIndex].value).removeClass('gallery-hide');
	                    	        }
	                    	    }
	                    	});
	                    	
	                    	var segs = location.pathname.split('/'),
	                    		segsLast = segs[segs.length-1],
	                    		select = drop.find('select').get(0),
	                    		selectLen = select.length;
	                    	
                            //Debug - if trailing slash present in URL
                            if(segsLast === '') {
                                segsLast = segs[segs.length-2];
                            }

	                    	for(i=0;i<selectLen;++i) {
	                    		if(select.options[i].value == segsLast) {
	                    			galleries.addClass("gallery-hide");
	                    			$('#'+select.options[i].value).removeClass('gallery-hide');
	                    		}
	                    	}
                    	}
                    }
                    dropdowns.find('select').change(function() {
                        $(this.parentNode).siblings('.txt').text(this.options[this.selectedIndex].innerHTML);
                        if(this.className.indexOf('link-off') > -1) {
                            if(this.options[this.selectedIndex].value != '#' && this.options[this.selectedIndex].value != '') {
                                window.location = this.options[this.selectedIndex].value;
                            }
                        }
                        
                    });
                    
                }
                
                if(obsEmail.length) {
                    obsEmail.emailObs();
                }
                
                if(clickable.length) {
                    clickable.click(function() {
                        window.location = this.getAttribute('itemid');
                    });
                }
                
                if(Modernizr.inputtypes.search && $.browser.safari) {
                    //TO DO: FireFox4 returns true here, but it's not styled!
                    //Need to test if it's webkit specifically
                    $('#text_search').addClass('webkit').html('<input type="search" id="searchbox" name="q" placeholder="Search" autosave="utc_auto_save" results="16" class="webkitsearch" />');
                }
                $('#site_search').addClass('webshow');
            },//End init
            mediaDownloads: function(){
              $("#video-list a[rel^='prettyPhoto']").prettyPhoto({iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>'});
              
              $("#nav_tabs, #nav_tabs2, #nav_tabs3").tabs();
              
              var contactForm = $('#contactForm'),
                  submitBtn = $('#submitBtn'),
                  modalBox = $('#simplemodal-container');

                $('.forbidden').click(function(e) {
                    e.preventDefault();
                    modalBox.modal({
                        overlayClose: true
                    });
                });
              
              contactForm.validate({
                  rules:{
                      first_name: {required:true},
                      last_name:  {required:true},
                      email:      {required:true, email:true},
                  },
                  errorPlacement:function() {},
                  errorClass:'error'
              });
              
              submitBtn.click(function(e) {
                  e.preventDefault();
                  contactForm.trigger('submit');
                  return false;
              });
              
              $('.a_gallery').gallery();
              
            },
            proddocs: function(){
              var contactForm = $('#contactForm'),
                  modalBox = $('#simplemodal-container'),
                  submitBtn = $('#submitBtn');

                $('.clickable.forbidden').click(function(e) {
                    e.preventDefault();
                    modalBox.modal({
                        overlayClose: true
                    });
                });


              contactForm.validate({
                  rules:{
                      first_name: {required:true},
                      last_name:  {required:true},
                      email:      {required:true, email:true},
                  },
                  errorPlacement:function() {},
                  errorClass:'error'
              });
              
              submitBtn.click(function(e) {
                  e.preventDefault();
                  contactForm.trigger('submit');
                  return false;
              });
              
            },
            home:function() {
                var img = $("<img />").css('zIndex', 1),
                    img2 = $("<img />").css('zIndex', 0),
                    blockHead = $('.grid_12.block_heads'),
                    positions = {
                        current: 'pos_midLeft',
                        topLeft: 'pos_topLeft',
                        botLeft: 'pos_botLeft',
                        botRight: 'pos_botRight',
                        midLeft: 'pos_midLeft'
                    },
                    h1a = $('#block_head_content article:first-child h1'),
                    h1b = $('#block_head_content article:nth-child(2) h1'),
                    headp = $('#block_head_content article p'),
                    startSize = false,
                    firstLoad = true,
                    isAnimating = false,
                    popups = $('#home_menus .pop_up'),
                    resizeWindow = function(e) {
                        var winSize = {w: $(window).width(), h: $(window).height()},
                        scale = 0;
                        
                        if(winSize.h < 788 && winSize.h > 700) {
                            blockHead.addClass('alt').removeClass('shortest');
                        }
                        else if(winSize.h <= 700){
                            blockHead.addClass('shortest').removeClass('alt');
                        }
                        else {
                            blockHead.removeClass('alt shortest'); // Chris - this actually worked.
                        }
                        
                        if(firstLoad === true) {
                            img.unbind('load');
                            img.load(function() { //Triggered below on image fades
                                img.show();
                                img2.attr('src', '');
                                blockHeadContent.fadeIn(600, function() {
                                    isAnimating = false;
                                });
                            });
                            firstLoad = false;
                        }
                        if(startSize === false) {
                            startSize = {w: img.width(), h:img.height()};
                        }
                        
                        scale = parseFloat(winSize.w) / parseFloat(startSize.w);
                        
                        //check if assumption is right, othewise assume height
                        if(startSize.h * scale < winSize.h){
                            scale = winSize.h / startSize.h;
                        }
                        //console.log(startSize.w * scale+' :: '+startSize.h * scale);
                        //use scale that fits best to size image            
                        img.css({
                            "width": startSize.w * scale,
                            "height": startSize.h * scale
                        });
                        img2.css({
                            "width": startSize.w * scale,
                            "height": startSize.h * scale
                        });
                    };

                $(window).bind("resize", resizeWindow);
                //TO DO: GRAB THIS from global object output by EE
                //var imgAr = ['/img/bg_large_field.jpg','/img/bg_large_night.jpg'],
                imgCurInd = 0,
                blockHeadContent = $('#block_head_content');
                
                img.load(resizeWindow);
                img.attr('src', imgAr[0].url);
                
                $('#home_stretch').append(img).append(img2);
                
                //FADE homepage image AND inner text
                window.setInterval(function() {
                    isAnimating = true;
                    blockHeadContent.fadeOut(600, function() {
                        imgCurInd += 1;
                        if(imgCurInd >= imgAr.length) {
                            imgCurInd = 0;
                        }
                        blockHead.removeClass(positions.current);
                        switch(imgAr[imgCurInd].position) {
                            case 'Top Left':
                                blockHead.addClass(positions.topLeft);
                                positions.current = positions.topLeft;
                                break;
                            case 'Bottom Left':
                                blockHead.addClass(positions.botLeft);
                                positions.current = positions.botLeft;
                                break;
                            case 'Bottom Right':
                                blockHead.addClass(positions.botRight);
                                positions.current = positions.botRight;
                                break;
                            case 'Middle Left':
                            default:
                                blockHead.addClass(positions.midLeft);
                                positions.current = positions.midLeft;
                                break;
                        }
                        h1a.text(imgAr[imgCurInd].h1a);
                        h1b.text(imgAr[imgCurInd].h1b);
                        headp.text(imgAr[imgCurInd].headp);
                        if(imgAr[imgCurInd].colorp == 'Light text on a dark background') {
                            headp.addClass('light');
                        } else {
                            headp.removeClass('light');
                        }
                        if(imgAr[imgCurInd].h1color != '') {
                            h1a.css('color', '#'+imgAr[imgCurInd].h1color);
                            h1b.css('color', '#'+imgAr[imgCurInd].h1color);
                        }
                        img2.attr('src', imgAr[imgCurInd].url);
                    });
                },6000);
                img2.load(function() {
                    img.fadeOut(700, 'easeInOutExpo', function() {
                        img.attr('src', img2.attr('src')); //This will trigger img.load()
                    });
                });
                
                if(popups.length) {
                    var curInd = 0,
                        curObj = false;
                    $('#home_menus .pop_up .hgroup').click(function() {
                        //if(!isAnimating) { //If background isn't fading and causing terrible lag
                            curInd = parseInt($(this).attr('itemid'), 10);
                            curObj = $(popups.get(curInd));
                            if(curObj.hasClass('up')) {
                                curObj.animate({bottom: 0},200,'easeInOutExpo',function() {curObj.removeClass('up');});
                            } else {
                                popups.each(function(i) {
                                    if(i === curInd) { return true; }
                                    var it = $(this);
                                    it.animate({bottom: 0},200,'easeInOutExpo',function() {it.removeClass('up');});
                                });
                                curObj.animate({bottom: 514},200,'easeInOutExpo',function() {$(popups.removeClass('up').get(curInd)).addClass('up');});
                                _gaq.push([ '_trackEvent', "home", "tab_open", $(this).find('h2').text() ]); // track tab open
                            }
                        //}
                        return false;
                    });
                }
            },//End home
            product:function() {
                var currentTabIndex = 0,
                tabs = $('#int_how_work nav li'),
                tNode = false;
                
                $('#support_nav').parents('.grid_12').tabs({select: function(event, ui) {
                    tNode = $(ui.tab.parentNode);
                    if(tNode.hasClass('subnav_link')) {
                        event.preventDefault();
                        window.location = tNode.attr('itemid');
                        return false
                    }
                }}).navJump();
                
                $('.faq').faq();
                
                $('#int_how_work').tabs({select:function(e, ui) {
                    tabs.get(currentTabIndex).className = tabs.get(currentTabIndex).className.replace(' orange_btn', '');
                    tabs.get(ui.index).className += ' orange_btn';
                    currentTabIndex = ui.index;
                }});
                
            },//End product
            purecell400: function(){
                var clickies = $('#major_benefits .energy_benefit'),
                    info = $('#major_benefits .show');
                $(info.get(clickies.index(0))).show();
                clickies.click(function() {
                    info.hide();
                    $(info.get(clickies.index($(this)))).show();
                });
                
                var tourObj = {
                    features: {
                        front: [{
                            //0
                            tooltip: "What is a Fuel Cell?",
                            x: 150,
                            y: 52,
                            img: "/img/tour/slides/front_0.jpg"
                        }, {
                            //1
                            tooltip: "Customize Your Fuel Cell",
                            x: 290,
                            y: 35,
                            img: "/img/tour/slides/front_1.jpg"
                        }, {
                            //2
                            tooltip: "Fuel Cell Inputs & Outputs",
                            x: 246,
                            y: 202,
                            img: "/img/tour/slides/front_2.jpg"
                        }, {
                            //3
                            tooltip: "Thermal Energy",
                            x: 290,
                            y: 185,
                            img: "/img/tour/slides/front_3.jpg"
                        }, {
                            //4
                            tooltip: "Water Conservation",
                            x: 412,
                            y: 123,
                            img: "/img/tour/slides/front_4.jpg"
                        }],
                        back: [{
                            //0
                            tooltip: "Reduced Emissions",
                            x: 173,
                            y: 138,
                            img: "/img/tour/slides/back_0.jpg"
                        }, {
                            //1
                            tooltip: "Fuel Cell Certifications",
                            x: 315,
                            y: 35,
                            img: "/img/tour/slides/back_1.jpg"
                        }, {
                            //2
                            tooltip: "Fuel Cell Stacks",
                            x: 388,
                            y: 112,
                            img: "/img/tour/slides/back_2.jpg"
                        }, {
                            //3
                            tooltip: "Quiet Operation",
                            x: 463,
                            y: 57,
                            img: "/img/tour/slides/back_3.jpg"
                        }],
                        sidebar: [{
                            //0
                            img: "/img/tour/slides/sidebar_0.jpg"
                        }, {
                            //1
                            img: "/img/tour/slides/sidebar_1.jpg"
                        }, {
                            //2
                            img: "/img/tour/slides/sidebar_2.jpg"
                        }, {
                            //3
                            img: "/img/tour/slides/sidebar_3.jpg"
                        }, {
                            //4
                            img: "/img/tour/slides/sidebar_4.jpg"
                        }],
                        footer: [{
                            //0
                            tooltip: "Energy Productivity & Efficiency",
                            x: 0,
                            y: 0,
                            img: "/img/tour/slides/footer_0.jpg"
                        }, {
                            //1
                            tooltip: "Energy Security",
                            x: 0,
                            y: 0,
                            img: "/img/tour/slides/footer_1.jpg"
                        }, {
                            //2
                            tooltip: "Reduced Carbon Footprint",
                            x: 0,
                            y: 0,
                            img: "/img/tour/slides/footer_2.jpg"
                        }]
                    }
                }//end tourObj
                //draw the first view
                function buildView(v){
                    var markup = '';
                    var i;
                    var buildables = {
                        unbuild: function(){
                            //clear out contents of #graphic_features
                            $("#graphic_features").html("");
                            //remove qtips
                            $("#graphic_features .qtip").qtip("destroy");
                            $("#graphic_features .qtip").remove();
                        },
                        front: function(){
                            //make the backgound of the graphic the front image
                            $("#int_product_tour #graphic").css("background-image", "url(/img/tour/prod_front.jpg)");
                            //loop through obj and draw anchor tags where they go.
                            //add bindings to those guys for roll overs and clicks.
                            //TODO Merge
                            var objLen = tourObj.features.front.length;
                            for (i = 0; i < objLen; i++) {
                                //dom additions add to id="graphic_features";
                                $('<a href="#" title="default"></a>').appendTo("#graphic_features").css({
                                    display: "block",
                                    height: "34px",
                                    width: "34px",
                                    position: "absolute",
                                    top: tourObj.features.front[i].y,
                                    left: tourObj.features.front[i].x
                                }).attr("alt", tourObj.features.front[i].img).attr("title", tourObj.features.front[i].tooltip).bind('click.showImage', function(e){
                                    e.preventDefault();
                                    //console.log();
                                    //$(this).attr("alt") is the image url we're loading
                                    $("#int_product_tour .overlap").css({
                                        "visibility": "visible"
                                    }).hide().fadeIn();
                                    $("#int_product_tour .overlap img").attr("src", $(this).attr("alt"));
                                }).qtip({
                                    position: {
                                        corner: {
                                            target: 'bottomLeft',
                                            tooltip: 'topLeft'
                                        }
                                    },
                                    style: {
                                        title: {
                                            'background-color': 'black'
                                        },
                                        tip: {
                                            size: {
                                                width: 25,
                                                height: 10
                                            }
                                        },
                                        border: {
                                            width: 3,
                                            radius: 5,
                                            color: 'black'
                                        },
                                        tip: true
                                    }
                                });
                            }
                        },
                        back: function(){
                            //make the backgound of the graphic the front image
                            $("#int_product_tour #graphic").css("background-image", "url(/img/tour/prod_back.jpg)");
                            //loop through obj and draw anchor tags where they go.
                            //add bindings to those guys for roll overs and clicks.
                            var objLen = tourObj.features.back.length;
                            for (i = 0; i < objLen; i++) {
                                //dom additions add to id="graphic_features";
                                $('<a href="#" title="default"></a>').appendTo("#graphic_features").css({
                                    display: "block",
                                    height: "34px",
                                    width: "34px",
                                    position: "absolute",
                                    top: tourObj.features.back[i].y,
                                    left: tourObj.features.back[i].x
                                }).attr("alt", tourObj.features.back[i].img).attr("title", tourObj.features.back[i].tooltip).bind('click.showImage', function(e){
                                    e.preventDefault();
                                    //console.log();
                                    //$(this).attr("alt") is the image url we're loading
                                    $("#int_product_tour .overlap").css({
                                        "visibility": "visible"
                                    }).hide().fadeIn();
                                    $("#int_product_tour .overlap img").attr("src", $(this).attr("alt"));
                                }).qtip({
                                    position: {
                                        corner: {
                                            target: 'bottomLeft',
                                            tooltip: 'topLeft'
                                        }
                                    },
                                    style: {
                                        title: {
                                            'background-color': 'black'
                                        },
                                        tip: {
                                            size: {
                                                width: 25,
                                                height: 10
                                            }
                                        },
                                        border: {
                                            width: 3,
                                            radius: 5,
                                            color: 'black'
                                        },
                                        tip: true
                                    }
                                });
                            }
                        },
                        image: function(){
                            //drop image on top of everything.
                        }
                    }
                    if (buildables[v]) {
                        buildables[v].apply(root, []);
                    } else {
                        //console.log("view " + v + " not found in buildView()");
                    }
                }
                function switchView(v){
                    //hide the current view
                    buildView('unbuild');
                    buildView(v);
                }
                //events when you click on the thumbnails of front or back
                $("#product-views #front").bind('click', function(e){
                    e.preventDefault();
                    switchView('front');
                    $("#product-views #back").removeClass("selected");
                    $("#product-views #front").addClass("selected");
                });
                $("#product-views #back").bind('click', function(e){
                    e.preventDefault();
                    switchView('back');
                    $("#product-views #front").removeClass("selected");
                    $("#product-views #back").addClass("selected");
                });
                $("#product-views #front").click();
                //rig close button
                $("#int_product_tour .overlap a.close").bind('click', function(e){
                    //fade out
                    e.preventDefault();
                    $("#int_product_tour .overlap").fadeOut("fast", function(){
                        //when fade out is done, replace loading image and hide everything
                        $("#int_product_tour .overlap img").attr("src", "/img/tour/loading.gif");
                        $(this).css("visibility", "hidden");
                    });
                    //
                });
                //rig side menu
                $("#int_product_tour .sidemenu li").each(function(i){
                    $(this).attr("alt", tourObj.features.sidebar[i].img);
                    $(this).bind('click', function(e){
                        e.preventDefault();
                        $("#int_product_tour .overlap").css({
                            "visibility": "visible"
                        }).hide().fadeIn();
                        $("#int_product_tour .overlap img").attr("src", $(this).attr("alt"));
                    });
                });
                //rig footer menu
                $("#int_product_tour #graphic .footer li").each(function(i){
                    $(this).attr("alt", tourObj.features.footer[i].img).attr("title", tourObj.features.footer[i].tooltip).qtip({
                                    position: {
                                        corner: {
                                            target: 'topLeft',
                                            tooltip: 'bottomLeft'
                                        }
                                    },
                                    style: {
                                        title: {
                                            'background-color': 'black'
                                        },
                                        tip: {
                                            size: {
                                                width: 25,
                                                height: 10
                                            }
                                        },
                                        border: {
                                            width: 3,
                                            radius: 5,
                                            color: 'black'
                                        },
                                        tip: true
                                    }
                                });
                    $(this).bind('click', function(e){
                        e.preventDefault();
                        $("#int_product_tour .overlap").css({
                            "visibility": "visible"
                        }).hide().fadeIn();
                        $("#int_product_tour .overlap img").attr("src", $(this).attr("alt"));
                    });
                });
            },//end tour
            history:function() {
                var curDecade = 0,
                    newDecade = 0,
                    isAnimating = false,
                    slides = $('.slides'),
                    slide_nav = $('#hist_nav li a');
                    total_items = 0,
                    left_offset = 0,
                    slide_width = ($('.slides li').width() + 38); // takes into account padding
                    var width_60s, width_70s, width_80s, width_90s, width_00s, width_10s = 0;
                    var total_width = 0;
                    var current_item;
                    
					var decade = new Array(width_60s, width_70s, width_80s, width_90s, width_00s, width_10s);
                	var markers = new Array('end_60s', 'end_70s', 'end_80s', 'end_90s', 'end_00s', 'end_10s');
                
	            // calculate total width of decades within slide
	            decade[0] = 0; //first decade starts at position 0.
	            for(var i = 1; i < decade.length; i++){
	                $('.slides li').each(function(){				
						total_items++; 
						if($(this).hasClass(markers[i-1])){	
							decade[i] = (total_items) * slide_width;
						}
	                });
		            total_items = 0; 
	            }
	            
	            /* calculate total width of entire slide */
 				$('.slides li').each(function(){
 					total_width += slide_width;
 				});

                slide_nav.click(function() {
                    if(!isAnimating) {
                        newDecade = $(this).attr('itemid');

                        left_offset = $('.slides').position().left;
                                                
                        isAnimating = true;
                        
                        slide_nav.get(curDecade).parentNode.className = '';
                        slide_nav.get(newDecade).parentNode.className = 'active';
                        
                        slides.animate({
                            left: "+=" + -(left_offset + decade[newDecade]),
                            x: 0,
                            queue: true
                        }, "swing", function(){
                            isAnimating = false;
                        });
                        curDecade = newDecade;
                    }
                    return false;
                });
                
                /* animate on click */
                $('#btn_next a').click(function(){
	                 left_offset = $('.slides').position().left;
	                 
	                 /* if we're on the last slide animate to first */
	                 if(Math.abs(left_offset) >= (total_width - slide_width)){
	                 slides.stop(true, true).animate({
	                            left: "+=" + (total_width - slide_width),
	                            x: 0,
	                            queue: true
	                        }, "swing", function(){
	                            isAnimating = false;
	                        });
	                        decadeParser('next');
	                		return false;
	                 
	                 } 
	                 /* else, animate the width of a single list item */
	                 else{
	                 slides.stop(true,true).animate({
	                            left: "+=" + -slide_width,
	                            x: 0,
	                            queue: true
	                        }, "swing", function(){
	                        	
	                            isAnimating = false;
	                            
	                        });
	                        decadeParser('next');
	                        return false;
	                 }
                });
                
                /* animate on click */
                $('#btn_prev a').click(function(){             	
	                left_offset = $('.slides').position().left;

					/* if we're on the first slide animate to last */
	                if(left_offset >= 0){
	                slides.stop(true, true).animate({
	                            left: "+=" + -(total_width - slide_width),
	                            x: 0,
	                            queue: true
	                        }, "swing", function(){
	                            isAnimating = false;
	                            
	                        });
	                        decadeParser('prev');
	                        return false;
	                
	                } 
	                /* else, animate the width of a single list item */
	                else{
	                slides.stop(true,true).animate({
	                            left: "+=" + slide_width,
	                            x: 0,
	                            queue: true
	                        }, "swing", function(){
	                        	
	                            isAnimating = false;
	                            return false;
	                        });
	                        decadeParser('prev');
	                        return false;
	                }              
                });
                
                 function decadeParser(nextOrPrev){
					var offset = Math.abs($('.slides').position().left);
					//console.log(offset + "total " + total_width);
					
					/* if we're on last slide element and user hits next */
					if(offset == total_width - slide_width && nextOrPrev == 'next'){
							slide_nav.get(curDecade).parentNode.className = '';
	               	 		curDecade = 0;
	               	 		slide_nav.get(curDecade).parentNode.className = 'active';
	               	 		return false;
					}
					for(var i = 0; i < decade.length; i++){ 
						/* if user hits next and next slide happens to be first year of decade */
	               		if(offset + slide_width == decade[i] && nextOrPrev == 'next'){
	               			slide_nav.get(curDecade).parentNode.className = '';
	               	 		curDecade = i;
	               	 		slide_nav.get(i).parentNode.className = 'active';
	               	 		return false;
	               	 	}
	               	 	/* if user hits prev and prev slide happens to be last year of decade */
	               	 	else if(offset == decade[i] && nextOrPrev == 'prev'){
	               			slide_nav.get(curDecade).parentNode.className = '';
	               	 		curDecade = i-1;
	               	 		slide_nav.get(i-1).parentNode.className = 'active';
	               	 		return false;
	               	 	}
	               	}

	              }


            },//End history
            fleetvehicles:function() {
                $('#overview_3').tabs();
            },//End fleetvehicles
            triptych:function() {
                var box1 = $('#box_1'),
                    box2 = $('#box_2'),
                    box3 = $('#box_3');
                //select the first box
                box1.playTo();
                box1.playTo('selected');
                //mouse events
                box1.hover(
                    function(){
                        $(this).playTo('linear', 5);
                    },
                    function(){
                        $(this).playTo('linear', 0);
                    }
                )
                .bind('click', function(){$("#box_1").playTo('selected');})
                .click(function(evt){    
                    $("#content_swap").fadeToContent({"speed": 200, "child": 1});
                    evt.preventDefault();
                    return false;
                });
                
                //initialize
                box2.playTo();
                box2.hover(
                    function(){ $(this).playTo('linear', 5); },
                    function(){ $(this).playTo('linear', 0); }
                )
                .bind('click', function(){$("#box_2").playTo('selected');})
                .click(function(evt){    
                    $("#content_swap").fadeToContent({"speed": 200, "child": 2});
                    evt.preventDefault();
                    return false;
                });
                
                //initialize
                box3.playTo();
                box3.hover(
                    function(){ $(this).playTo('linear', 5); },
                    function(){ $(this).playTo('linear', 0); }
                )
                .bind('click', function(){$("#box_3").playTo('selected');})
                .click(function(evt){
                    $("#content_swap").fadeToContent({"speed": 200, "child": 3});
                    evt.preventDefault();
                    return false;
                    
                });
            },//End triptych
            single:function() {
                $('#social').rail();
            },//End single
            leadership:function() {
                $('#bio-links a').click(function() {
                    $('#bio-links a').removeClass('active')
                    $(this).addClass('active');
                    $('.bio').hide();
                    var idx = $('#bio-links a').index(this);
                    $('#bios .bio').eq(idx).show();
                });
            },//End leadership
            news_overview:function() {
                $('#twitstream').twitter({username:'utc_power', count:2});
            },
            blog_side:function() {
                $('#twitstream').twitter({username:'utc_power', count:1});
            },
            search:function() {
                $('#twitstream').twitter({username:'utc_power', count:1});
            },
            contact:function() {
                if(body.id == 'marketing' && body.className.indexOf('newsletter') == -1) {
                    initCountry('USA');
                    
                    var contactForm = $('#contactForm'),
                        submitBtn = $('#submitBtn');
                    
    
                    contactForm.validate({
                        rules:{
                            first_name: {required:true},
                            last_name:  {required:true},
                            company:    {required:true},
                            email:      {required:true, email:true},
                            phone:      {required:true},
                            country:    {required:true},
                            description:{required:true}
                        },
                        errorPlacement:function() {},
                        errorClass:'error'
                    });
                    
                    submitBtn.click(function(e) {
                        e.preventDefault();
                        contactForm.trigger('submit');
                        return false;
                    });
                    
                }
            },
            newsletter:function() {
                var newsForm = $('#newsletterForm'),
                    submitBtn = $('#submitBtn');
                
                newsForm.validate({
                    rules:{'cm-cltuti-cltuti':  {required:true, email:true}},
                    errorPlacement:function() {},
                    errorClass:'error'
                });
                
                submitBtn.click(function(e) {
                    e.preventDefault();
                    newsForm.trigger('submit');
                    return false;
                });
            },
            faqs:function() {
                $('.faq').faq();
                
                var cats = $('.faq h4 a'),
                	dls = $('.faq dl');
                cats.click(function(e) {
                	e.preventDefault();
                	dls.slideUp('slow');
                	$('#'+$(this).attr('itemid')).slideDown('slow');
                	return false;
                });
            },
            media:function() {
                $("#video-list a[rel^='prettyPhoto']").prettyPhoto({iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>'});
            },
            stock:function() {
                /*
                //http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=utx&callback=YAHOO.Finance.SymbolSuggest.ssCallback
                
                var YAHOO = {
                    Finance:{
                        SymbolSuggest:{
                            ssCallback:function() {
                                this.YAHOO = {};
                            }
                        }
                    }
                };
                $.ajax({
                    type:'GET',
                    url:'http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=utx',
                    contentType: "application/json; charset=utf-8",
                    dataType:'jsonp',
                    //jsonpCallback:'YAHOO.Finance.SymbolSuggest.ssCallback',
                    //jsonp:'YAHOO.Finance.SymbolSuggest.ssCallback',
                    success:function(data, textStatus, jqXHR) {
                        alert(data);
                    },
                    error:function(jqXHR, textStatus, errorThrown) {
                        alert('error: '+textStatus);
                    }
                });
                */
            },
            gallery:function() {
                var galleries = $('.ad-gallery').adGallery({
                    description_wrapper: $('#descriptions'),
                    loader_image:'/img/gallery_assets/loader.gif',
                    next_link: $('#override_controls .next_btn'),
                    prev_link: $('#override_controls .prev_btn')
                });
            }
        }
                
    //call init on every page load
    pageScripts.init();

    //loop through and execute all available functions
    //based on body classes
    for(i in bodyClasses){
        if(pageScripts[ bodyClasses[i] ]){
            numRan++;
            pageScripts[ bodyClasses[i] ].apply(root, []);  
        }
    }
    
    
    /*
    $('a#stationary').click(function(){
        $('dl#category_2').slideUp("slow");
        $('dl#category_3').slideUp("slow");
        $('dl#category_4').slideUp("slow");
        $('dl#category_1').slideToggle("slow");
        return false;
    });
    $('a#buses').click(function(){
        $('dl#category_1').slideUp("slow");
        $('dl#category_2').slideUp("slow");
        $('dl#category_4').slideUp("slow");
        $('dl#category_3').slideToggle("slow");
        return false;
    });
    $('a#automotive').click(function(){
        $('dl#category_1').slideUp("slow");
        $('dl#category_3').slideUp("slow");
        $('dl#category_4').slideUp("slow");
        $('dl#category_2').slideToggle("slow");
        return false;
    });
    $('a#aerospace_defense').click(function(){
        $('dl#category_1').slideUp("slow");
        $('dl#category_2').slideUp("slow");
        $('dl#category_3').slideUp("slow");
        $('dl#category_4').slideToggle("slow");
        $('.faq h4#last').toggleClass('last');
        return false;
    });
    */
    
    
    //log(numRan + " methods have been executed");
    
    
    /* Stock Ticker */
    
    var change = $("#ticker_change").text();
    if( change.indexOf( '-' ) !== -1 ){
       	$("#ticker_change").css({'background-image' : 'url(../images/ticker_negative.png)', 'color' : '#e21c1c'});
    }
    else{
    	$("#ticker_change").css({'background-image' : 'url(../images/ticker_positive.png)', 'color' : '#2b9706'});
    }
    
    
    
    
});





