$(document).ready(function(){
	$.preload = function(){
		for(var i = 0; i <arguments.length; i++){
			$("<img>").attr("src", arguments[i]);
			console.log( "Preloading: " + arguments[i] );
		}
	}

		// Expanding Articles
	$('.expanding li h4').click(function() {
		$(this).parent().toggleClass('open').find('.expand-content').slideToggle();
	});
	
	$('table.expanding td').click(function() {
		$(this).toggleClass('open').find('.expand-content').slideToggle();
	});

	// Clickable list item hack (there, I said it)
	$("ul.resource-list li").hover(function(){
		link = $(this).find("a.clickable");
		if( link.html() == null ){
			console.log("a.clickable not found. Click event was not added");
		} else {
			console.log("Click event added");
			$(this).addClass("hover clickable").css({cursor:"pointer"}).click(function(){
				window.location = link.attr("href");
			});
		}
	},function(){
		$(this).removeClass("hover clickable");
	});

	$('li.teacher').click(function(){
		var url = $(this).find('span.name a').attr('href')
		window.location = url;
	});
		
	/* GRIDS */
	   $('.grid li .qtip').each(function()
		   {
		      $(this).qtip({
		      	content: $(this).find('.tip'),
				
				position: {
						corner: {target: 'rightMiddle', tooltip: 'leftMiddle'}, /* rightMiddle 40px 30px */
						adjust: { x: -35, y: 0 }
 				},
				
				hide: { when: 'mouseout', fixed: true },
				style: {
						width: 300,
						tip: 'leftMiddle',
				        border: {
							width: 1,
							radius: 5,
							color: '#DDDDDD'	
						}
					
				}
		      });
		
		   });

	$("a.view-cart-button").click(function(){
		$("#cart-dropdown").hide();
//		tb_show( "", "#WHYDOESTHISNOTWORK", "height=400&width=620" );
		//TB_iframe=true&amp;height=400&amp;width=620
		return false;
	});
	
	$('ul.cycle').each(function() {
		var cycleTimeout = ( $(this).attr('timeout') !== undefined ) ? parseInt($(this).attr('timeout')) * 1000 : 8000
		$(this).cycle({
			fx: 'fade',
			speed: 800,
			// speedIn: 800,
			// speedOut: 1600,
			pause: 1,
			easing: 'linear',
			timeout: cycleTimeout,
			manualTrump: true,
			pager: '.cycle-control'
		});
	});
	var numOfSlides = $('ul.cycle').children().size()*16+10+"px";
	$('.cycle-control').css("width",numOfSlides);//should be number of slides * 16, but for some reason it needs more...
	
});

