function commonTemplate(item) {
	return "<option value='" + item.Value + "'>" + item.Text + "</option>"; 
};

function commonTemplate2(item) {
	return "<option value='" + item.Value + "'>***" + item.Text + "***</option>"; 
};
		
function commonMatch(selectedValue) {
	return this.When == selectedValue; 
};

$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}


$(document).ready(function(){
	
	$("#javascriptwarning").remove();
	
	// Tell People to upgrade from IE 5
	if ($.browser.msie) {
		if($.browser.version < 6) {
			$("#body").prepend('<div class="infobar"><img src="layout/warning.png" style="float: left;" /><p style="float: left; height: 20px; margin-top: 5px;">You are using Internet Explorer 5. Please upgrade your browser to increase safety and your browsing experience. Choose one of the following links to download a modern browser: <a href="http://www.getfirefox.com" target="_blank"> Firefox</a>, <a href="http://www.opera.com/download/" target="_blank"> Opera</a>, <a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" target="_blank"> Internet Explorer</a> </p></div>');
		}
	}
	
	var content = 0;
	var drw_class = 0;
	
	 $.ui.accordion.animations.superbounce = function(options) {
		this.slide(options, {
			easing: "easeInOutQuad",
			duration: 750
		});
 	};
	 
	$("#example").accordion({
			header: 'a.head', 
			active: false,
			autoHeight: false,
			alwaysOpen: false,
			navigation: false,
			animated: "superbounce"
	})
	
	$("#articles_list").sortable({
		handle : '.handle',
		update : function () {
			$("input#test-log").val($('#articles_list').sortable('serialize'));
		}
	});
	
	$('a[rel*=facebox]').facebox({
		loading_image : '../../../layout/loading.gif',
		close_image   : '../../../layout/closelabel.gif'
	});
      
	$("#websiteslist").hide();
	$("#reveallist").click(function(){
		
		$(this).next("#websiteslist").slideToggle(1500, "easeOutQuad");
		
	});
	
	$('a[rel*=drw]').click(function () {
		
		content = "#" + this.href.split('#')[1];
		drw_class = this.href.split('#')[1];
		
		if ($('#drw').height() > 0) {
			
			if($('#drw').hasClass(this.href.split('#')[1])) {
				$('#drw').removeClass(this.href.split('#')[1]);
				$('#drw').animate(
					{height: 0},
					500,
					"easeInOutQuad",
					function() {
						$('#drw').empty()
					}
				);
			} else {
				$('#drw').removeClass();
				$('#drw').animate(
					{height: 0},
					500,
					"easeInOutQuad",
					function() {
						
						$('#drw').empty()
						$(content).clone(true).appendTo('#drw')
						h = $(content).height() + 40;
					
						$('#drw').animate( { height: h }, {duration:500, easing: "easeInOutQuad" } );
						$('#drw').addClass(drw_class);
					}
				);
				
			}
			
		} else {
				
			content = "#" + this.href.split('#')[1];
			$(content).clone(true).appendTo('#drw')
			h = $(content).height() + 40;
			$('#drw').animate( { height: h }, {duration:500, easing: "easeInOutQuad" } );
			$('#drw').addClass(this.href.split('#')[1]);
				
		}				 

		
								
		return false;
	});
	
	// This is the easiest fix for the stupid, stupid Internet Explorer 6 sticky footer
	// If people haven't got js they need to move with the times
	if($(window).height() > $("#wapper").height()) {
		$("#base").css("height",(40 + $(window).height()) - $("#wapper").height());
	}
	
	$('A[rel="external"]').click( function() {
		window.open( $(this).attr('href'), $(this).attr('title'), 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left = 200,top = 200' );
		return false;
	});
	
});



tinyMCE.init({
	mode : "exact",
	elements : "articles_text,categories_text,sections_text",
	theme : "simple"
});
