﻿/// <summary>
/// After a fully load, the window will be resized
/// </summary>
$(window).load(setSize);

/// <summary>
/// Document Ready
/// </summary>
$(function () {
    setSize();
    
    $(window).resize(setSize);
    
    $("li.selected").parents("ul").css("display", "block");
    $("li.selected ul:first").show();
    
    var wmv = $('a[href$="wmv"]');
	//var wav = $('a[href$="wav"]');       
	if(wmv.exists()){
		EnsureScript('mediaplayer.js', typeof(mediaPlayer) != 'undefined' ? typeof(mediaPlayer.attachToMediaLinks) : 'undefined');
		ExecuteOrDelayUntilScriptLoaded(
		function() {
		   if (Silverlight.isInstalled('2.0')) {
		       mediaPlayer.createOverlayPlayer();
		    	wmv.each(function() {
		        	var parent = $(this).parents("div:first");
					mediaPlayer.attachToMediaLinks(parent[0], ["wmv","wma","mp3","mp4", "wav"],'');
		  		});
			}
		}, 'mediaplayer.js');
	}
});

/// <summary>
/// Function to check if an element exists
/// </summary>
$.fn.exists = function () {
    return ($(this).length > 0);
}

/// <summary>
/// Function to check if an element has Children of a given element
/// </summary>
$.fn.hasChildren = function (element) {
    return $(this).find(element).length > 0;
}

function setSize() {
	var workspace = $("#s4-workspace");
	var width = workspace.width();
	var height = $(document).height(); 
	var containerHeight = height - 208 - workspace.position().top;
		
	$("div.main-container").height(containerHeight).width(width-5);
	$("div#s4-leftpanel").height(containerHeight);
}
