/**
*
* @package Aqua3
* @version $Id: waterscouting-scripts.functions.js 2056 2010-02-11 16:33:38Z erik $
* @copyright (c) 2009 waterscouting.com
*
*/

//-- Setup
function scrollWindow()
{
	if (anchor_pos != -1)
	{
		scrollTo(location, 200);
	}
}

function initLinks()
{
	// Prompt voor confirmation
	$('#mark-forums-read, #mark-topics-read').click(function() {
		ret = confirm_mark(this);
		return ret;
	});
}

//-- Functions

/**
* Maak de "profile" border net zo lang als de post
*/
function fixProfileBorder()
{
	col_even = '#f5f5f5';
	col_odd	 = '#aac3da';

	$('.post', '#content').each(function(i){
		// Fix de hoogte
		$post_height = $('.postbody', this).height();
		if ($post_height > $('.postprofile', this).height())
		{
			$('.postprofile', this).height($post_height);
		}

		// Fix kleuren
		border_colour = (i % 2 == 0) ? col_even : col_odd;
		$('.postprofile,.signature,.notice', this).css('border-color', border_colour);
	});
}

/**
* Show/Hide QR
*/
function flipQR()
{
	newFormStatus	= ($('#qr_editor_div').css('display') == 'block') ? 'none' : 'block';
	newButtonStatus	= ($('#qr_showeditor_div').css('display') == 'block') ? 'none' : 'block';

	// Altijd 1!
	if (newFormStatus == newButtonStatus)
	{
		newFormStatus	= 'none';
		newButtonStatus	= 'block';
	}

	// Set new status
	$('#qr_editor_div').css('display', newFormStatus);
	$('#qr_showeditor_div').css('display', newButtonStatus);
}

function scrollTo(_location, _duration)
{
	// Only internally
	if (_location.href.slice(0, $_base_url.length + 1) == ($_base_url + '#'))
	{
		_anchor = _location.href.slice(anchor_pos + 1);
		$('html,body').scrollTo($('#' + _anchor), {duration:_duration});
		return false;
	}

	return true;
}

/**
* The clock
*/
function liveClock()
{
	var $clock = 0;

	// Smart date
	$user_date_format = $PHP.str_replace("|", '', $user_date_format);

	$clock = $PHP.date($user_date_format);
	$('#currentime').text($PHP.sprintf($lang_entries[1], $clock));

	setTimeout(function()
	{
		liveClock()
	}, 1000);
}

/**
* FF checken of de user echt dit wilt doen :P
*/
function confirm_mark(ele)
{
	$href = $(ele).attr('href');
	$type = ($PHP.strpos($href, 'mark=forums')) ? 'forums' : 'topics';
	$confirm_txt = ($type == 'forums') ? $lang_entries[2] : $lang_entries[3];
	$confirm = confirm($confirm_txt);
	if ($confirm == true)
	{
		$href = $type = $confirm_txt = $confirm = '';
		return true;
	}
	return false;
}

/**
* Prompt de ws.com url box helper
*/
function wscom_url_bbcode_box()
{
	var $insert = "";

	// Pak de URL
	var $url = prompt($lang_entries[4], 'http://');
	if ($url == null)
	{
		return;
	}
	else if (!$url)
	{
		alert($lang_entries[6]);
		return;
	}

	// Pak de titel
	var $title = prompt($lang_entries[5], '');
	if ($title == null)
	{
		return;
	}
	else if (!$title)
	{
		// Alleen de URL
		$insert = "[url]" + $url + "[/url]";
	}
	else
	{
		// Met link titel
		$insert = "[url=" + $url + "]" + $title + "[/url]";
	}

	// Voeg toe aan de text area
	insert_text($insert, false, false);
}

/**
* Genereer de toeter tags
*/
function create_toeter()
{
	// Toeter holder tag
	$toeter_object_holder = $('<div>').attr({
		'id'	: 'toeter-holder'
	}).addClass('skiplink');

	// Build the object tag
	var $toeter_object_tag = $('<object>').attr({
		'type'		: 'src',
		'data'		: $toeter_path,
		'width'		: '0',
		'height'	: '0'
	}).appendTo($toeter_object_holder);

	// Generate all the param tags
	var $toeter_src_param = $('<param />').attr({
		'name'	: 'src',
		'value'	: $toeter_path
	}).appendTo($toeter_object_tag);

	var $toeter_autoplay_param = $('<param />').attr({
		'name'	: 'autoplay',
		'value'	: 'true'
	}).appendTo($toeter_object_tag);

	var $toeter_autostart_param = $('<param />').attr({
		'name'	: 'autostart',
		'value'	: '1'
	}).appendTo($toeter_object_tag);
}