// Origin.js file, all the javascript the plugin needs, it gets loaded into the footer on load
plugin_url = '';

function setup(plugin_url) {
	
	// Set up the specialty hover
	$('.specialty_holder>div').hover(function() {
		$(this).toggleClass('specialtyhot');
	});
	
	// Set up the category hover
	$('.category').hover(function() {
		$(this).toggleClass('categoryhot');
	});
	
	// Set up the category hover
	$('.thumb').mouseover(function() {
		$(this).addClass('thumbhot');
		//$('.bubble').stop(true,true).hide();
		$(this).children('.bubble').fadeIn();
	});
	

	// Set up the transcript holder {
	$("#local_transcript").click(function() {
		$("#new_transcript_holder").slideToggle();
		
		$("#local_transcript").toggleClass("open");
		
	});
		
	
	$('.thumb').mousemove(function(e) {
				
		var position = $(this).offset(); // position = { left: 42, top: 567 }
			
				
	    var x = e.pageX - position.left;
	    var y = e.pageY - position.top;
		
		$(this).children('.bubble').css('left', x - 50);
		$(this).children('.bubble').css('top', y - 65);
		

	});
	
	$('.thumb').mouseout(function() {
		
		$(this).stop(true, true);
		$('.bubble').hide();
		$(this).removeClass('thumbhot');

	});
	
	
	// Set up the thumb click
	$('.thumb').click(function() {
	
		flash_url = $("#" + $(this).attr("id") + "_flash_url").html()
		
		if ($("#video_holder").html() == "") {

			new_video = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='480' height='295' id='single1' name='single1'><param name='movie' value='" + plugin_url + "/wp-content/plugins/origin/js/mediaplayer-5.3/player.swf'><param name='allowfullscreen' value='true'><param name='allowscriptaccess' value='always'><param name='bgcolor' value='#000000'><param name='flashvars' value='file=" + flash_url + "&image=" + plugin_url + "/wp-content/plugins/origin/css/images/poster.jpg'><embed width='480' height='295' id='single2' name='single2' src='" + plugin_url + "/wp-content/plugins/origin/js/mediaplayer-5.3/player.swf' allowfullscreen='true' allowscriptaccess='always' bgcolor='#000000' flashvars='file=" + flash_url + "&image=" + plugin_url + "/wp-content/plugins/origin/css/images/poster.jpg' /></object>";
		
		} else {
		
			new_video = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='480' height='295' id='single1' name='single1'><param name='movie' value='" + plugin_url + "/wp-content/plugins/origin/js/mediaplayer-5.3/player.swf'><param name='allowfullscreen' value='true'><param name='allowscriptaccess' value='always'><param name='bgcolor' value='#000000'><param name='flashvars' value='file=" + flash_url + "&image=" + plugin_url + "/wp-content/plugins/origin/css/images/poster.jpg'><embed width='480' height='295' id='single2' name='single2' src='" + plugin_url + "/wp-content/plugins/origin/js/mediaplayer-5.3/player.swf' allowfullscreen='true' allowscriptaccess='always' bgcolor='#000000' flashvars='file=" + flash_url + "&autostart=true' /></object>";
		
		}
		
		$("#video_holder").html(new_video);
	
		$('.thumbcurrent').removeClass("thumbcurrent");
		$(this).addClass("thumbcurrent");
		$('#local_title').html($("#" + $(this).attr("id") + "_title").html());
		$('#local_description').html($("#" + $(this).attr("id") + "_description").html());
		
		$('#local_download').attr('href', plugin_url + "/redirector.php?file=" + $("#" + $(this).attr("id") + "_download").html());
		
		$('#new_transcript_holder').load($("#" + $(this).attr("id") + "_transcript").html());
		
		
					
	});

	
	// Set up the category clicker
	$('.category').click(function() {
	
		$(".categorycurrent").removeClass("categorycurrent");
		$(this).addClass('categorycurrent');
		
		new_id = $(this).attr('id') + "_holder";
		
		$("#" + new_id).slideDown();
		
		$('.specialty_holder').each(function() {
		
			if ($(this).attr('id') != new_id) {
				$(this).slideUp();
			}
			
		})
		
		$("#" + new_id + " .specialty:first").click();
		
	});
	
	
	$('.specialty_holder>div').click(function() {
	
		$(".specialtycurrent").removeClass("specialtycurrent");
		$(this).addClass("specialtycurrent");
		
		$(".inner_thumb_holder").hide();
		
		new_id = $(this).attr('id');
		
		$("#" + new_id + "_inner_thumb_holder").fadeIn();
		$("#" + new_id + "_inner_thumb_holder").removeClass("hidden");
		
/* 		$("#" + new_id + "_inner_thumb_holder .thumb:first").click();	  			 */
	
	});
	
	
	// Set up the category clicker
	$('.file_category').click(function() {
		
		new_id = $(this).attr('id') + "_container";
		
		$("#" + new_id).slideDown();
		
		$('.file_category_container').each(function() {
		
			if ($(this).attr('id') != new_id) {
				$(this).slideUp();
			}
			
		})
		
	});
	
	
	if(window.location.hash) {
	
		// Split up the rel tag so we have some things to click
		target = $(".thumb[rel^=" + window.location.hash + "]").attr("rel");
		
		if (target != null) {
			clickables = target.split("::");
			
			$('#' + clickables[1]).click();
			$('#' + clickables[2]).click();
			
			$(".thumb[rel^=" + window.location.hash + "]").click();
		} else {
		}
	} else {
		
		$('.category:first').click();
		$('.thumb:first').click();
	
	}

}

