/**
 * User functions' set
 *
 * initLoad ()
 * clickVideo (ob_li, st_type)
 * clickCategory (ob_li)
 * clickPlaylist (ob_li)
 * clickChannel (ob_li)
 * clickAddComment (ob_li)
 * streamInfo (ob)
 *
 * @version 1.2
 * @author Max Kiusso, Michal Luberda
 */

/**
 * initLoad
 */
 
 
function setSeek (seekvalue)
{
	var flashMovie = getFlashMovieObject ("stplayer");
	// prima i parametri, poi il comando
	flashMovie.SetVariable("/:jcommandvalue", seekvalue );
	flashMovie.SetVariable("/:jcommand", "seek" );
}

function initLoad ()
{

	/* show banner */
	
	channel_id = $(".li_channel_selected .div_id").text ();
	$ ("element", window._wtv.xml).each (function () {
		if ( $(this).children ("id").text () == channel_id ) {
			st_img = $ (this).children ("image").text ();
			$("#div_container").append( "<img id='header_img' alt='header' src='videoimgs/" + st_img + "' />" );
		}
	});

	/* get imgset file name */
	$ ("element", window._wtv.xml).each (function () {
		if ( $(this).children ("id").text () == channel_id ) {
			file_imgset = $ (this).parent("node").children("node").children("name").text().replace(/ /g,"_").toLowerCase();
		}
	});

	
	
	$.ajax ({
		type:     "GET",
		url:      "set/" + file_imgset + ".xml",
		dataType: "xml",
		success:  function (data) {
			window._wtv.slidesxml       = data;
			window._wtv.slidesxmlLoaded = true;
		},
		error:    function (XMLHttpRequest, textStatus, errorThrown) {
			alert("slides loading error");
			
		}
	});

	intval = window.setInterval (
		function () {
			if (window._wtv.slidesxmlLoaded) {
				
				var out = "";
				
				// get the slides
				window.clearInterval (intval);

				$.each (
					  $( "data" , window._wtv.slidesxml ).children()
					, function () {
						out += "<li><img src='" + $( this ).attr("src").replace("imgset/","imgset/t_") + "' time='" + $( this ).attr("cuepoint") + "' /><div class='title'>" + $( this ).attr("alt") + "</div></li>";
					}
				);
				
				$ ("#div_slides").html ("<ul id='ul-slides' class='jcarousel-skin-tango' >" + out + "</ul>");
				
				
				$("#div_slides img").click (
						function () {
							var time = $ (this).attr("time");
							setSeek( time )
						}
					);
					
				$("#ul-slides").jcarousel( {scroll:8} );
				
				var textbox = $(".li_channel_selected .div_description").html();
				$("#div_text").html( textbox );
				
            	$ (".jcarousel-item img").hover (
            	    function () {
            	        var offset_x = ($ (this).offset ().left - $ ("#div_slides").offset ().left < 100) ?
            	            31 :
            	            (($ (this).offset ().left - $ ("#div_slides").offset ().left > 800) ?
            	                154 :
            	                95
            	            );
                        $ ("#div_tooltip").css ({
                            left: $ (this).offset ().left - $ ("#div_slides").offset ().left - offset_x + "px",
                            top:  $ (this).offset ().top - 230 + "px",
                            width: "300px",
                            height: "225px"
                        });
                        $ ("#div_tooltip img").attr ("src", $ (this).attr ("src").replace ("/t_", "/"));
            	    },
            	    function () {
                        $ ("#div_tooltip").css ({
                            left: "-1000px",
                            top:  "-1000px",
                            width: 0,
                            height: 0
                        });
                        $ ("#div_tooltip img").attr ("src", "");
            	    }
            	);
				
			}
		},200
	);
	
}

 
function initLoad2 ()
{

	var tabMenu = new ddtabcontent("menutabs");
	tabMenu.setpersist(true);
	tabMenu.setselectedClassTarget("link"); //"link" or "linkparent"
	tabMenu.init();
	
	
	if (getURLParam("start") !="") {

		var item = getURLParam("start");
		var ob_li = $ ("#li_video_" + item);
		var st_video	= ob_li.children (".div_videoid").text ();
		var st_bitrate	= ob_li.children (".div_bitrate").text ();
		var st_url		= ob_li.children (".div_url").text (); // live parameter
		var st_name		= ob_li.children (".div_name").text ();
		var file_imgset = st_name.replace(/ /g,"_").toLowerCase();
		var st_desc		= ob_li.children (".div_description").text ();
		var st_img		= ob_li.parent().parent().children(".div_image").children("img").attr("src");
	
		$("#div_header").append("<img id='header_img' alt='header' src='" + st_img + "' /><h1>"+st_name+"</h1>\n<h2>"+st_desc+"</h2>");

		
		window._wtv.playlist = false;
		window._wtv.type = "video";
		
		
		// open video
		openVideo ({
			  url: st_url || videoconfig.videoserver
			, file: st_video
			, speed: st_bitrate
			, live: false
			, skin: videoconfig.skin || ''
			, slidesinterface: true
			, title: st_name
		});
		// open slideshow
		openSlideshow ({
			  webtvid: videoconfig.id
			, setid:   ob_li.children (".div_imageset").text ()
			, path:    videoconfig.path
			, url:     window._path + "set/" + file_imgset + ".xml"
			, mode:    "ondemand"
		});
		
		openSlideshowThumbnails(st_name);
			
	} else {
	
			channel_id = $(".li_channel_selected .div_id").text ();
			$ ("element", window._wtv.xml).each (function () {
				if ( $(this).children ("id").text () == channel_id ) {
					/* set presentation name */
					st_presentation_name = $(this).parent("node").children("node:first").children("name").text();

					/* set presentation description */
					st_presentation_description = $(this).parent("node").children("node:first").children("element").children("description").text();
				}
			});

			/* get imgset file name */
			$ ("element", window._wtv.xml).each (function () {
				if ( $(this).children ("id").text () == channel_id ) {
					file_imgset = $ (this).parent("node").children("node:first").children("name").text().replace(/ /g,"_").toLowerCase();
				}
			});


		 	openSlideshowThumbnails(st_presentation_name);
	}
console.log("test");	
	var textbox = $(".li_channel_selected .div_description").html();
    $("#div_text").html( textbox );
}

/**
 * clickVideo
 *
 * @param object ob_li clicked li element
 * @param string st_type VIDEO or LIVE
 */
function clickVideo (ob_li, st_type)
{
}

/**
 * clickCategory
 *
 * @param object ob_li clicked li element
 */
function clickCategory (ob_li)
{
}

/**
 * clickPlaylist
 *
 * @param object ob_li clicked li element
 */
function clickPlaylist (ob_li)
{
}

/**
 * clickChannel
 *
 * @param object ob_li clicked li element
 */
function clickChannel (ob_li)
{
}

/**
 * clickAddComment
 *
 * @param integer video or playlist id
 */
function clickAddComment (in_id)
{
}

/**
 * streamInfo
 *
 * @param object ob
 */
function streamInfo (ob)
{
}

