var ad_timeout;
var button_active = '';

function InitSystemEngine(page_id, cat_id, show_ad) {
	show_ad = Number(show_ad);
	switch(page_id) {
		case 'media':
			RefreshVideoCont('new');
			ShowAdContent(show_ad);
			ShowCategory(cat_id, 1);
			break;
		case 'live':
			RefreshVideoCont('new');
			ShowAdContent(show_ad);
			ShowCategory(cat_id, 1);
			break;
	}
}

function ShowAdContent(show_content) {
	if(show_content == 1) {
		$('LayBoxRight').style.display = 'block';
		$('LayContentAdRight').style.display = 'block';
	} else {
		$('LayBoxRight').style.display = 'block';
		$('LayContentAdRight').style.display = 'none';
	}
}

function ShowCategory(div_id, page_num) {

	new Ajax.Request('ajax.cmd.php', {
		parameters: 'ajax_action=list_category&cat_id=' + div_id + '&page_num=' + page_num + '&random=' + Math.random(),
		method: 'get',
		evalJS: true,

		onComplete: function(transport) {
			var splitResponse = '';

			splitResponse = transport.responseText.split('<#split#>');

			if($('CategoryBox').innerHTML != splitResponse[0]) {
				$('CategoryBox').innerHTML = splitResponse[0];
			}

			if($('CategoryListing').innerHTML != splitResponse[1]) {
				$('CategoryListing').innerHTML = splitResponse[1];
			}
		}
	});

	for(var ii = 100; ii <= 120; ii++) {
		if($('subnaviPoint' + ii + 'Row') != null) {
			$('subnaviPoint' + ii + 'Row').className = 'subnaviPoint';
			$('subnaviPoint' + ii + 'RowLeft').className = 'subnaviRowLeft';
			$('subnaviPoint' + ii + 'RowRight').className = 'subnaviRowRight';
		}
	}
	
	$('subnaviPoint' + div_id + 'Row').className = 'subnaviPointActive';
	$('subnaviPoint' + div_id + 'RowLeft').className = 'subnaviRowLeftActive';
	$('subnaviPoint' + div_id + 'RowRight').className = 'subnaviRowRightActive';
}

function LoadCategoryList() {
	for (ii = 0; ii < 4; ii++) {
		var content_id = 'tblContent' + parseInt(100 + ii);
		var title_id = 'tblContentTitle' + parseInt(100 + ii);
		var space_id = 'tblContentTitleSpacer' + parseInt(100 + ii);

		if($(content_id).innerHTML != '') {
			$(title_id).style.display = 'block';

			if($(space_id) != null) {
				$(space_id).style.display = 'block';
			}
		}
	}
}

function AppearDiv(div_name) {
	if($(div_name).style.display == 'none') {
		Effect.Appear(div_name, { duration: 0.5, from: 0, to: 1 });
	}
}

function RefreshVideoCont(action) {
	new Ajax.Request('ajax.cmd.php', {
		parameters: 'ajax_action=list_' + action + '&random=' + Math.random(),
		method: 'get',
		evalJS: true,

		onComplete: function(transport) {
			if($('Previewbox').innerHTML != transport.responseText) {
				$('Previewbox').innerHTML = transport.responseText;
			}
		}
	});

	switch(action) {
		case 'new':
			$('subnaviNewRow').className = 'subnaviNewActive';
			$('subnaviMostRow').className = 'subnaviMost';
			$('subnaviLiveRow').className = 'subnaviLive';

			$('subnaviNewRowLeft').className = 'subnaviRowLeftActive';
			$('subnaviNewRowRight').className = 'subnaviRowRightActive';

			$('subnaviMostRowLeft').className = 'subnaviRowLeft';
			$('subnaviMostRowRight').className = 'subnaviRowRight';

			$('subnaviLiveRowLeft').className = 'subnaviRowLeft';
			$('subnaviLiveRowRight').className = 'subnaviRowRight';			
			break;
		case 'best':
			$('subnaviMostRow').className = 'subnaviMostActive';
			$('subnaviNewRow').className = 'subnaviNew';
			$('subnaviLiveRow').className = 'subnaviLive';

			$('subnaviNewRowLeft').className = 'subnaviRowLeft';
			$('subnaviNewRowRight').className = 'subnaviRowRight';

			$('subnaviMostRowLeft').className = 'subnaviRowLeftActive';
			$('subnaviMostRowRight').className = 'subnaviRowRightActive';

			$('subnaviLiveRowLeft').className = 'subnaviRowLeft';
			$('subnaviLiveRowRight').className = 'subnaviRowRight';			
			break;
		case 'live':
			$('subnaviMostRow').className = 'subnaviMost';
			$('subnaviNewRow').className = 'subnaviNew';
			$('subnaviLiveRow').className = 'subnaviLiveActive';

			$('subnaviNewRowLeft').className = 'subnaviRowLeft';
			$('subnaviNewRowRight').className = 'subnaviRowRight';

			$('subnaviMostRowLeft').className = 'subnaviRowLeft';
			$('subnaviMostRowRight').className = 'subnaviRowRight';

			$('subnaviLiveRowLeft').className = 'subnaviRowLeftActive';
			$('subnaviLiveRowRight').className = 'subnaviRowRightActive';
			break;
	}
}

/*
	Video-Player-Aktivitäten
*/
function SetPlayerAction(btn_action) {
	var volume_now = 0;
	var volume_set = 0;
	var volume_step = 10;
	var player_art = 'Wmt';

	if(browser_name == 'msie' || browser_name == 'ff') {
		switch(player_art) {
			case 'Wmt':
				video_status = $('MediaPlayer').playState;

				switch(btn_action) {
					case 'start':
						$('MediaPlayer').controls.play();
						InitButtonStatus(btn_action, 'active', 1);
						break;
					case 'stop':
						if(video_status > 1 && video_status < 6) {
							$('MediaPlayer').controls.stop();
							InitButtonStatus(btn_action, 'active', 1);
						}
						break;
					case 'pause':
						alert(video_status);
						if(video_status > 2 && video_status < 6) {
							$('MediaPlayer').controls.pause();
							InitButtonStatus(btn_action, 'active', 1);
						}
						break;
					case 'fullscreen':
						if(video_status == 3) {
							$('MediaPlayer').fullScreen = 'true';
						}
						break;
					case 'volume_plus':
						volume_set = $('MediaPlayer').settings.volume + volume_step;

						if(volume_set > 100) {
							volume_set = 100;
						}

						$('MediaPlayer').settings.volume = volume_set;
						break;
					case 'volume_minus':
						volume_set = $('MediaPlayer').settings.volume - volume_step;

						if(volume_set < 0) {
							volume_set = 0;
						}

						$('MediaPlayer').settings.volume = volume_set;
						break;
				}
			break;
		}
	}
}

/*
	Button-Engine initialisieren
*/
function SetButton(action, name) {
	var image_src = '';
	var image_tmp = '';

	image_src = document.images["ctl_" + name + "_btn"];
	image_tmp = CleanButtonStatus(image_src);
	
	if(image_tmp.src.indexOf('_a.gif') == -1) {
		switch(action) {
			case 'over':
				image_src.src = image_tmp.src.replace('.gif', '_o.gif');
				break;
			case 'out':
				image_src.src = image_tmp.src.replace('_o.gif', '.gif');
				break;
			case 'active':
				if(image_tmp.src.indexOf('_a.gif') == -1) {
					image_src.src = image_tmp.src.replace('.gif', '_a.gif');
				}
				break;
		}
	}

	return image_src;
}

/*
	Buttons im Customized-Design zurücksetzen
*/
function CleanButtonStatus(image_src) {
	image_src.src = image_src.src.replace('_o.gif', '.gif');
	return image_src;
}

/*
	Buttons im Customized-Design aktualisieren
*/
function InitButtonStatus(name, action, active) {
	var image_src = '';

	image_src = SetButton(action, name);

	if(active == 1) {
		if(button_active != '') {
			if(button_active.src != image_src.src) {
				button_active.src = button_active.src.replace('_a.gif', '.gif');
			}
		}

		button_active = image_src;
	}
}

function ShowVideoContent() {
	$('LayVideoContent').style.display = 'block';
}

function SubmitPlayerAction(action, time) {

}

function openTarget() {
	window.open("http://ad-emea.doubleclick.net/clk;222686601;46439785;s");
	var url = 'click.5.html';
	new Ajax.Request(url, {
  		method: 'get'
	});
}
