/* js enchanced functionality for dbs */

// Mootools is MODx standard javascript framework and it is used by the very useful QuickEdit
// front end editing module. I've bumped jQuery into no conflict mode which disables the $ alias
// in favour of 'jQuery' (minus quotes), and modified this file.
jQuery.noConflict();

 jQuery(document).ready(function() {

    /* Menu animations*/

	//on link hover
	jQuery("div#primary-nav a").not("a.selected").hover(function(e){
		
        // Stop current animations
        jQuery(this).stop();
        
        //fade the bg colour
		jQuery(this).css({"backgroundColor": "#FFFFFF"}).animate({"backgroundColor": "#EC008C"}, { queue: false, duration: 75 });
        
		//fade the font colour
		jQuery(this).css({"color": "#666666"}).animate({"color": "#FFFFFF"}, { queue: false, duration: 75 });
	    e.preventDefault();
    },function(e){
		
        // Stop current animations
        jQuery(this).stop();
        
		//fade the bg colour
		jQuery(this).animate({"backgroundColor": "#FFFFFF"}, { queue: false, duration: 75 });
        
		//fade the font colour
		jQuery(this).animate({"color": "#666666"}, { queue: false, duration: 75 });
	    e.preventDefault();
	});
    
    
	jQuery("#level-2-nav li a:not(.selected)").not(jQuery("#level-2-nav li li a")).hover(function(e){
		
        // Stop current animations
        jQuery(this).stop();
        
        //fade the bg colour
		jQuery(this).css({"backgroundColor": "#FFFFFF"}).animate({"backgroundColor": "#CC0066"}, { queue: false, duration: 50 });
        
		//fade the font colour
		jQuery(this).css({"color": "#4B2432"}).animate({"color": "#FFFFFF"}, { queue: false, duration: 50 });
        
        //Swap the background image
       // jQuery(this).css({"background-image": "url('../images/template/level-2-white-arrow-on-pink.gif')"})
        
	    e.preventDefault();
    },function(e){
		
        // Stop current animations
        jQuery(this).stop();
        
		//fade the bg colour
		jQuery(this).animate({"backgroundColor": "#FFFFFF"}, { queue: false, duration: 100 });
        
		//fade the font colour
		jQuery(this).animate({"color": "#4B2432"}, { queue: false, duration: 100 });
        
        //Swap the background image
       // jQuery(this).css({"background-image": "url('../images/template/level-2-purple-arrow.gif')"})
	    e.preventDefault();
	});
    
	jQuery("#level-2-nav li li a:not(.selected)").hover(function(e){
		
        // Stop current animations
        jQuery(this).stop();
        
        //fade the bg colour
		jQuery(this).css({"backgroundColor": "#FFFFFF"}).animate({"backgroundColor": "#4B2432"}, { queue: false, duration: 50 });
        
		//fade the font colour
		jQuery(this).css({"color": "#EC008C"}).animate({"color": "#FFFFFF"}, { queue: false, duration: 50 });
        
        
	    e.preventDefault();
    },function(e){
		
        // Stop current animations
        jQuery(this).stop();
        
		//fade the bg colour
		jQuery(this).animate({"backgroundColor": "#FFFFFF"}, { queue: false, duration: 100 });
        
		//fade the font colour
		jQuery(this).animate({"color": "#EC008C"}, { queue: false, duration: 100 });
        
	    e.preventDefault();
	});    
        
    /* Arrow right for links that wrap over lines - inserts an image */
    var arrow = document.createElement('img');
    arrow.className = "arrow-image";
    arrow.src= "assets/images/template/generic-arrow-right.gif";
    arrow.alt= "Read more";
    jQuery('a.arrow-right').append(arrow);
    
    
    var arrow = document.createElement('img');
    arrow.className = "arrow-image";
    arrow.src= "assets/images/template/generic-arrow-right-white.gif";
    arrow.alt= "Read more";
    jQuery('#home .driver-type-2 p a').append(arrow);
    
    var arrow = document.createElement('img');
    arrow.className = "arrow-image";
    arrow.src= "assets/images/template/generic-arrow-right-grey.gif";
    arrow.alt= "Read more";
    jQuery('#home .driver-type-1 p a').append(arrow);
    
    /* Massage the padding of the speech bubbles so they can extend without the dotted lines joining up  */
    /* Wait till window-onload if the height is less than 50 */

    if (jQuery('div.driver-type-3').height() > 50 ) {
        jQuery('div.driver-type-3').data("heightinspected", '1');

        if ((jQuery('div.driver-type-3').height() % 2) == 1) {
            jQuery('div.driver-type-3 div.driver-text').css("paddingBottom", "37px");
        }
        if ((jQuery('div.driver-type-4').height() % 2) == 1) {
           // alert("DOMREADY b4 change: " + jQuery('div.driver-type-4').height());
            jQuery('div.driver-type-4 div.driver-text').css("paddingBottom", "37px");
           // alert("DOMREADY after change: " + jQuery('div.driver-type-4').height());
        }
    }

	
 });

 
 
 // Massage speech bubbles again incase it didnt work
 window.onload = function(){
        if (jQuery('div.driver-type-3').data('heightinspected') != '1') {
        
            /* Massage the padding of the speech bubbles so they can extend without the dotted lines joining up  */
            if ((jQuery('div.driver-type-3').height() % 2) == 1) {
                jQuery('div.driver-type-3 div.driver-text').css("paddingBottom", "37px");
            }
            if ((jQuery('div.driver-type-4').height() % 2) == 1) {
              //  alert("ONLOAD b4 change: " + jQuery('div.driver-type-4').height());
                jQuery('div.driver-type-4 div.driver-text').css("paddingBottom", "37px");
              //  alert("ONLOAD after change: " + jQuery('div.driver-type-4').height());
            }
        }
 };
