$jQ = jQuery.noConflict();//Avoids conflict with mooTools

/*   alert("THIS WORKED");    */

/********************************/
/****        MAIN_MENU       ****/
/********************************/

/* WITHOUT SUPER SUBS (FIXED WIDTH)
$jQ(document).ready(function(){ 
   $jQ("#main_menu ul.level_1").addClass("sf-menu");
   $jQ("#main_menu ul.level_1").superfish({
     delay:1000,                                   // delay on mouseout
     animation:{opacity:'show',height:'show'},    // fade-in and slide-down animation 
     speed:'normal',                              // faster animation speed 
     autoArrows:true,                             // set to false to disable generation of arrow mark-up 
     dropShadows:true                             // set to false to disable drop shadows 
   });  
}); 
*/

// WITH SUPER SUBS (VARIABLE WIDTH)
$jQ(document).ready(function(){ 
   $jQ("#main_menu ul.level_1").addClass("sf-menu");
   $jQ("ul.sf-menu").supersubs({ 
       minWidth:    12,   // minimum width of sub-menus in em units 
       maxWidth:    30,   // maximum width of sub-menus in em units 
       extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                          // due to slight rounding differences and font-family 
   }).superfish({
     delay:0,                                   // delay on mouseout
     animation:{opacity:'show',height:'show'},    // fade-in and slide-down animation 
     speed:'normal',                              // faster animation speed 
     autoArrows:false,                             // set to false to disable generation of arrow mark-up 
     dropShadows:false                             // set to false to disable drop shadows 
   });  
}); 

/*
$jQ(document).ready(function(){ 
     $jQ('li.submenu.l1 ul li a').hover(function() {
         $jQ(this).parent().parent().parent().addClass('highlight_parent');
     }, function() {
         $jQ(this).parent().parent().parent().removeClass('highlight_parent');
     });
}); 
*/


$jQ(document).ready(function() {
   $jQ("div.box_content p:last-child").addClass("last");
});

$jQ(document).ready(function() {//Ensures captions are notwider than images
   $jQ("div.caption").each(function() {
      var imgWidth = $jQ(this).prev().width();
      $jQ(this).width(imgWidth);
   }); 
});
$jQ(function(){//Adds margins to left floated images in the specified column
    $jQ("img","#Main_Left").each(function(){
            if($jQ(this).css('float') == 'left'){
                    $jQ(this).css('margin', '5px 20px 10px 0px');
            }
    });
});
$jQ(function(){//Adds margins to right floated images in the specified column
    $jQ("img","#Main_Left").each(function(){
            if($jQ(this).css('float') == 'right'){
                    $jQ(this).css('margin', '5px 0px 10px 20px');
            }
    });
});

$jQ(function(){//Add padding to td in calendar that do not contain a link
    $jQ("div.calendar td")
       .filter(function(){//That does not contain a a tag
           return $jQ("a",this).length==0;
    }).css({//Add Padding
      padding:"2px 6px"
    });
});

$jQ(document).ready(function() {
 
	// Add pdf icons to pdf links
	$jQ("a[href$='.pdf']").addClass("pdf").attr("target", "_blank");
 
	// Add word icons to document links (doc, rtf, txt)
	$jQ("a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").addClass("word");
 
	// Add zip icons to Zip file links (zip, rar)
	$jQ("a[href$='.zip'], a[href$='.rar']").addClass("zip"); 
 
	// Add email icons to email links
	$jQ("a[href^='mailto:']").addClass("email");
	
  // Add lightbox icons to lightbox links
	$jQ("a[rel^='lightbox']").addClass("textlightbox");
	$jQ("a[rel^='lightbox']:has(img)").removeClass("textlightbox").addClass("imglightbox");
	
	// Add a class of odd to every other row in a table
	$jQ("tr:nth-child(odd)").addClass("odd");
	
	// Add a class of last to the last list item
	$jQ("ul.test li:last-child").addClass("last");
	
	// Add a class of 3rd to every 3rd list item
	$jQ("ul.test li:nth-child(3n)").addClass("3rd");
	
	// Add a rel no follow attribute to links in the mincalendar -  search engines will not see it - but helps optilink report
	$jQ("div.calendar a").attr('rel','nofollow');
	
	// May be useful in the future
	//$jQ('form input[type="text"]').addClass("text");
	//$jQ('label[for="fOptIn"]').addClass("checks");
 
	//Add external link icon to external links - 
	//$jQ('a').filter(function() {
  //Compare the anchor tag's host name with location's host name
	//    return this.hostname && this.hostname !== location.hostname;
	//  }).addClass("new_win");

  //Add external link icon to external links and open in a new window
	$jQ('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("new_win").attr("target", "_blank");
	
	$jQ('#date').datepicker({dateFormat:'dd-mm-yy'});

	$jQ(function() {
		$jQ("#tabs").tabs();
	});
	
	$jQ(function() {
		$jQ("#accordion").accordion();
	});

});

// Fade image links on mouseover
$jQ(document).ready(function() {
// make sure the image is at full opacity on load
$jQ(".fade").css("opacity", "1.0");

	// Change speed/opactity of mouseover state
	$jQ('.fade').mouseover(function() {
		$jQ(this).stop().fadeTo(400, 0.3);
	});

	// Change speed/opactity of mouseout state
	$jQ('.fade').mouseout(function() {
		$jQ(this).stop().fadeTo(500, 1.0);
	});
});

