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

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