
// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetAbout.js
function WidgetAboutSaved()
{
	var text = window.object.about_text;
	var reg = new RegExp("(\n)", "g");
	text = text.replace(reg, "<br />");
	if (text.length > 0)
	{
		$('.empty_about_me').remove();
	}
	$('#widget_about_main').html(text);
}

$(document).ready(function()
{
	if (typeof(about_authorized_xhtml) != 'undefined')
	{
		var html = $('#widget_about_main').html();

		html = html.replace(/&lt;/gi, '<');
		html = html.replace(/&gt;/gi, '>');
		html = html.replace(/&amp;/gi, '&');

		$('#widget_about_main').html(html);
	}
});


// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetAbuse.js
$(document).ready(function()
{
	$('.abuse').click(function()
	{
	    var url = $(this).attr('class').split(' ');
		document.location.href = unescape(url[1]) + "/tools/abuse/?blog=" + unescape(url[2]) + "&url=" + unescape(url[3]);
		return false;
	});
});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetArchive.js
$(document).ready(function() {
	//generateArchiveLinks();
});

function generateArchiveLinks()
{
	$('.archive_link').remove();
	$('.archive_link_active').remove();

	if (getvar('content_datas') != false)
	{
		datas = new Array;
		datas = eval('('+getvar('content_datas')+')');

		for (month in datas['archives'])
		{
			var new_li = $('#archive_first_li').clone().appendTo('#archive_main');
			$(new_li).attr('id', 'li_'+month);
			$('#li_'+month+' a').attr('href', '/'+getvar('content_next')+'/'+month);
			$('#li_'+month+' a').attr('onclick', 'archiveLinkClicked(\'li_'+month+'\', \''+month+'\'); return false;');
			$('#li_'+month+' a').text(datas['archives'][month]);
			if (content_date == month)
			{
				$('#li_'+month).attr('class', 'archive_link_active');
			}
			else
			{
				$('#li_'+month).attr('class', 'archive_link');
			}
		}

	}
}

function archiveLinkClicked(linkid, month)
{
	$('#li_'+getvar('content_date')).attr('class', 'archive_link');
	content_date = month;
	$('#'+linkid).attr('class', 'archive_link_active');
	getVideos(1, month);
	return false;
}

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetConfigurator.js
refreshTheme = function(id) {
	$('#theme_'+id).val();
	var pattern = /\/theme\.css/g;

	var newPattern = '/css\\/styles\\/'+$('#theme_'+id).val()+'\\/theme\\.css/g';
	newPattern = eval(newPattern);

	$('link[@rel*=style]').each(function(i)
	{
		if(this.href.match(pattern) && !this.href.match(newPattern))
		{
			this.href = this.href.replace(this.href, '/css/styles/'+$('#theme_'+id).val()+'/theme.css');
		}
	});

	applyCorners();
	applyPlayerColor();
};

$(document).ready(function(){

	//display videoblog configurator
    $('#user_options_button').click(function() {
		$('embed').hide();

    	window.scrollTo(0,0);

        $('#opt_transparent_layer').show();
		$('#opt_transparent_layer').css({height:$(document).height(), width: $(document).width()});
			var ie7 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 7.0") != -1);
			if (jQuery.browser.msie && (ie7)) {
				$('#opt_transparent_layer').css({height:$(document).height(), width: $(document).width(), opacity:'0.7', filter: 'alpha(opacity = 70) progid:DXImageTransform.Microsoft.Alpha(opacity=70)'});
			}

       	$('#div_settings').show();

		$('#right_content_conf').hide();
		//$('#right_content_profile').hide();
		$('#right_content_theme').hide();
		$('#div_cat_themes').hide();
		$('#right_content_submit').hide();

		$('#top_text_config').hide();
		//$('#top_text_profile').hide();
 		$('#top_text_theme').hide();
 		$('#top_text_home').show();

        $('#option2').addClass('menu_on');
	});

	/* When window is resized */
	$(window).resize(function() {
		$('#opt_transparent_layer').css({height:$(document).height(), width: $(document).width(), opacity:'0.7', filter: 'alpha(opacity = 70)'});
	});

	$('#user_options_button').click(function(){
		$('embed').hide();
		/* Internet Explorer Hacks */
		var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
		var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
		if (jQuery.browser.msie && (ie55 || ie6)) {
	        $('#div_settings').show();
	        $('#div_settings').css({height:'576px', width:'720px', top:'15%', left:'20%', margin:'auto'});
	        return false;
	    }
		return false;
	});

	//title bar
	$('#cancel_image').hover(function(){
			$('#cancel_image').removeAttr('src');
			$('#cancel_image').attr('src', '/img/WidgetConfigurator/close_over.gif');
	}, function(){
			$('#cancel_image').removeAttr('src');
			$('#cancel_image').attr('src', '/img/WidgetConfigurator/close_off.gif');
	});

	//menu
	$('#option2').hover(function(){
			$('#option2').addClass('menu_over');
	}, function(){
			$('#option2').removeClass('menu_over');
	});
	$('#option1').hover(function(){
			$('#option1').addClass('menu_over');
	}, function(){
			$('#option1').removeClass('menu_over');
	});
	/*$('#option2').hover(function(){
			$('#option2').addClass('menu_over');
	}, function(){
			$('#option2').removeClass('menu_over');
	});*/
	$('#option3').hover(function(){
			$('#option3').addClass('menu_over');
	}, function(){
			$('#option3').removeClass('menu_over');
	});
	/*$('#option4').hover(function(){
			$('#option4').addClass('menu_over');
	}, function(){
			$('#option4').removeClass('menu_over');
	});
	$('#option5').hover(function(){
			$('#option5').addClass('menu_over');
	}, function(){
			$('#option5').removeClass('menu_over');
	});*/

	$('#option2').click(function() {
		$('.option').removeClass('menu_on');
		$('#option2').addClass('menu_on');
		$('.div_group_themes').removeClass('cat_on');
 		$('#right_content_conf').hide(); //
 		$('#right_content_profile').hide();
 		$('#right_content_theme').hide();
 		$('#right_content_submit').hide(); //
 		$('#top_text_home').show();
 		$('#top_text_config').hide(); //
 		//$('#top_text_profile').hide();
 		$('#top_text_theme').hide();
 		$('.cancel2').show();
 		$('.button_close_r').show();
 		$('.button_open_r').show();
 		$('#div_cat_themes').hide();
 		$('#right_content_home').show();
 	});

	$('#option1').click(function() {
		$('.option').removeClass('menu_on');
		$('#option1').addClass('menu_on');
		$('.div_group_themes').removeClass('cat_on');
 		$('#right_content_conf').show(); //
 		$('#right_content_profile').hide();
 		$('#right_content_theme').hide();
 		$('#right_content_submit').show(); //
 		$('#top_text_config').show(); //
 		//$('#top_text_profile').hide();
 		$('#top_text_theme').hide();
 		$('#top_text_home').hide();
 		$('.cancel2').show();
 		$('.button_close_r').show();
 		$('.button_open_r').show();
 		$('#div_cat_themes').hide();
 		$('#right_content_home').hide();
 	});

	/*$('#option2').click(function() {
		$('.option').removeClass('menu_on');
		$('#option2').addClass('menu_on');
		$('.div_group_themes').removeClass('cat_on');
 		$('#right_content_conf').hide();
 		$('#right_content_profile').show(); //
 		$('#right_content_theme').hide();
 		$('#right_content_submit').hide();
 		$('#top_text_config').hide();
 		$('#top_text_profile').show(); //
 		$('#top_text_theme').hide();
 		$('.cancel2').show();
 		$('.button_close_r').show();
 		$('.button_open_r').show();
 		//$('#div_cat_themes').hide();
 	});*/

	$('#option3').click(function() {
		$('.option').removeClass('menu_on');
		$('#option3').addClass('menu_on');
 		$('#right_content_conf').hide();
 		//$('#right_content_profile').hide();
 		$('#right_content_theme').show(); //
 		$('#right_content_submit').show(); //
 		$('#top_text_config').hide();
 		//$('#top_text_profile').hide();
 		$('#top_text_home').hide();
 		$('#top_text_theme').show(); //
 		$('.cancel2').hide();
 		$('.button_close_r').hide();
 		$('.button_open_r').hide();
 		$('#div_cat_themes').fadeIn(1000); //
 		$('.cat_theme').hide();
 		$('.div_group_themes').removeClass('cat_on');
 		$('#right_content_home').hide();
 		//$('.cat_current').show();

				var cat_current = $('.cat_current').attr('title');
 				$('#'+cat_current).addClass('current_cat');
 				$('.current_cat').addClass('cat_on');
 				$('.'+cat_current).show();
 	});

	// Buttons added
    $('#button_profile_public').hover(function(){
			$('#pp_user_open_options').addClass('pp_left_over');
			$('#pp_user_options').addClass('pp_over');
			$('#pp_user_close_options').addClass('pp_options_right_over');
	}, function(){
			$('#pp_user_open_options').removeClass('pp_left_over');
			$('#pp_user_options').removeClass('pp_over');
			$('#pp_user_close_options').removeClass('pp_options_right_over');
	});

    $('#button_profile_public').click(function(){
			$('#pp_user_open_options').addClass('pp_left_on');
			$('#pp_user_options').addClass('pp_on');
			$('#pp_user_close_options').addClass('pp_options_right_on');
			$('#pp_user_options').css('color', '#FFF');
			window.location=partner_url+'/videos/?action=public_profile';
	});

    $('#button_disable').hover(function(){
			$('#pp_user_open_logout').addClass('pp_left_over');
			$('#pp_user_logout').addClass('pp_over');
			$('#pp_user_close_logout').addClass('pp_logout_right_over');
	}, function(){
			$('#pp_user_open_logout').removeClass('pp_left_over');
			$('#pp_user_logout').removeClass('pp_over');
			$('#pp_user_close_logout').removeClass('pp_logout_right_over');
	});

    $('#button_disable').click(function(){
			$('#pp_user_open_logout').addClass('pp_left_on');
			$('#pp_user_logout').addClass('pp_on');
			$('#pp_user_close_logout').addClass('pp_logout_right_on');
			$('#pp_user_logout').css('color', '#FFF');
			window.location=partner_url+'/videos/?action=account_details';
	});
	//

	$('.div_group_themes').hover(function(){
			var cat = $(this).attr('id');
			$('#'+cat).addClass('cat_over');
	}, function(){
			var cat = $(this).attr('id');
			$('#'+cat).removeClass('cat_over');
	});

	$('.div_group_themes').click(function() {
		// Cat themes default display: auto;
		$('.option').removeClass('menu_on');
		$('#option3').addClass('menu_on');
 		$('#right_content_conf').hide();
 		//$('#right_content_profile').hide();
 		$('#right_content_theme').show(); //
 		$('#right_content_submit').show(); //
 		$('#top_text_config').hide();
 		//$('#top_text_profile').hide();
 		$('#top_text_theme').show(); //
 		$('.cancel2').hide();
 		$('.button_close_r').hide();
 		$('.button_open_r').hide();
 		//$('#div_cat_themes').show(); //
 		$('.cat_theme').hide();
 		$('.div_group_themes').removeClass('cat_on');
 		//$('.cat_current').show();
		//
		var cat = $(this).attr('id');
			$('.cat_theme').hide();
			$('.'+cat).show();
			$('.div_group_themes').removeClass('cat_on');
			$('#'+cat).addClass('cat_on');
 	});

	$('#link_cancel_setting').click(function() {
		$('embed').show();
 		$('#opt_transparent_layer').hide(function(){
			//refreshTheme($('#video_blog_themes').val());
        	displayAjax(getvar('LOADING_MSG'));
		});
 		$('#div_settings').hide();
 	});

	$('#configuratorForm').ajaxForm(options);

	$('#configuratorForm').submit(function(){
	    var newTitle = $('#header_title').val();
	    document.title = newTitle;
		$('.header_title a').text(newTitle);
		$('.header_baseline').text($('#header_baseline').val());
		return false;
	});

	$('.configurator .cancel').click(function(){
		$('.img_select_theme').removeClass('img_select_theme');
		$('.cat_theme').removeClass('thumb_on');
		$('.cat_current').addClass('thumb_on');
		$('.img_current_theme').addClass('img_select_theme');
		//$('.img_theme').css({opacity:'0.4', filter: 'alpha(opacity = 40)'});
		//$('.img_select_theme').css({opacity:'1', filter: 'alpha(opacity = 100)'});
		//$('.configurator').slideUp("fast", function(){
		var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
		var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
		if (!jQuery.browser.msie && !(ie55 || ie6)) {
			var id = $('.checked').val();
			refreshTheme(id);
	        //return false;
	    }
		//});
	});

	$('.img_theme').hover(function(){
		var alt = $(this).attr('alt');
		if (alt == $('#img_theme_'+alt).attr('alt'))
		{
			//$('#img_theme_'+alt).css({opacity:'1', filter: 'alpha(opacity = 100)'});
			$('#div_theme_'+alt).addClass('thumb_over');
			$('#thumb_theme_'+alt).addClass('thumb_over_img');
		}
	}, function(){
		var alt = $(this).attr('alt');
		if (alt == $('#img_theme_'+alt).attr('alt'))
		{
			//$('#img_theme_'+alt).css({opacity:'0.4', filter: 'alpha(opacity = 40)'});
			//$('.img_select_theme').css({opacity:'1', filter: 'alpha(opacity = 100)'});
			$('#div_theme_'+alt).removeClass('thumb_over');
			$('#thumb_theme_'+alt).removeClass('thumb_over_img');
		}
	});

	$('.img_theme').click(function(){
		var alt = $(this).attr('alt');
		if (alt == $('#img_theme_'+alt).attr('alt'))
		{
			$('.cat_theme').removeClass('thumb_on');
			$('.thumb_theme').removeClass('thumb_on_img');
			//$('.img_select_theme').css({opacity:'0.4', filter: 'alpha(opacity = 40)'});
			$('.img_select_theme').removeClass('img_select_theme');
			$('#div_theme_'+alt).addClass('thumb_on');
			$('#thumb_theme_'+alt).addClass('thumb_on_img');
			$('#img_theme_'+alt).addClass('img_select_theme');
		}
	});

	$('.link_theme').click(function(){
		//refreshTheme($(this).val());
		var id = $(this).attr('id');
		$('#video_blog_themes input').removeAttr('checked');
		if (id == $('.video_blog_themes_'+id).val()){
			$('.video_blog_themes_'+id).attr('checked', 'checked');
		}
		//displayAjax(getvar('LOADING_MSG'),1);
		var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
		var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
		if (!jQuery.browser.msie && !(ie55 || ie6)) {
			refreshTheme(id);
	        return false;
	    }
		//removeMessage();
	});
	//

	$('input[@type="submit"][@name="reset_conf"]').click(function()
	{
	    deleteConf(true);
	    return false;
	});

	$('input[@type="reset"][@class="cancel"]').click(function()
	{
	    $('#opt_transparent_layer').hide(function(){});
 		$('#div_settings').hide();
	});

	/*$('#public_profil').ajaxForm(options);

	$('#public_profile').submit(function()
	{
		$.ajax({
			type: "POST",
			url: "/api_server/",
			data: "action=save_public_profile"
		});
		return false;
	});*/
});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetContact.js
$(document).ready(function() {
	var avatar = new Image();
	$(avatar).attr('width', '45').attr('height', '45').attr('src', '/img/you.gif');
	
	var new_link = $('.widget_contact .content').prepend('<div id="create_your_account_div" class="contact_account"><a href="'+getvar('register_link')+'" id="create_your_account" class="visitor_url_contact" title="'+getvar('create_own_account_to_contact')+'"></a></div>');
	$(avatar).appendTo('#create_your_account');
	$('#create_your_account').append('<p class="create_your_account_link">'+getvar('create_own_account_to_contact')+'</p><div class="spacer">&nbsp;</div>');

	$('.visitor_url_contact').Tooltip(
	{
		track: false,
		event: "mouseover",
		delay: 1
	});
	
	if(userguid == '') {
		$('div#create_your_account_div').show();
	} else {
		$('div#contact_me').show();
		if(is_owner == 1) {
			$('div#message_unread').show();
		} else {
			$('div#message_unread').empty();
		}
	}
	
	/*$('.contact_connection_link').click(function()
	{
		var url = $(this).attr('class').split(' ');
		document.location.href = unescape(url[1]) + "/member/login.php?username=" + unescape(url[2]);
		return false;
	});*/
	
	
	$('#contact_send_f').click(function ()
	{
	    var to = $('#contact_to_f').val();
	    var subject = $('#contact_subject_f').val();
	    var message = $('#contact_message_f').val();
	    
        $.post("/api_server/?action=contact_send_message", {to: to, subject: subject, message: message, userguid: userguid}, function(json)
		{
			var result = eval('('+json+')');

			if (result['return'] == true)
			{
				$('div#res_send_message').empty();
				$('#contact_subject_f').val('');
	    		$('#contact_message_f').val('');
				$('div#res_send_message').append('<span class="contact_success">' + contact_success + '</span><br /><br />');
			}
			else if (result['return'] == false)
			{
				$('div#res_send_message').empty();
				$('div#res_send_message').append('<span class="contact_error">' + contact_error + '</span><br /><br />');
			}
			else
			{
				$('div#res_send_message').empty();
				$('div#res_send_message').append('<span class="contact_error">' + contact_incorrect + '</span><br /><br />');
			}
		});
		
		return false;
	});
});


// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetContent.js
var content_with_ajax = 0;

var updateTvDisplay = function(video, event)
{
	$('.video_date span').text(video['date']);
	$('.video_author').html(video['author_html_link']);

	// Video title + top permalink
	$('.video_title span').html('<a href="' + video['permalink'] + '" class="video_title">' + video['title'] + '</a>');

	$('.video_description span').text(video['description']);

	// Each categories
	$('.video_categories a').empty();

	for(var i = 0, count = video['categories'].length; i < count; i++)
	{
		$('.video_categories').append('<a href="' + video['categories'][i]['href'] + '">' + video['categories'][i]['name'] + '</a> ');
	}

	// Each keywords
	$('.video_keywords a').empty();

	for(var i = 0, count = video['keywords'].length; i < count; i++)
	{
		$('.video_keywords').append('<a href="' + video['keywords'][i]['href'] + '">' + video['keywords'][i]['name'] + '</a> ');
	}

	// Add bottom permalink
	$('.video_permalink').html('<span>' + content_permalink + ' </span> <a href="' + video['permalink'] + '">' + video['permalink'] + '</a>');

	$('.video_duration span').text(video['duration']);
	$('.video_counter span').text(video['counter']);
	$('.video_rating span').text(video['rating']);

	$('.video_comments a').attr('href', video['comments_href']);
	$('.video_comments span').text(video['nbcomments']);

	// Manager the border-cader
	$('#content_videos_album div[@class=content_video_album_this]').attr('class', 'content_video_album_any');
	$(event).parent().attr('class', 'content_video_album_this');

	$('a.flash_player').remove();
	$('.video_container embed').remove();
	$('#adult_content').remove();

	// If Adult Content
	if (video['adult'] == true)
	{
		$('h1.video_title').after(video['adult_dom']);
	}
	else
	{
		// Remove and add new flash player
		var player_url = $('.video_container embed').attr('src');

		if (player_url)
		{
			var regexp = new RegExp("sig=([0-9a-z\-_]+)","gi");
			var new_player_url = player_url.replace(regexp, 'sig='+video.sig);

			$('h1.video_title').after('<a href="' + new_player_url + '" class="flash_player">Kewego Player</a>');
			applyPlayerColor('autostart');
		}
		else
		{
			$.post("/api_server/?action=content_get_flv_url",
			  	{widget_id: $(event).parents('.widget').attr('id'), sig: video.sig},
			  		function(json)
					{
						var url = eval('(' + json + ')');

						$('#adult_content').remove();


						$('h1.video_title').after('<a href="' + url + '" class="flash_player">Kewego Player</a>');
						applyPlayerColor('autostart');
					});
		}
	}

	window.document.location = '#topplayer';
}


// Display video with Ajax
function populateVideo()
{
	$("#content_videos_album a").unbind();
	$("#content_videos_album a").click(function()
	{
		var regexp = new RegExp("sig=([0-9a-zA-Z\-_]+)","g");
        regexp = regexp.exec($(this).attr("href"));
        var sig = null;
        if (regexp != null)
			sig = regexp[1];

		// Obtain page num
	    /*var regexp = new RegExp("^/([0-9]+)","g");*/
	    var regexp = new RegExp("next=([0-9]+)","g");
	    regexp = regexp.exec($(this).attr("href"));
		var page = 0;
		if (regexp != null)
			page = regexp[1];

		// Obtain date if present
		/*var regexp = new RegExp("/(.*)/([0-9-]+)([/\?]+)","g");*/
		var regexp = new RegExp("date=([0-9-]+)","g");
	    regexp = regexp.exec($(this).attr("href"));
	    var date = null;
		if (regexp != null)
		/*	date = regexp[2];*/
			date = regexp[1];

		if (sig == null || page == null)
		{
			return true;
		}

		var this_click = $(this);

		$.post("/api_server/?action=content_get_video",
				{widget_id: $(this).parents('.widget').attr('id'), sig: sig, page_id: page, date: date},
				function(json)
				{
				    var video = eval('('+json+')');
					updateTvDisplay(video, this_click);

					populateVideo();
				});

		return false;
	});
}

function populateVideosTV() {
	$("#content_tv_pagination a").unbind();
	$("#content_tv_pagination a").click(function()
	{
		// Obtain page num
	    /*var regexp = new RegExp("^/([0-9]+)","g");*/
	    var regexp = new RegExp("next=([0-9]+)","g");
	    regexp = regexp.exec($(this).attr("href"));
		var page = 0;
		if (regexp != null)
			page = regexp[1];

        // Obtain date if present
		/*var regexp = new RegExp("/(.*)/([0-9-]+)([/\?]+)","g");*/
		var regexp = new RegExp("date=([0-9-]+)","g");
	    regexp = regexp.exec($(this).attr("href"));
	    var date = null;
		if (regexp != null)
		/*	date = regexp[2];*/
			date = regexp[1];

 		$.post("/api_server/?action=content_get_tv", {widget_id: $(this).parents('.widget').attr('id'), page_id: page, date_: date}, function(json)
		{
			var videos = eval('('+json+')');

   			regexp = new RegExp("sig=([0-9a-zA-Z\-_]+)","g");
        	regexp = regexp.exec($(".video_container embed").attr("src"));
        	var this_sig = null;
        	if (regexp != null)
				this_sig = regexp[1];

			var i;
			for (i = 0, j = 1; i < videos['videos'].length; i++)
			{
    			$("#content_videos_album_void").text(videos['videos'][i]['title']).html();
			    var title_fix = $("#content_videos_album_void").text();
			    $("#content_videos_album_void").empty();

				$("#content_video_" + i + "_album").remove();

				var newContent = $(
					"<div id=\"content_video_" + i + "_album\"" + ((this_sig == videos['videos'][i]['sig']) ? ' class=\"content_video_album_this\"' : ' class=\"content_video_album_any\"') + ">" +
						"<a href=\"/?next=" + page + (date ? "&date=" + date : "") + "&s=1&sig=" + videos['videos'][i]['sig'] + "\" title=\"" + title_fix + "\">" +
						/*
						"<a href=\"/" + page + (date ? "/" + date : "") + "/?s=1&sig=" + videos['videos'][i]['sig'] + "\" title=\"" + title_fix + "\">" +
						*/
							"<img src=\"" + videos['videos'][i]['thumb'] + "\" width=\"154\" height=\"114\" alt=\"" + title_fix + "\" />" +
							"<br />" +
							title_fix.substr(0, 20) +
						"</a>" +
					"</div>"
				);

				$("#content_videos_album").append(newContent);

				$("#content_video_" + i + "_album").fadeIn("normal");

			}
			$("#content_videos_album").append("<div class=\"killer\"></div>");

			for (;i<videos['data']['max_per_page'];i++)
				$("#content_video_" + i + "_album").remove();

			$("#content_tv_pagination").empty();

			$("#content_tv_pagination").append(
				videos['pagination'][0] +
				'<img src="/img/blank.gif" width="15" height="0" alt="" />' +
				videos['pagination'][1] +
				'<img src="/img/blank.gif" width="15" height="0" alt="" />' +
				videos['pagination'][2] +
				"<div class=\"killer\"></div>"
			);

			populateVideo();

            populateVideosTV();

		});
		return false;
	});

}

$(document).ready(function() {

	if ($('#content_source').val() == getvar('DISPLAY_CHANNEL'))
	{
		$('#content_channel_sig').css('visibility', 'visible');
	}

	$('#content_source').change(function(){
		if ($('#content_source').val() == getvar('DISPLAY_CHANNEL'))
		{
			$('#content_channel_sig').css('visibility', 'visible');
		}
		else
		{
			$('#content_channel_sig').css('visibility', 'hidden');
		}
	});

	if (content_with_ajax == 1)
	{
    	populateVideo();

		populateVideosTV();
	}
});


var total_results_count = 0;


function displayVideos(videos)
{
	videos = eval('('+videos+')');
	last_id = 'widget_content_main';
	$('.content_one_video').remove();

	total_results_count = videos['total_count'];


	if (videos['total_count'] > 0)
	{
		for (rows in videos['results'])
		{
			if (typeof(videos['results'][rows]['id']) != 'undefined')
			{
				var id = videos['results'][rows]['id'];

   	var clone = $('#widget_content_main').clone().insertAfter('#'+last_id);
				clone.attr('id', id);
				clone.hide();
				$('#'+id).attr('class', 'content_one_video');
				var flash_html_code = '<object type="application/x-shockwave-flash" data="'+videos['results'][rows]['flv_url']+'" width="400" height="368"><param name="movie" value="'+videos['results'][rows]['flv_url']+'"></object>';
				$('#'+id+' .flash_player span').html(flash_html_code);
				$('#'+id+' .video_title span').text(videos['results'][rows]['title']);
				$('#'+id+' .video_author span').text(videos['results'][rows]['username']);
				$('#'+id+' .video_date span').text(videos['results'][rows]['date']);
				$('#'+id+' .video_duration span').text(' '+videos['results'][rows]['duration']);
				$('#'+id+' .video_rating span').text(' '+videos['results'][rows]['rating']);
				$('#'+id+' .video_counter span').text(videos['results'][rows]['counter']);
				$('#'+id+' .video_comments span').text(videos['results'][rows]['nbcomments']);
				$('#'+id+' .video_comments a').attr('href', partner_url+'/video/'+videos['results'][rows]['sig']+'.html#comments');
				$('#'+id+' .video_description span').html(videos['results'][rows]['description']);

				$('#'+id).show();
				last_id = id;
			}
		}
	}

	$('#content_previous_link').unbind('click');
	$('#content_next_link').unbind('click');
	managePagination();
	return;
}


function managePagination()
{
	if (getvar('content_next') > 1)
	{
		$('#content_previous_link').css('display', 'inline');
		$('#content_previous_link').attr('href', '/'+(getvar('content_next')-1)+'/'+getvar('content_date'));
		$('#content_previous_link').click(function(){
			getVideos((getvar('content_next')-1), getvar('content_date'));
			return false;
		});
	}
	else
	{
		$('#content_previous_link').css('display', 'none');
	}

	if ( (getvar('content_next') * getvar('content_max_per_page')) < total_results_count)
	{
		$('#content_next_link').css('display', 'inline');
		$('#content_next_link').attr('href', '/'+(getvar('content_next')+1)+'/'+getvar('content_date'));
		$('#content_next_link').click(function(){
			getVideos((getvar('content_next')+1), getvar('content_date'));
			return false;
		});
	}
	else
	{
		$('#content_next_link').css('display', 'none');
	}
}

function getVideos(next, date)
{
	$.ajax({
	type: "GET",
	url: "/api_server/",
	data: 'action=get_content_videos&next='+next+'&date='+date+'&content_source='+getvar('content_source')+'&channel_sig='+getvar('content_channel_sig'),
	success: function(msg) {
		content_next = next;
		window.scrollTo(0,0);
		displayVideos(msg)
	}
	});
}


function afterSave()
{
	/*$('#'+window.object.id+' .title span').text(window.object.widget_title);
	$('.content_one_video').remove();
	window.scrollTo(0,0);
	content_datas = window.object.datas;
	content_source = window.object.content_source;
	channel_sig = window.object.channel_sig;
	content_next = 1;
	content_date = '';
	displayVideos(content_datas);
	generateArchiveLinks();*/

}





// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetDebug.js
var modifier = false;

$(document).ready(function(){

	$(document).add("body").keydown( function(e) {
	    modifier = false;
		// 16 = Maj
		// 17 = Ctrl
		// 18 = Alt
		if(e.keyCode >= 16 && e.keyCode <= 18)
		{
		    modifier = true;
		}
	});
	
	$(document).add("body").keyup( function(e) {
	    modifier = false;
	});

	$('.headertoolbar').dblclick(function(){
	    if(modifier !== false)
	    {
	    	$(this).toggleClass('bottom');
	    	return false;
		}
	});

	$('.headertoolbar input').dblclick(function(){
	    return false;
	});
	
	$('.headertoolbar a').dblclick(function(){
	    return false;
	});

	$('#devDebug .content').hide();
	
	$('#devDebug .title').dblclick(function(){
	    $(this).parent().children('.content').slideToggle();
	});
	$('#devDebug .footer').dblclick(function(){
	    $(this).parent().children('.content').slideToggle();
	});
	
});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetHeaderToolbar.js
$(document).ready(function () {

	/*$('a.connect_link').click(function(){
	    if(!$('#widget_mini_login').is(':visible'))
	    {
	        $('#widget_mini_login').slideDown("fast");
	    }
	    else
	    {
	        $('#widget_mini_login').slideUp("fast");
	    }
	    return false;
	});

    $('a.logout_link').click(function(){
            $.ajax({
    			type: "GET",
    			url: "/api_server/",
    			data: "action=logout",
    			success: function(msg) {
    				if(msg == 1)
    				{
    					$('body').append('<img src="http://www.kewego.com'+getvar('url_suffix')+'/tools/videoblog/set_username.php?clear" width="0" height="0" id="transparent_pixel" />');
                        window.location = './';
    				}
    			}
    		});
            return false;
    });*/
    
    $('#user_home_button').hover(function(){
			$('#user_home').addClass('home_button_over');
	 }, function(){
			$('#user_home').removeClass('home_button_over');
	});
	
    $('#user_home_button').click(function(){
    		$('#user_home').addClass('home_button_on');
			$('#user_home_button').css('color', '#FFF');
			window.location=partner_url+'/videos/';
	});
	
    $('#user_film_button').hover(function(){
    		$('#user_film').addClass('user_film_button_over');
	}, function(){
			$('#user_film').removeClass('user_film_button_over');
	});
	
    $('#user_film_button').click(function(){
    		$('#user_film').addClass('user_film_button_on');
			$('#user_film_button').css('color', '#FFF');
			window.location=partner_url+'/upload/';
	});
	
    $('#user_options_button').hover(function(){
			$('#user_options').addClass('user_options_button_over');
	}, function(){
			$('#user_options').removeClass('user_options_button_over');
	});
	
    $('#user_options_button').click(function(){
			$('#user_options').addClass('user_options_button_on');
			$('#user_options_button').css('color', '#FFF');
	});
	
    $('#user_logout_button').hover(function(){
			$('#user_logout').addClass('user_logout_button_over');
	}, function(){
			$('#user_logout').removeClass('user_logout_button_over');
	});
	
    $('#user_logout_button').click(function(){
			$('#user_logout').addClass('user_logout_button_on');
			$('#user_logout_button').css('color', '#FFF');
			window.location=partner_url+'/member/logout.php?username='+username;
	});
	
    $('#user_connect_button').hover(function(){
			$('#user_connect').addClass('user_logout_button_over');
	}, function(){
			$('#user_connect').removeClass('user_logout_button_over');
	});
	
    $('#user_connect_button').click(function(){
			$('#user_connect').addClass('user_logout_button_on');
			$('#user_connect_button').css('color', '#FFF');
			window.location=partner_url+'/member/login.php?username='+username;
	});

});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetImageDisplay.js
$(document).ready(function(){
	$('#image_display_selector').change(function(){
	    var widget = $(this).parent().parent().parent();
	    widget.children('.content').children('img').attr('src', $(this).val());
	    toggleSettings(widget);
	});
	/*
	$('#image_display_selector').change(function(){
	    //var widget = $(this).parent().parent().parent();
	    //widget.children('.content').children('img').attr('src', $(this).val());
	    toggleSettings(widget);
	});
	*/
});


// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetMessage.js
$(document).ready(function () {
	$('#form_message').submit(function () {
		if ($('#message_to').val() == "")
		{
			displayError("Receiver can't be empty !");
			return false;
		}
		if ($('#message_subject').val() == "")
		{
			displayError("Subject can't be empty");
			return false;
		}
		if ($('#message_body').val() == "")
		{
			displayError("Body can't be empty");
			return false;
		}

        $.ajax({
			type: "GET",
			url: "/api_server/",
			data: "action=send_message",
			success: function(msg) {
                if(msg == -1)
				{
					displayError('Failed');
					return false;
				}
				else if(msg == 1)
				{
					displayInfo('Message sent !');
					return false;
				}
				else
				{
				    displayError('You must be connected to send a message !');
				    return false;
                }
			}
		});        		
		return false;
	});	
});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetMiniLogin.js
$(document).ready(function () {

    $('form.miniLoginForm').submit(function(){
        username = $('.login_email').val();
        login_pass = $('.login_password').val();
        action = $('#miniLoginForm').attr('action');
		if (username != '' && login_pass != '' && action == ".")
		{
            $.ajax({
    			type: "GET",
    			url: "/api_server/",
    			data: "action=connection&email="+username+"&pwd="+login_pass,
    			success: function(msg) {
                    if(msg == -1)
    				{
    					displayError('Failed');
    				}
    				else if(msg == 1)
    				{
    					displayInfo('Success login !!!');
    					window.location = './';
    				}
    				else
    				{
    				    displayError('Username / Password incorrect');
                    }
    			}
    		});
        }
        else if (username != '' && login_pass != '')
        {
            return true;
        }
        else
        {
            displayError("Email and Password can't be empty !");
        };
        return false;
    });

});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetSpectators.js
$(document).ready(function() {

	if (getvar('userguid') && getvar('userguid') != 'false')
	{
		$.ajax({
			type: "GET",
			url: "/api_server/",
			data: "action=log_vblog_visitor&userguid="+window.userguid,
			dataType: "json",
			success: function(msg) {
				if(msg['username'])
				{
					if (getvar('is_logged') == 0)
					{
						$('#new_videoblog').html(getvar('welcome')+' <strong>'+msg['username']+'</strong>');
						//$('#login_email').val(msg['email']);
					}
					$('#new_videoblog').show();

					$('#visitor_'+msg['id']).remove();
					var avatar = new Image(45, 45);
					$(avatar).attr('width', '45').attr('height', '45').attr('src', msg['avatar']);

					var new_link = $('.spectators .content').prepend('<a href="'+msg['url']+'" id="visitor_'+msg['id']+'" class="visitor_url" title="'+msg['username']+', '+msg['age']+getvar('years_old')+'"></a>');
					$(avatar).appendTo('#visitor_'+msg['id']);


					$('.visitor_url').Tooltip(
					{
						track: false,
						event: "mouseover",
						delay: 1
					});
				}
			}
		});
	}
	else
	{
		//displayInfo('Welcome Anonymous. You should login or create an account...');
		var avatar = new Image();
		$(avatar).attr('width', '45').attr('height', '45').attr('src', '/img/you.gif');

		var new_link = $('.spectators .content').prepend('<div id="create_your_account_div"><a href="'+getvar('register_link')+'" id="create_your_account" class="visitor_url" title="'+getvar('create_own_account')+'"></a></div>');
		$(avatar).appendTo('#create_your_account');
		$('#create_your_account').append('<p class="create_account_link">'+getvar('create_own_account')+'</p><div class="spacer">&nbsp;</div>');

		$('.visitor_url').Tooltip(
		{
			track: false,
			event: "mouseover",
			delay: 1
		});
	};


	$('#spectator_avatars_count').change(function() {
		$('#settings_widget_spectators').submit();
	});


});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\WidgetWidgetDeveloper.js
lhighlighted = whighlighted = false;

fixIeDebug = function(){
	if($('#devDebug').size())
	{
	    var newY = Math.round($(document).height()+$('#devDebug').height());
	    $('#devDebug').css('margin-top', newY);
	}
}

$(document).ready(function () {

	if(jQuery.browser.msie)
	{
        setTimeout("fixIeDebug()",3000);
	}

	$('a.Whighlighter').click(function(){
		$('.widget').toggleClass('Whighlight');
		if(!whighlighted)
		{
			whighlighted = true;
			$('.widget').hover(function(){
				var parentClass = $(this).parent().attr('class').replace(/ /g, '.');
				parentClass = parentClass.replace(/layout/g, '');
				var thisClass = $(this).attr('class').replace(/ Whighlight/g, '');
				thisClass = thisClass.replace(/ /g, '.');
				var infos = parentClass + ' &gt; .' + thisClass;
				$('body').append('<span class="label" style="color: #006FFF;">'+infos+'</div>');
			}, function(){
				$('.label').remove();
			});
		}
		else
		{
			whighlighted = false;
			$('.widget').unbind();
			$('.label').remove();
		}
		return false;
	});
	
	$('a.Lhighlighter').click(function(){
		$('.layout').toggleClass('Lhighlight');
		if(!lhighlighted)
		{
			lhighlighted = true;
			$('.layout').hover(function(){
				var parentClass = $(this).parent().attr('class').replace(/ /g, '.');
				var thisClass = $(this).attr('class').replace(/layout| Lhighlight/g, '');
				thisClass = thisClass.replace(/ /g, '.');
				var infos = '.' + parentClass + ' &gt; ' + thisClass;
				$('body').append('<span class="label" style="color: #FFAE00;">'+infos+'</div>');
			}, function(){
				$('.label').remove();
			});
		}
		else
		{
			lhighlighted = false;
			$('.layout').unbind();
			$('.label').remove();
		}
		return false;
	});
	
	$('#showMsg').click(function(){
	    displayMessage($('#inputMsg').val(), $('#typeMsg').val());
	});
	
	$('#register_widgets').click(function(){
		$.ajax({
			type: "POST",
			url: "/api_server/",
			data: "action=register_widgets",
			success: function(msg){
			    displayInfo(msg);
			}
		});
		return false;
	});
	
	$('#register_themes').click(function(){
		$.ajax({
			type: "POST",
			url: "/api_server/",
			data: "action=register_themes",
			success: function(msg){
			    displayInfo(msg);
			}
		});
		return false;
	});

	$('#delete_conf').click(function(){
	    deleteConf(false);
	    return false;
	});
	
	$('#packer').click(function(){
		$.ajax({
			type: "POST",
			data: "action=pack_files",
			url: "/api_server/",
			dataType: 'json',
			success: function(msg){
			    displayInfo(msg);
			}
		});
		return false;
	});
	
});

// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\querystring.js
/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}


// JAVASCRIPT CONTENT FROM C:\usr\local\pulse3\kewego\videoblog\www\js\widgets.js

var dropscroll, documentscroll, preDrag;

var ie7 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 7.0") != -1);

$(document).ready(function() {

    deferScripts();

    $('.headertoolbar').append('<div id="systemMessage" style="display: none;"></div>');
    $('<div class="footer"/>').appendTo('#systemMessage');

    /* Internet Explorer Hacks */
    if (jQuery.browser.msie) {
        if (!ie7) {
            // Fix Configuration form in header
            $.ifixpng('/img/blank.gif');
            $('img[@src$=.png], .widget, .headertoolbar .footer, #systemMessage').ifixpng();
            $('img[@src$=.png], #header_settings, #top_text, #top_disable').ifixpng();
			
			$('.configurator').css({
                position: 'absolute',
                zIndex: '99999',
                marginTop: '2em',
                left: '1em'
            });

            // Force rounded corners position by forcing content width
            $('.widget .content').css('width', '100%');

            $('.header .content').css({
                height: ($('.header .content').height() + $('.headertoolbar .content').height())
            });
			$('.abuse_img').ifixpng();
        }
        // Emulate min-height for droppable zones
        $('div[@class*=col]').css('height', '600px');


    }
    /* End IE hacks */

$('a.edit').fadeOut('slow');

    $('.allowDrag').Sortable(
    {
        accept: 'widget',
        helperclass: 'dropHelper',
        activeclass: 'sortableactive',
        hoverclass: 'sortablehover',
        handle: '.draggable',
        fixed: '.fixed',
        opacity: '0.8',
        containment: 'none',
        tolerance: 'pointer',
        onStart: function()
        {
            //$.iAutoscroller.start(this, document.getElementsByTagName('body'));
            
			preDrag = new Array();
	            $(this).parent().children('.widget').each(function()
	            {
	                preDrag.push($(this).attr('id'));
	
	            });
	            
        },
        onStop: function()
        {
            //$.iAutoscroller.stop();

			var container = $(this).parent().attr('id');
       		var newLayoutParts = new Array();

            $(this).parent().children('.widget').each(function()
            {
                newLayoutParts.push($(this).attr('id'));
            });

            if (newLayoutParts.join('') != preDrag.join(''))
            {
				$.ajax({
                    type: "POST",
                    data: 'action=pos&container=' + container + '&newOrder=' + newLayoutParts,
                    url: '/api_server/',
                    dataType: 'json',
                    error: function(response) {
                        displayError(getvar('ERROR_SAVING_MSG'));
                    },
                    success: function(response) {
                        if (response.code < 1)
                        {
                            displayError(response.message);
                        }
                        else if (response.message)
                        {
                            displayInfo(response.message);
                        }
                    }
                });
            }
            
        }

    }
    );

    $('a.edit').click(function() {

		toggleSettings($(this).parent().parent());
        	return false;

    });

    $('.widget').mouseover(function() {
        $(this).find('a.edit').show();

    });

    $('.widget').mouseout(function() {
        $(this).find('a.edit').hide();

    });

    $('.widget .settings .cancel').click(function() {
        toggleSettings($(this).parent().parent().parent());
        return false;

    });

    applyCorners();
    applyPlayerColor();

});

var options = {
    target: '#myTarget',
    type: 'post',
    beforeSubmit: preSubmit,
    success: postSubmit,
    error: errorSubmit,
    url: '/api_server/',
    dataType: 'json',
    clearForm: false,
    resetForm: false,
    timeout: 5000

};

/* FORM HANDLING */
$(document).ready(function() {

    $('.widget .settings .settingsForm').submit(function() {
        $(this).parent().hide();

    });

    // bind form using 'ajaxForm'
    $('.widget .settings .settingsForm').ajaxForm(options);

    // bind ajax loading
    //$('.widget .settings .settingsForm').ajaxStart(function(){
    $('body').ajaxStart(function() {

       	displayAjax(getvar('LOADING_MSG'));
        $(document.body).css({
            cursor: "wait"
        });

    });

    $('body').ajaxStop(function() {
        removeMessage();
        $(document.body).css({
            cursor: "auto"
        });

    });


});

// pre-submit callback
function preSubmit(formData, jqForm, options) {

    for (i in formData)
    {
        if (formData[i].name == 'widget')
        {
            window.widget_id = formData[i].value;

        }

    }
    var obj = new Object();
    obj.name = 'action';
    obj.value = 'save';
    formData.push(obj);

    return true;

}

// post-submit callback
function postSubmit(response, status) {

    if (response.refresh)
    {
        displayInfo(response.message, 2000);
        setTimeout("window.location.href='/'", 1000);
        //setTimeout("window.location.reload()",1000);
        return;

    }

    if (response.code < 1)
    {
        displayError(response.message);

    }
    else
    {
        displayInfo(response.message);

    }

    if (response.object)
    {
        window.object = response.object;
        window.object.id = window.widget_id;
        if (response.object.fallback)
        {
            eval(response.object.fallback + '();');

        }

    }
    else
    {
        window.object = false;

    }


}

// post-submit error callback
function errorSubmit() {
    displayError(getvar('ERROR_SAVING_MSG'));
    window.object = false;

}

function toggleSettings(e)
 {
    //var content = e.children('.content');		//commenté le 17/12
    var settings = e.children('.settings');
    //settings.slideToggle();	//commenté le 17/12
    
    if ( settings.css("display") == "none" ) {
		settings.show();	//évite de redémarrer la video lorsqu'on édite le widget
		//ajout d'un effet?
	} else {
    	settings.slideUp();
    }
}

deleteConf = function(owner) {
    var question = (owner) ? CONFIGURATION_RESET_QUESTION: CONFIGURATION_DELETE_QUESTION;
    if (confirm(question))
    {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/api_server/",
            data: "action=delete_conf",
            success: function(msg) {
                postSubmit(msg);

            }

        });

    }

}

var applyCorners = function()
 {

    var doCanvas = true;

    var pos = ['left', 'right'];
    var items = ['title', 'footer'];
    var part = {
        top: pos,
        left: pos
    };

    $('.cornercanvas').remove();

    var testWidget = $('<div class="widget"><h3 class="title">title</h3><div class="settings">settings</div><div class="content"><p>content</p></div><h3 class="footer" style="overflow:hidden; position:relative;"></h3>').css({
        display: 'none'
    });
    $('body').append(testWidget);
    test_title = testWidget.children('h3.title');
    test_footer = testWidget.children('h3.footer');

    for (var i in items) {
        if (typeof(items[i]) != 'function') {
            var part = items[i];
            for (var p in pos) {
                if (typeof(pos[p]) != 'function') {
                    $('.' + part + '_' + pos[p]).remove();
                    var corner = $('<div class="' + part + '_' + pos[p] + '"></div>').css({
                        float: pos[p]
                    });
                    eval('var target = test_' + part);
                    target.before(corner);

                    if (corner.css('background-image') != 'none') {
                        doCanvas = false;
                        if (part == 'footer') {
                            $('.widget .footer').css({
                                position: 'relative',
                                overflow: 'hidden'
                            });

                        }

                        $('.widget .' + part).before(corner);
                        $('.widget .' + part + '_' + pos[p]).ifixpng();

                    }

                }

            }

        }

    }

    if (doCanvas)
    {
        var corner = $('<div class="corners">x</div>').css('visibility', 'hidden');
        $('body').append(corner);
        var radius = corner.css('width');

        if (radius != '0px')
        {
            $('.widget .title').corner(radius + ' top');
            if ($('.widget .footer').css('height') != '0px')
            {
                $('.widget .footer').corner(radius + ' bottom');

            }

        }
        corner.remove();

    }
    else
    {
        testWidget.remove();

    }

}

var toHex = function(rgb)
 {
    if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(rgb))
    {
        rgb = [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
        var r = rgb[0];
        var g = rgb[1];
        var b = rgb[2];

        return (r < 16 ? '0': '') + r.toString(16) + 
        (g < 16 ? '0': '') + g.toString(16) + 
        (b < 16 ? '0': '') + b.toString(16);


    }
    else if (rgb.indexOf('#') > -1)
    {
        return rgb.substr(1, rgb.length);

    }
    else
    {
        return rgb;

    }

}

var applyPlayerColor = function(autostart_)
 {

    var flash = $('<span class="player">x</span>').css('visibility', 'hidden');
    $('body').append(flash);
    var hexaColor = toHex(flash.css('color'));

    $('.flash_player').each(function() {
        var href = this.href;

        // Auto-start the video
        var qs = new Querystring();

        if ($(this).attr('class').indexOf('player_autostart') != -1)
        {
            autostart = 'true';

        }
        else if (typeof(autostart_) != 'undefined' && autostart_ != 'false')
        {
            autostart = 'true';

        }
        else if (qs.get('s'))
        {
            autostart = 'true';

        }
        else
        {
            autostart = 'false';

        }

        var advertised = null;
		if ($(this).attr('class').indexOf('advertised') != -1)
		{
		    advertised = '1';
		}
		
		if(getvar('is_owner') == 1)
		{
			autostart = 'false';
		}

        $(this).flash(
        {
            src: href,
            height: (getvar('player_vb_key') ? 300 : 368),
            width: 400,
            wmode: 'Window',
            allowFullScreen: 'true',
            allowscriptaccess: 'always',
            flashvars: {
                stat: 'videoblog',
                autostart: autostart,
                playerKey: getvar('player_vb_key'),
                skinKey: getvar('skinKey'),
                env_type: getvar('env_type'),
                language_code: getvar('language_code'),
                advertise: advertised
            }
        },
        {
            version: '7',
            expressInstall: true
        },
        function(htmlOptions) {
            var $this = $(this);
            if (hexaColor != '000000') {
                htmlOptions.flashvars.forceColor = hexaColor;

            }
            $this.before($.fn.flash.transform(htmlOptions));
            $this.remove();

        }
        );

    });
    flash.remove();
    

}

var displayInfo = function(msg, time, speed)
 {
    displayMessage(msg, 'info', time, speed);

}

var displayError = function(msg, time, speed)
 {
    displayMessage(msg, 'error', time, speed);

}

var displaySystem = function(msg, time, speed)
 {
    displayMessage(msg, 'system', time, speed);

}

var displayAjax = function(msg, time, speed)
 {
    if (!window.ajaxStarted)
    {
        displayMessage(msg, 'ajax', time, speed);

    }

}

var displayMessage = function(msg, type, time, speed)
 {
    if (!msg)
    {
        return;

    }
    if (!time)
    {
        time = 5000;

    }

    if (!speed)
    {
        speed = 'fast';

    }

    var newMsg = $('<div class="content ' + type + '" style="display: none;">' + msg + '</div>').insertBefore('#systemMessage .footer');

    newMsg.click(function() {
        newMsg.slideUp(speed, 
        function() {
            removeMessage(newMsg, speed);

        });

    });

    newMsg.slideDown(speed, 
    function() {
        if (type != 'ajax')
        {
            setTimeout(function() {
                removeMessage(newMsg);
            },
            time);

        }

    });

    if ($('#systemMessage').is(':hidden')) {
        $('#systemMessage').slideDown(speed);

    }

    if (jQuery.browser.msie) {
        if (!ie7) {
            if (!$('#systemMessage .footer img').size()) {
                $('#systemMessage .footer').css('background', 'none').append('<img src="/img/HeaderToolbarFooter.png" width="100%" height="7" />');

            }
            $('#systemMessage').ifixpng();
        }

    }


}

var removeMessage = function(element, speed)
 {
    if (!element)
    {
        element = $('#systemMessage div.ajax');

    }

    if (element.size())
    {
        element.slideUp(speed, 
        function() {
            element.remove();
            var messages = $('#systemMessage div.content').get();
            if (messages.length < 1)
            {
                $('#systemMessage').slideUp(speed);

            }

        });

    }

}

var getvar = function(key)
 {
    try {
       	return eval(key)

    }
    catch(e) {
        return false;

    }

}

var deferScripts = function()
 {
    $('.defer').each(function() {
        var script_url = $(this).text();
        if (script_url.indexOf('"') > 0)
        {
            var script_url = eval('"' + script_url + '";');

        }
        else
        {
            var script_url = eval("'" + script_url + "';");

        }
        $(this).after('\n<script src="' + script_url + '" type="text/javascript"></script>');

    });

}
