/*******************************************************************************
* Init
*******************************************************************************/

	var vIndex		= 0;
	var vSecure		= false;
	var vLinkArray	= new Array;
	var Ajax_Handler = '/ddl/res/mod/AjaxHandler.mod.php';
	var Ajax_Animation = '<img src="/res/gr/Ani/Loading.gif" border="0" width="20" height="20" alt="Inhalt wird geladen" tile="">';

/*******************************************************************************
* JQuery
*******************************************************************************/

	function AJ_Request(Request) {

		//> Init
		var Param1 = arguments[1];
		var Param2 = arguments[2];
		var Param3 = arguments[3];

		//> Requests Verarbeiten
		switch (Request) {

			case 'GetPreview':
				if (Param2 == 'Layer') {
					tb_show(Param3, Ajax_Handler + '?height=440&width=615&Request=ShowEntry&ID=' + Param1);
					return false;
				} else if (Param2 == 'Promotion') {
					tb_show(Param3, Ajax_Handler + '?height=400&width=400&Request=Promotion&ID=' + Param1);
					return false;
				} else if (Param2 == 'Comments') {
					tb_show(Param3, Ajax_Handler + '?height=440&width=800&Request=Comments&ID=' + Param1);
					return false;
				} else {

					if ($('#QuickView' + Param1).length == 0)
						$.ajax({type: "POST", url: Ajax_Handler, dataType: "html",
							data: "Request="+ Request + ((Param2 == "QuickView2") ? "2" : "") + "&Param1=" + Param1,
							success: function(html) {
								$('#BlockItem_' + Param1).append(html);
								$('#BlockItem_' + Param1).animate({ height: "150px"}, 1100);
							}
						});
					else {
						if ($('#QuickView' + Param1).css("display") == 'block') {
							$('#BlockItem_' + Param1).animate({ height: "22px"}, 800);
							$('#QuickView' + Param1).fadeOut();
						} else {
							$('#BlockItem_' + Param1).animate({ height: "150px"}, 1100);
							$('#QuickView' + Param1).fadeIn();
						}
					}
				}
				break;

			case 'RaiseDTC':

				$.ajax({type: "POST", url: Ajax_Handler, dataType: "text",
					data: "Request=RaiseDTC&Param1=" + Param1,
					success: function(Msg) {
						alert(Msg);
					}
				});

				break;

			case 'RaiseTagCounter':

            	if (!confirm('Bist Du Dir sicher, dass Du diesen Eintrag\n' + ((Param2 == 'Top') ? 'POSITIV' : 'NEGATIV') + '\nBerwerten möchtest?'  )) return;

				$.ajax({type: "POST", url: Ajax_Handler, dataType: "json",
					data: "Request="+ Request + "&EntryID=" + Param1 + '&Mode=' + Param2,
					success: function(json) {
						alert(json.Msg);
					}
				});
				break;

			case 'CommentIt':

				$.ajax({type: "POST", url: Ajax_Handler, dataType: "json",
					data: "Request="+ Request + "&" + $("#CommentForm").serialize(),
					success: function(json) {
						if (json.Error == 1)	alert(json.Msg);
						else					$('#NewCommentRow').append(json.Msg);
						$('#MewoComment').attr('value', '');
					}
				});

				break;

			case 'ToggleGenreGroup':

				//> Gruppe ein- oder ausblenden
				$('.Group' + Param1).toggle();

				break;

		}

	}

/*******************************************************************************
* Grafische Spielerein
*******************************************************************************/

	function AddBtnEffect() {
		$(".NewsItem").bind("mouseover", function(e) { $(this).css("borderColor", "#B3B9C1"); });
		$(".NewsItem").bind("mouseout",  function(e) { $(this).css("borderColor", ""); });
		$(".NewsItem").bind("mousedown", function(e) { $(this).css("borderColor", "#3A434E"); $(this).css("marginTop", "1px"); $(this).css("marginBottom", "1px"); });
		$(".NewsItem").bind("mouseup",	 function(e) { $(this).css("borderColor", "#B3B9C1"); $(this).css("marginTop", "0px"); $(this).css("marginBottom", "2px"); });
	}

	function ShowTop5(No) {
		for (var i = 0; i < 8; i++)
			document.getElementById('Top5ImageNo' + i).style.display = ((i == 4 || i == 0 || (No == 1 && i > 4) || (No == 0 && i < 4) ) ? 'inline' : 'none');
	}

	function ToogleDescriptionBox() {
		var BoxHeight = $('.DynamicDescription').height();
        $('.DynamicDescription').animate({ height: ((BoxHeight > 160) ? '160' : '460') + 'px'}, 600);
	}

	function ToogleScreenshot(ID) {
		var BoxHeight = $('#ScreenshotSpace').height();

		if (BoxHeight > 2) {
	        $('#ScreenshotSpace').html('');
	        $('#ScreenshotSpace').css('font-size', '1px');
	        $('#ScreenshotSpace').animate({ height: '1px'}, 600);
		} else {

	        $('#ScreenshotSpace').animate({ height: '50px'}, 600);
	        $('#ScreenshotSpace').css('font-size', '12px');
	        $('#ScreenshotSpace').html('<br><center>' + Ajax_Animation + '</center>');

			//> Eintrag Details holen
			$.ajax({type: "POST", url: Ajax_Handler, dataType: "json",
				data: "Request=GetScreenShots&ID=" + ID,
				success: function(Response) {
					$('#ScreenshotSpace').animate({ height: Response.Height + 'px'}, 400, "swing", function() {
	                	$('#ScreenshotSpace').html(Response.HTML);
						tb_init('.Peeview');
					});
				}
			});

		}

	}

/*******************************************************************************
* Formulare
*******************************************************************************/

	function add() {
		top.location = vLinkArray[vIndex];
		vIndex ++;
		if (vIndex == vLinkArray.length && vSecure && vLinkArray[vIndex] != '') {
			top.clearInterval(vSecure);
			vIndex = 0;
		}
		return true;
	}

	function SubmitForm(FormNo) {
		$("form")[FormNo].submit();
	}


	function SubFormWithCheck(FormID, FormNo) {

		switch (FormID) {

        	case 'UploadForm':

            	if ($('#PromoTitle').attr('value') != undefined && $('#PromoLng').attr('value') != undefined && $('#PromoDescr').attr('value') != undefined && $('#GroupDetail_46').attr('value') != undefined && $('#GroupDetail_46').attr('value') != 'http://archiv.to/?Module=Details&HashID=' && $('#GroupDetail_50').attr('value') != undefined) {
					SubmitForm(FormNo);
				} else {
					alert('Um einen Titel oder ein Album zu promoten, brauchen wir folgende Daten von Dir:\n - Titel\n - Sprache\n - Beschreibung\n - Archiv.to Link\n - Genre\n\n');
				}

				break;

		};


	}

	function DownloadAllLinks() {
		for (i = 0; i < arguments.length; i++) vLinkArray[i]  = arguments[i];
		vSecure = top.setInterval('add()', 400);
	}

/*******************************************************************************
* Browser Goodies
*******************************************************************************/

	function GetSearchPlugin() {
		try {
			window.external.AddSearchProvider("http://www.saugstube-server.to/pub/xml/SearchPlugin.xml");
		} catch (ex1) {
			alert("Das Suchplugin funktioniert leider nur unter Firefox und Internet Explorer 7.\nWenn Du mit Opera (9) unterwegs bist, klicke einfach mit rechts auf das Suchfesnter und wähle 'Suche hinzufügen' ;)");
		}
	}