/**
 * Prevent errors from Mootools scripts
 * 
 * Whenever we replace stuff like joomlas core tooltips,
 * or tabs and like, scripts added to the head by joomla is unesseccary and can cause errors.
 * The following code will only execute if MooTools isn't loaded,
 * and will prevent the most common errors.
 *
 */
if(typeof MooTools == 'undefined')
{
	var $lambda = function(){};
	window.addEvent = Class = Events = Options = $lambda;
	Class.prototype.implement = $lambda;
}

jQuery.noConflict();
(function($) {
	$(document).ready(function(){
		$('#gcf_placeholder').css('z-index','9999');
		$("#topnav.call-for-action li:last").addClass("action-link");
		$("#topnav.call-for-action li:last").prev("li").addClass("second-last");
		
		$("body").removeClass("js-disabled").addClass("js-enabled");
		
		$("input, textarea", $("form")).focus(function(){
			$(this).addClass("focus");
			$(this).parents(".form-field").addClass("cur");
		});
		$("input, textarea", $("form")).blur(function(){
		    $(this).removeClass("focus");
		    $(this).parents(".form-field").removeClass("cur");
		});
		
		$(".search-results li:odd, .module-previews .mod:odd, table tr:even").addClass("alt");
				
		$("#article-content p:first").addClass("teaser");
		
		$("#nav li:first, .sidebar li:first-child, .ui-tabs-nav li:first-child").addClass("first");
		$(".sidebar li:last-child, .article_separator:last").addClass("last");

		$("#footer-links .fl-left li:last, #footer-links .fl-right li:last").addClass("fl-last");
		$("#footer-links .fl-right li:first").addClass("fl-first");		
				
		$("#secondary-content.sidebar .mod:first, #tertiary-content.sidebar .mod:first").addClass("firstmodule");

		$("#secondary-content.sidebar .mod:last, #tertiary-content.sidebar .mod:last").addClass("lastmodule");
		
		$('img[align*=right]').addClass("img-right");
		$('img[align*=left]').addClass("img-left");
    
    	        
        	$("a[rel='lightbox']").colorbox();
			$(".video").colorbox({"iframe":true,"innerWidth":425,"innerHeight":344}); 
		
						$().bind('cbox_open', function(){
			    $('body').css({overflow:'hidden'});
			}).bind('cbox_closed', function(){
			    $('body').css({overflow:'auto'});
			}); 
						
						$("#primary-content p.readon a.preview-link").removeClass("preview-disabled").addClass("preview-enabled");
			$("#primary-content a[rel='article-preview']").click(function(){
			    var url = $(this).attr('href');
			     $.fn.colorbox({href: url + " div.article-page", width:700, height:600});
			    return false;
			});
						   
                
    
    		
		
		$.fn.topLink=function(s){s=jQuery.extend({min:400,fadeSpeed:500},s);return this.each(function(){var e=$(this).hide().click(function(){$.scrollToTop(0,300);return false;})
	$(window).scroll(function(){if($(window).scrollTop()>=s.min){e.fadeIn(s.fadeSpeed);}else{e.fadeOut(s.fadeSpeed);}});});};
	$('#top-link').topLink();
		
		
			    		$('#topshelf .modinner').equalHeights();$('#bottomshelf .modinner').equalHeights();$('#user2 .modinner').equalHeights();				$("#top.primary-nav .menu, #topnav.primary-nav .menu").supersubs({
			minWidth: 12,
		 	maxWidth: 27,
		 	extraWidth: 1
		})		.superfish({
			delay: 1000,
			animation: {opacity:'show'},
			speed: 'normal',
			autoArrows: true,
			dropShadows: false,
			hoverClass: 'sfHover',
 			disableHI: false		});
				var taboptions = {fx:{opacity:'toggle',duration: 1},cookie:{expires:7,path:'/'}};
				$('#tabs1').tabs(taboptions);
				$('#tabs2').tabs(taboptions);
				
/* @group Custom Themelet JS */


 /* @end */ 
$(".leading").wrapInner('<div class="leading-inner"></div>');
$(".leading-inner").append('<span class="new-badge"></span>');
$("#secondary-content li.banneritem:odd").addClass('alt');
$("#explorer .newsflash p:last").addClass('last');
$("#article-content ul.compound li:odd").addClass('alt');
$("#article-content ul.compound li:last").addClass('last');
$("#article-content ul.compound li:last").prev("li").addClass("last");
$("#primary-content div.article-row:last").addClass('last');
$("#article p:first").addClass('teaser');
$("#sociableList li:last").addClass('last');
$("#sociableList li:last").prev("li").addClass("last");
$("#sociableList li:first").addClass('first');
$("#sociableList li:first").next("li").addClass("first");
$(".mod.ads125 li:odd").addClass('alt');	});
})(jQuery);