// settings and global functions
var ntv = new Object();
ntv = {
	debug: true,
	hasFirebug: "console" in window && "firebug" in window.console,
	random:	Math.round( Math.random() * 999998 + 1 ),
	basepath: window.location.protocol+"//"+window.location.host,
	log: function( message ) {
		if( this.debug && this.hasFirebug ) {
			console.debug( message );
		}
	}
};


function videotracking() {

}



// jquery functions


(function($) {

	/*
	$.fn.ntv_media_nav = function( options ) {
		var settings = $.extend({
			"visible": 5,
			"width": 117
		}, options);

		return this.each( function() {

			var $list = $( this ).find( "ul" );
			var count = $list.find( "li" ).size();
			var $backward = $( "<a />" ).attr( { "href": "", "title": "mehr", "class": "backward" } );
			var $forward = $( "<a />" ).attr( { "href": "", "title": "mehr", "class": "forward" } );

			$list.css( "width", "2000px" );

			ntv.log( count );

			// append nav buttons
			$( this ).append( $forward ).append( $backward );

			ntv.log( this );
			$list.animate( { "left": "-100px" }, 10000 );
			$( "li", this ).each(function(){
				var left = $( this ).css("left");
				ntv.log(left);

			});


			$backward.click( function() {

			});

			$forward.click( function() {

			});

		});

	};
	*/

	$.fn.ntv_media_detail = function( options ) {
		var settings = $.extend({
			backgroundColor: "#383838",
			linkColor: "#FFFFFF"
		}, options);

		return this.each( function() {
			var $container = $( this );
			var $link = $( this ).find( "a" );
			var $detail = $( this ).find( ".detail" );
			var backgroundColor = $( this ).css( "backgroundColor" );
			var timeout = null;

			$link.hover(
					// over
					function() {

						timeout = window.setTimeout(function(){
							$container.css( "backgroundColor", settings.backgroundColor );
							$detail.css( "backgroundColor", settings.backgroundColor );
							$detail.show();
						}, 200);
					},
					// out
					function() {
						window.clearTimeout( timeout );
						$detail.hide();
						$container.css( "backgroundColor", backgroundColor );
						$detail.css( "backgroundColor", backgroundColor );
					}
			);
		});

	};


	$.fn.ntv_player = function(settings) {


		var options = $.extend(
				{
					w3c: $.browser.msie ? false : true,
					bgcolor: "#2A425E",
					advertising: true,
					modus: "vod",
					theme: "video"
				}, settings
		);


		var src = relat_prefix + "flash/NTV_Player_AS3.swf?f="+options.video+"&pm="+options.modus;
		if(options.advertising == true){
			src = src + "&preroll=http://ad.de.doubleclick.net/adx/www.teleboerse.de/" + ivw_code + ";pack=;theme="+options.theme+";"+ip_additional+"playersize=" + options.width +  "x" + options.height + ";sz=320x240;tile=10;pos=pre;dcmt=text/xml;ord="+ip_random;
		}

		return this.each(function(){
			$(this).flashembed(
					{
						src: src,
						width: options.width,
						height: options.height,
						w3c: options.w3c,
						bgcolor: options.bgcolor
					});
		});
	};


	$.fn.ntv_send_toggle = function() {
		return this.each(function() {
			$( this ).click( function() { return false; } );
			$( this ).toggle(
					function() {
						$( ".player" ).fadeOut( "fast",
							function() {
								$( ".send_overlay" ).fadeIn( "fast" );
							}
						);
					},
					function() {
						$( ".player" ).fadeIn( "fast",
							function() {
								$( ".send_overlay" ).fadeOut( "fast" );
							}
						);

					}
			);
		});
	};

	// play buttons
	$.fn.ntv_video_play = function() {
		return this.each( function() {
			try {
				var a = $(this).find( "a" ).get( 0 );
				var href = a.href;
				$( a ).append( "<span class='play'></span>" ).css( "cursor", "pointer" );
			} catch ( e ) {}
		});
	};

	// settings and global functions
	var ntv = new Object();
	ntv = {
		debug: true,
		hasFirebug: "console" in window && "firebug" in window.console,
		random:	Math.round( Math.random() * 999998 + 1 ),
		log: function( message ) {
			if( this.debug && this.hasFirebug ) {
				console.debug( message );
			}
		}
	};

	$( document ).ready( function() {
		//$( "#teaser_wrapper" ).ntv_media_nav( { "visible": 6 } );
		//$( "#nav_prog" ).ntv_media_nav( { "visible": 5 } );
		$( ".faces dd" ).ntv_media_detail( );
		$( ".program ul.prog li" ).ntv_media_detail( { "backgroundColor": "#535353" } );
		$( ".sendungen ul li" ).ntv_media_detail( { "backgroundColor": "#535353" } );
		$( "div.send a" ).ntv_send_toggle();
		$( "div.more ul li" ).ntv_video_play();
	});

})(jQuery);
