		
		function is_ie6(){
		     return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
		}
     	
		// Cufon breaks iepngfix in ie6
		if(!is_ie6()){ Cufon.replace('h1'); }

        function pxDiff(current, pixels){
        	var current = parseInt(current);
        	var diff = parseInt(pixels);
        	var val = current + diff;
        	return val + 'px';
        }
        
        var isiPadOriPhone = navigator.userAgent.match(/(iPad|iPhone)/i) != null;
     	
        $.noConflict();
		jQuery(document).ready(function(){
            
            if (isiPadOriPhone){
                jQuery('#main-nav a').click(function(){ 
                    window.location = this.href
                    return false;
                })
                jQuery('#main-nav li.expandable').click(function(){
                    ul = jQuery('ul:first', jQuery(this))
                    if(ul.is(':visible')){
                        ul.slideUp();
                        return false;
                    } else {
                        ul.slideDown();
                        return false;
                    }
                });
            } else { // all other browsers
                jQuery("#main-nav").treeview({
                    animated: "fast",
                    unique: true
                });
            }


			
		    // Secondary Nav
			//=================
			
			//show current subnav child if on that page
	    	if (jQuery('.current_page_item').length > 0){
	    		var current = jQuery('.current_page_item').parents('ul:first').css('left', '125px');
	    		if (current.hasClass('company')){ jQuery('#company').css('color', 'white'); }
	    		if (current.hasClass('downloads')){ jQuery('#downloads').css('color', 'white'); }
	    		if (current.hasClass('media')){ jQuery('#media').css('color', 'white'); }
	    		if (current.hasClass('news')){ jQuery('#news').css('color', 'white'); }	    		
    		}
		    jQuery('#secondary-nav li').click(function(){
		    	jQuery('.' + this.id).css('z-index', '2').animate({
		    		"left": "125px"		    		
	    			}
		    		, 1000
	    		);
			    jQuery('.secondary-nav-children:not(.' + this.id + ')').css('z-index', '1').animate({
			    	"left": "10px"		    		
	    			}
		    		, 1000
	    		);
		    });
	    	
		    			
      // Extract overview bullets
      jQuery('ul.buyNowWrap').remove();
      var points = jQuery('#overview ul:last').html() ? jQuery('#overview ul:last').html() : '';
      // Add bullet points from WP if not already available via the XML
      if(jQuery('ul.bullet-points').length < 1){
        jQuery('#overview-bullets').html('<ul class="bullet-points">' + points + '</ul>');
      }
			
			// Tabs
			jQuery('.tabButton').click(function(){
				jQuery('.tab').hide();
				jQuery('.' + this.id).show();	 
			})
			jQuery('.tabButton')
				.click(function(){
					jQuery('.tabButton, #subCompareBikes').removeClass('active');
					jQuery(this).addClass('active');	
				})
			jQuery('.tabButton, #subCompareBikes')
				.hover(function(){
					jQuery(this).addClass('tabButtonOvr');
					},
					function(){
						jQuery(this).removeClass('tabButtonOvr')	;
					}
				)
			
			//========	
			// Modals
			//========
			
			// Compare bikes modal in header.php tempate as it needs access to php
	
			
			// Associate program modal
			jQuery('#buyNowLink').colorbox({
				speed: 0,
				transition: 'none',
				inline: 'true',
				width: '251px',
				height: '530px',
				href: '#buyNow',
				opacity: '0',
				onLoad: function(){ jQuery('#buyNow').show(); },
				onComplete: function(){ 
					jQuery('#colorbox')
						.css('left', pxDiff(jQuery('#colorbox').css('left'), '-400px'))
						.css('top', '210px') 
				},
				onCleanup: function(){ jQuery('#buyNow').hide(); }
			})			
			
			// Price Range modal
			jQuery('#price-range-wrap a.modal').colorbox({
				speed: 0,
				iframe: 'true',
				transition: 'none',
				width: '500px',
				height: '300px',
				opacity: '0'
			})	
						
			// Mailing List modal
			jQuery('a#mailing-list').colorbox({
				speed: 0,
				iframe: 'true',
				width: '560px',
				height: '450px',
				transition: 'none',
				opacity: '0'
			})	
					
			// Bike Image modal
			jQuery('a#current_image_link, a#current_image_text_link').colorbox({
				speed: 0,
				opacity: '0'
			})
		
			// Associate program modal
			jQuery('#find-a-dealer, #find-a-dealer-button').colorbox({
				speed: 0,
				transition: 'none',
				inline: 'true',
				width: '270px',
				height: '330px',
				href: '#dealer_flyout',
				opacity: '0',
				onLoad: function(){ jQuery('#dealer_flyout').show(); },
				onComplete: function(){ 
					jQuery('#colorbox')
						.css('left', pxDiff(jQuery('#colorbox').css('left'), '-400px'))
						.css('top', '210px') 
				},
				onCleanup: function(){ jQuery('#dealer_flyout').hide(); }
			})			
			
	    })

