$(document).ready(function() {
	$("a[rel='colorbox']").colorbox();
	var video_index = 0;
	$("a[rel='colorbox-video']").each( function() { 
		
		var video = $(this)
		$(this).colorbox(
			{
				'scrolling' : false,
				'current' : '',
				'href' : $(this).attr("href")+"?nojQuery=1",
				'rel' : 'video-colorbox-'+(video_index++),
				'onOpen' : function() {
					if ($(video).attr('href') == "/video/index-demo")
					{
						_gaq.push(['_trackPageview', '/virtual/video/demo/-'+window.location.pathname],['_trackEvent', 'video-demo', 'play', window.location.pathname]);
					}
				},
				'onCleanup' : function() {
					// IE7 doesn't clean them always properly when done from innerHTML alone, so let's clean using DOM removal
					$("#cboxLoadedContent").find("embed").remove();
					$("#cboxLoadedContent").find("object").remove();				
				}
			}
	)});

	/**
	 * 
	 * This code makes it a separate unit for the 
	 * style of "sidebar-testimonials-bottom".
     * The right menu is in the file "RightSideBar.php" - 
     * function "rightSideBar".
     *
     * 	;==============================================================================
	 *	; --[26/5/2010] Comments (Bunin Georgy):
	 *	;		stopped using 
	 *  ; 		changed sidebar-testimonials-bottom to sidebar-testimonials-bottom-old
	 *	;==============================================================================
	 *
	 * */
	if($("#sidebar-testimonials-bottom-old").length){
		var top = 	$("#left-side").position().top +
				$("#left-side").height() -
				$("#sidebar-testimonials-bottom").height()-40;
		
		if($("#sidebar-testimonials-bottom").position().top < top){
			$("#sidebar-testimonials-bottom").css({
				'position' : 'absolute',
				'top' : top,
				'width' : '255px',
				'margin-top' : '20px',
				'left' : $("#right-side").position().left
			});
			$("#sidebar-testimonials-bottom div.box-top").addClass("box-container-top");
			$("#sidebar-testimonials-bottom div.box-spacer").addClass("box-container-bottom").removeClass("box-spacer");
			//$("#sidebar-testimonials").html('<div class="box-container-top"></div><div class="box-container-center">'+$("#sidebar-testimonials").html()+'</div><div class="box-container-bottom"></div>');
		}
		// IE7 has an issue with repositioning the testimonial box, and it displays it empty
		// It turns out that changing this element position to static and then to relative solves the problem:)
		$(".testimonial div.txt-container").css("position","static");
		$(".testimonial div.txt-container").css("position","relative");
	}
	
	$(".ownerPlayer").each(function(){
		eval('var baseParams = ' + $(this).attr('rel'));
		var flashvars = {
			videoLocation : baseParams.videoSrc,
			HD : baseParams.videoHQSrc
		};
		var params = {
			play : "true",
			loop : "true",
			menu : "false",
			quality : "best",
			scale : "showall",
			wmode : "opaque",
			devicefont : "true",
			allowfullscreen : "true",
			allowscriptaccess : "sameDomain",
			base : "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0"
		};
		var attributes = {
			id : baseParams.id,
			align : "middle"
		};
		swfobject.embedSWF(baseParams.src, $(this).attr('id'), baseParams.width, baseParams.height, "9.0.0", "/server/js/lib/swfobject/expressInstall.swf", flashvars, params, attributes);
	});
	
});
