var flashvars = {};
	var params = {
	allowFullScreen: "true",
	allowScriptAccess: "always",
    wMode: "opaque"
};

	var attributes = {};
	var myVideo = "http://www.youtube.com/v/hnNLOOh6JlI&amp;hl=en_GB&amp;fs=1&amp;rel=0";

	swfobject.embedSWF(myVideo, "youtube-video", "420", "258", "9.0.0", false, flashvars, params, attributes);

  
    function ImgError(source) {
        source.src = rootPath + "Images/Temp/spacer.gif";
        source.onerror = "";
        return true;
    };

    
/*
	OnLoad
*/
	$(function () {

	    var TS_additional = 320;

	    var menu_opacity = 0.2;
	    var busy = 0;

	    $(".videolink").click(function () {
	        myVideo = $(this).attr("href");
	        $(".videolink img").css({ 'border': 'none', 'margin': '0', 'width': '104px', 'height': '63px' });
	        $(this).find("img").css({ 'width': '98px', 'height': '57px', 'border': '3px solid #00cbcd' });
	        swfobject.embedSWF(myVideo, "youtube-video", "420", "258", "9.0.0", false, flashvars, params, attributes);
	        return false;
	    });


	    /*
	    Initialise Related Content
	    */

	    initRelatedContent = function (parent) {

	        // Get total children
	        var totalChildren = $(parent + " div.scroll-panel-container").size();
	        // Calculate widths
	        var childWidth = 106;
	        var containerWidth = totalChildren * childWidth;
	        // ammount the parent will need to move to display each item
	        var difference = childWidth;
	        // Get the maximum left point (to stop it from falling off the edge of the world...)
	        var endOfLine = containerWidth - difference * 3;
	        debug(endOfLine);

	        // Remove css scrollbar 
	        $('div.related_content_mask').css("overflow", "hidden");

	        if (totalChildren > 1) {
	            //var lis = $(parent + " div.scroll-panel-container").children().size();
	            $('div.related_content_mask').height($(parent).find('div.scroll-panel-container').height());
	        }
	        else {
	            var lis = $(parent + " div.scroll-panel-container").children().size();
	            if (lis < 6) {
	                $('div.related_content_mask').height(51);
	            }
	            else {
	                $('div.related_content_mask').height($(parent).find('div.scroll-panel-container').height());
	            }

	        }

	        // Set container width
	        $(parent).width(containerWidth);

	        if (totalChildren > 3) {

	            // Show controls
	            $('#related_content_controls').css("display", "block");
	            $('#related_content_controls .left');

	            $('a.related_scroller').click(function () {

	                // store the clicked anchor as an object for ease of use in the function
	                var selectedLink = $(this);

	                // check current CSS left value and * 1 so its treated as a number not a string
	                var containerPosLeft = $(parent).css('left').split('px')[0] * 1;
	                debug(containerPosLeft);

	                if (selectedLink.hasClass('left') && !busy && containerPosLeft != 0) {
	                    // Prevent further calls
	                    busy = 1;
	                    // calculate new location
	                    var newLoc = containerPosLeft + difference * 3;

	                    // Selection number
	                    var nextNum = ((-containerPosLeft + childWidth) / childWidth) - 2;
	                    var prevNum = nextNum + 1;

	                    // if its the last element fade out controls					
	                    if (newLoc == 0) {
	                        $('#related_content_controls .left img').animate({ opacity: 0.2 }, 200);
	                    }
	                    // animate content
	                    $(parent).animate({ left: newLoc }, TS_additional, function () {
	                        relatedComplete();
	                    });
	                    $('#related_content_controls .right img').animate({ opacity: 1 }, 500);
	                }
	                if (selectedLink.hasClass('right') && !busy && containerPosLeft > -endOfLine) {
	                    // Prevent further calls
	                    busy = 1;
	                    // calculate new location
	                    var newLoc = containerPosLeft - difference * 3;

	                    // Selection number
	                    var nextNum = ((-containerPosLeft + childWidth) / childWidth);
	                    var prevNum = nextNum - 1;

	                    $('.paging_container .dot_' + prevNum).animate({ opacity: 0.2 }, 200);
	                    $('.paging_container .dot_' + nextNum).animate({ opacity: 1 }, 200);

	                    // if its the last element fade out controls
	                    if (newLoc <= -endOfLine) {
	                        $('#related_content_controls .right img').animate({ opacity: 0.2 }, 200);
	                    }
	                    // animate content
	                    $(parent).animate({ left: newLoc }, TS_additional, function () {
	                        relatedComplete();
	                    });
	                    //debug(newLoc);

	                    // Lazyness? Setting the opposte arrows oppacity to full evertyime instead of checking
	                    // this isnt hard to update... just low on time as per...
	                    $('#related_content_controls .left img').animate({ opacity: 1 }, 500);
	                }

	                return false;
	            });

	        } else {
	            $('a.related_scroller.right, a.related_scroller.left').hide();
	        }

	    };

	    // Call Init related content function
	    initRelatedContent(".related_content_container");

	    /*
	    Related Content scroller
	    */

	    relatedComplete = function () {
	        busy = 0;
	    }

	});




