$().ready(function() {
	if($('#video_player').length > 0) {
		if(!swfobject.hasFlashPlayerVersion("1")) {
			$('#video_player').remove();
			$('#video').prepend('<video controls id="html5Fallback" style="display:block; width:640px; height:360px;"><source src="'+public_dir+'movie.mp4"></video>');
		}
	}

	if($('#flashvideoplayer').length > 0) {
		if(!swfobject.hasFlashPlayerVersion("1")) {
			$('#flashvideoplayer').remove();
			$('#video').prepend('<video controls id="html5Fallback" style="display:block; width:640px; height:360px;"><source src="'+public_dir+'movie.mp4"></video>');
		}
	}

	$("#menu .item:not(.sublist .item)").mouseenter(function() {
		if($(this).find(".sublist").length > 0) {
			$(this).find(".sublist").css("display","block");
			$("#submenu").css("display","block");
		} else {
			$("#submenu").css("display","none");
			$(".sublist").css("display","none");
		}
	}).mouseleave(function(e) {
		var hover_id = e.relatedTarget.id;
		var hover_class = e.relatedTarget.className;
		var hover_node = e.relatedTarget.nodeName;
		if((hover_id != "submenu")&&(hover_class != "subitem")&&(hover_class != "on-top")) {
			$("#submenu").css("display","none");
			$(".sublist").css("display","none");
		}
	});
	$("#submenu").mouseenter(function() {
		$(this).css("display","block");
	}).mouseleave(function(e) {
		var hover_id = e.relatedTarget.id;
		var hover_class = e.relatedTarget.id;
		if((hover_class != "item")&&(hover_class != "subitem")&&(hover_class != "on-top")) {
			$(this).css("display","none");
			$(".sublist").css("display","none");
		}
	});
	
	if($("#news_rotator").length > 0) {
		$('#news_rotator').anythingSlider({
			autoPlay: true,
			buildArrows: true,
			toggleArrows: true,
			buildStartStop: false,
			buildNavigation: false,
			delay: newsrotator_duration
		});
	}
	
	$("#content-sidebar").mouseenter(function() {
		if($(this).find(".more").length > 0) {
			$(this).find(".hideme").attr("rel","hideme");
			$(this).find(".more").addClass("hideme");
			$(this).find(".item[rel='hideme']").removeClass("hideme");
		}
	}).mouseleave(function() {
		$(this).find(".item[rel='hideme']").addClass("hideme");
		if($(this).find(".more").length > 0) {
			$(this).find(".more").removeClass("hideme");
		}
	});
	
	$("#content-sidebar .item:not(.item.top_active)").mouseover(function() {
		$(this).addClass("active");
	}).mouseout(function() {
		$(this).removeClass("active");
	});
	
	$(".video_list .item:not(.navigation .item)").live('mouseenter',function() {
		$(this).append("<div class='active'></div>");
	}).live('mouseleave',function() {
		$(this).find(".active").remove();
	});

	$('.video_list .navigation a').live('click',function(e) {
		//TODO: here could go something like a loading gif
		e.preventDefault();
		var url = $(this).attr('href');
		var this_link = $(this);
		$.get(url,function(data) {
			// update the video list
			if($('.video_list.three_col').length > 0) {
				this_link.parents('.video_list.three_col').find('ul:first').html(data.videolist);
			} else {
				this_link.parents('.video_list').find('ul:first').html(data.videolist);
			}
			// update the video list navigation
			$('.navigation ul:first').html(data.navigation);
		},'json');
	});
	
function isIE()
{
    if(navigator.userAgent.match(/MSIE \d\.\d+/))
        return true;
    return false;
}
	
function zIndexWorkaround()
{
    // If the browser is IE,
    if(isIE())
    {
        /*
        ** For each div with class menu (i.e.,
        ** the thing we want to be on top),
        */
        $("#menu .sublist,#content-sidebar .item").parents().each(function() {
            var p = $(this);
            var pos = p.css("position");
 
            // If it's positioned,
            if(pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed")
            {
                /*
                ** Add the "on-top" class name when the
                ** mouse is hovering over it, and remove
                ** it when the mouse leaves.
                */
                p.hover(function() {
                        $(this).addClass("on-top");
                    },
                    function() {
                        $(this).removeClass("on-top");
                    });
            }
        });
    }
}

zIndexWorkaround();

$('#search input[type="text"]').focus(function() {
	console.debug("test>>> "+$(this).val());
	if($(this).val()=='Suche') {
		$(this).attr('alt',$(this).val());
		$(this).attr('value','');
	}
}).blur(function() {
	if($(this).val()=='') {
		$(this).attr('value',$(this).attr('alt'));
	}
});

	$('#debug_nfo').mouseenter(function() {
		$(this).css({ width: 'auto', height: 'auto', minWidth: '100px' });
	}).mouseleave(function() {
		$(this).css({ width: '100px', height: '15px' });
	});

	$('#debug_nfo .info_headline').click(function() {
		var info_content = $(this).parents('.info').find('.info_content');
		if(info_content.hasClass('hideme')) {
			info_content.removeClass('hideme');
		} else {
			info_content.addClass('hideme');
		}
	});

	$('#debug_nfo .info_content').click(function() {
		if(!$(this).hasClass('hideme')) {
			$(this).addClass('hideme');
		}
	});

	function addCookie(ref,cookie,lifetime) {
		var expDate = new Date();
		expDate.setTime(expDate.getTime()+lifetime*86400000);
		document.cookie = ref+"="+cookie+"; expires="+expDate.toUTCString();
	}


	$('#debug_nfo .close_btn').click(function() {
		$(this).parents('#debug_nfo').remove();
		addCookie('debug_nfo',0,1);
		document.cookie = 'debug_nfo = 0';
	});

});


function onStartContent() {
    if(!vlog_send) {
        $.post(js_path+'video_log.php', {
            ad_played: ad_played,
            ad_program: ad_program,
            ipid: 'http://www.content1.de/player/play.php?p=1411',
            pid: 0,
            version_ident: '03022011',
            video_id: $('#video_player').attr('href').replace('.flv','').replace('flv:','')
        });
    }
}

function onAdVideoProgress() {
    ad_played = true;
}
