/**
 * 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 ()
{


		if (getURLParam("start") !="") {

			var item = getURLParam("start");

			// get properties
			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 st_desc		= ob_li.children (".div_description").text ();

			$("#div_header h2").html(st_name);
			$("#div_header h3").html(st_desc);

			//openSlideshowThumbnails(st_name);
			//var in_id_video = ob_li.children (".div_id").text ();
			//$ ("#div_addcomment .div_id").text (in_id_video);

			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/" + ob_li.children (".div_name").children ("a").text ().replace (/\s/g, "_").toLowerCase () + ".xml"
				, mode:    "ondemand"
			});

		}
	


	/* show banner */
	
	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();
		
		
			st_img = $ (this).children ("image").text ();
			$("#div_header").append("<img id='header_img' alt='header' src='videoimgs/" + st_img + "' /><h1>"+st_presentation_name+"</h1>\n<h2>"+st_presentation_description+"</h2>");

				var textbox = $(".li_channel_selected .div_description").html();

				$("#div_text").html( textbox );
	
		
		
		//	$("#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();
		}
	});

//console.log("set/" + file_imgset + ".xml");

	$.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 ("<div class='jCarousel_container'><button class='prev''></button><div class='jCarousel'><ul id='ul-slides'>" + out + "</ul></div><button class='next'></button></div>");
				
				$("#div_slides img").click (
						function () {
							var time = $ (this).attr("time");
							setSeek( time )
						}
					);
				
						$("#div_slides .jCarousel").jCarouselLite({
							btnNext: "#div_slides .next",
							btnPrev: "#div_slides .prev",
							mouseWheel: true,
							speed: 300,
							visible: 6
						});
				
				


				//$ ("#div_slides").html ("<ul id='ul-slides' class='jcarousel-skin-tango' >" + out + "</ul>");
				
				
					
				//$("#ul-slides").jcarousel( {scroll:5} );
				
				
				
            	$ ("#ul-slides li 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",
//                            left: $ (this).offset ().left - 100 + "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
	);
	
}

/**
 * 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)
{
}

