jQuery(function($){



	var host = window.location.host;
	var basePath = "http://" + host + "/";
	var actualPage = window.location.href;
	var languageLx = actualPage.match(/L=.?/g);
	if(languageLx){
		var languageLx = languageLx.reverse();
	} 

	$(".tx-proxsysext-pi3-item").each(function(){
		var selectableMetadata1 = $(this).find(".selectableMetadata1 .content1");
		var selectableMetadata4 = $(this).find(".selectableMetadata4 .content4");
		var selectableMetadata4_text = selectableMetadata4.text();
		selectableMetadata4.text(selectableMetadata4_text + ", ");
/*
	//	var selectableMetadata4_html = selectableMetadata4.html();
		var selectableMetadata4_secLabel = selectableMetadata4.find(".sec .label");
		var selectableMetadata4_secLabel_text = selectableMetadata4_secLabel.text();
		selectableMetadata4_secLabel.text(selectableMetadata4_secLabel_text + ", ");
*/
		$(this).find("h5").after(selectableMetadata4, selectableMetadata1);
	});

/*
//  $f("#page-154 #pxPlayer", "typo3conf/ext/proxsysext/res/flowplayer/flowplayer-3.2.2.swf", {
  $f("pxPlayer", "typo3conf/ext/proxsysext/res/flowplayer/flowplayer-3.2.2.swf", {
    plugins: {
      controls: {fullscreen: false}
    }
  });
*/


	// Line break after "Worldmediafestival" in Menu:
//	$(".menu_left li.page153 a.menu_left_aTag, .menu_left li.page154 a.menu_left_aTag").replace(/ /, "<br>");
//	$(".menu_left li.page153 a.menu_left_aTag, .menu_left li.page154 a.menu_left_aTag").replace(/Worldmediafestival /, "Worldmediafestival<br>");

//	$(".tx-proxsysext-pi3-item .selectableMetadata4 .content4, .tx-proxsysext-pi3-item .selectableMetadata1 .content1").insertAfter(".tx-proxsysext-pi3-item h5")

//alert(languageLx[0]);

	$('.tx-proxsysext-pi3 li.tx-proxsysext-pi3-item').add('.tx-proxsysext-pi1 .newsList').add('.tx-proxsysext-pi2 li.tx-proxsysext-pi3-item').add('.tx-proxsysext-pi5 .newsList').each(function(){
		var itemForPicturePiX = this;
		$(this).find('#smallPic').append('<img class="button_player_px" src="fileadmin/templates/images/button_player_px.png" />')
	//	$(this).find('.detailInfo').css('display', 'none');
//		$(this).find('.button_player_px').click(function(){
//		$(this).find('#smallPic').click(pxSearchFormat());

//		$(this).find('#smallPic').click(function(){
//			pxSearchFormat(pxSearchFormat);
//		});

//		$(this).find('#smallPic').bind("click",pxSearchFormat2);

		$(this).find('#smallPic').click(function(){
			$(itemForPicturePiX).find('.detailInfo').trigger('click');
		});

	})



	$('#col3_content_top').append("<div class='line2'></div>");
//	$('.px_pi2_projectForm .px_media_search').clone().appendTo($('#col3_content_top .line2'));
//	$('.px_pi2_searchForm').appendTo($('#col3_content_top .line2'));

	$('#col3_content_top .line2').after($(".px_pi2_projectForm"));

	$("#menu_left li.page153").append($("#page-153 .px_folderList"));
	$("#menu_left li.page154").append($("#page-154 .px_folderList"));
	$("#menu_left li.page142").append($("#page-142 .px_folderList"));
	$("#menu_left li.page141").append($("#page-141 .px_folderList"));
	$("#menu_left li.page140").append($("#page-140 .px_folderList"));
	$("#menu_left li.page139").append($("#page-139 .px_folderList"));

	$(".px_pi2_searchForm .submit").attr("value", "Go");

	$("#logo_topleft").click(function(){
		window.location.href = "http://www.worldmediafestival.org/en/festival_information/about_us";
	});


	// Internet addresses in .selectableMetadata2 (comes from metadata field URL)
	// shall become real links.

	$(".tx-proxsysext-pi3-item .selectableMetadata2 .content").each(function(){
		var urlInMetadataList_text = $(this).text();
		if(urlInMetadataList_text){
			var urlInMetadataList_link = "<a href='" + urlInMetadataList_text + "' target='_blank'>" + urlInMetadataList_text + "</a>";
			$(this).html(urlInMetadataList_link);
		}
	});
/*
	// Don't show picture in single view if url is shown
	var urlText = $(".pxSingleView #longList .URL").text();
	if(urlText){
		$(".pxSingleView #flashinhalt-image").css("display","none");
	}
*/

	// If in the register page you have ###FIELD_username### instead of the user name:
//alert('test');
	$("#page-128 dd").each(function(){
//alert('xxx');
		var registerPage_ddText = $(this).text();
		var match_fieldUsername = registerPage_ddText.match(/###FIELD_username###/);
//alert(registerPage_ddText);
//alert(match_fieldUsername);
		if(match_fieldUsername == "###FIELD_username###"){
			$(this).text("Is your email address");
		}
	});

/*
	// page "Links"
	$("#page-134 .csc-textpic-text:first").css({"border-top": "none", "padding-top": "0px"});
	$("#page-134 .csc-textpic-imagewrap:first").css({"margin-top": "0px"});
*/
/*
	var px_label_search  = $(".px_label_actualFolder .label_search").text();
//	if(px_label_search != false){
	if(px_label_search == "search"){
		$(".px_label_actualFolder").css("display","inline");
	}
*/
/*
	// Disk ID / Blu-ray ID, Quick Select, Folder, Container
//	$(".px_containerView").prependTo("#col1_content .submenu");
	$(".px_folder_header").prependTo("#col1_content .submenu");
	$(".px_folder_header").after($(".px_folderList"));
	$(".px_diskIdOutput").prependTo("#col1_content .submenu");
	$(".px_quickselect").prependTo("#col1_content .submenu");

	var px_quickselect_header = $(".px_quickselect .qsHeader").text();
	var px_diskIdOutput_header = $(".px_diskIdOutput .header").text();
	var px_folder_header = $(".px_folder_header").text();
	$(".px_quickselect .qsHeader, .px_diskIdOutput .header, .px_folder_header").text("");

	var pxDiskIdList = $(".px_diskIdOutput .diskIdList");
	if ($(".px_diskIdOutput .diskIdList").css("display") != "none") {
//	if ((pxDiskIdList != false) && (pxDiskIdList.css("display") != "none")) {
//		$("#col3_content_top").append($(".px_label_ActualDiskId"));
		$("#col3_content_top .line2").prepend($(".px_label_ActualDiskId"));
		var px_diskIdOutput_header_activity = "-active";
	}
	else {
		var px_diskIdOutput_header_activity = "";
	}
	$(".px_diskIdOutput .header").html("<img src='fileadmin/templates/images/blu-ray-id" + px_diskIdOutput_header_activity + ".gif' alt='" + px_diskIdOutput_header + "'>");
		
	if($(".px_quickselect .quickselectList").css("display") != "none"){
//		$("#col3_content_top").append($(".px_label_QuickSearchItem"));
		$("#col3_content_top .line2").prepend($(".px_label_QuickSearchItem"));
		var px_quickselect_header_activity = "-active";
	}else{
		var px_quickselect_header_activity = "";
	}

	if(languageLx){
		if(languageLx[0] == 'L=0'){
			$(".px_quickselect .qsHeader").html("<img src='fileadmin/templates/images/schnellauswahl" + px_quickselect_header_activity + ".gif' alt='" + px_quickselect_header + "'>");
		} else if(languageLx[0] == 'L=1'){
			$(".px_quickselect .qsHeader").html("<img src='fileadmin/templates/images/quick-select" + px_quickselect_header_activity + ".gif' alt='" + px_quickselect_header + "'>");
		} else {
			$(".px_quickselect .qsHeader").html("<img src='fileadmin/templates/images/schnellauswahl" + px_quickselect_header_activity + ".gif' alt='" + px_quickselect_header + "'>");
		}
	} else {
		$(".px_quickselect .qsHeader").html("<img src='fileadmin/templates/images/schnellauswahl" + px_quickselect_header_activity + ".gif' alt='" + px_quickselect_header + "'>");
	}

	if($(".px_folderList").css("display") != "none"){
//		$("#col3_content_top").append($(".px_label_actualFolder"));
//		$("#col3_content_top .proxsysext-searchform").prepend($(".px_label_actualFolder"));
		$("#col3_content_top .line2").prepend($(".px_label_actualFolder"));
		var px_folder_header_activity = "-active";
	}else{
		var px_folder_header_activity = "";
	}

	if(languageLx){
		if(languageLx[0] == 'L=0'){
			$(".px_folder_header").html("<img src='fileadmin/templates/images/ordner" + px_folder_header_activity + ".gif' alt='" + px_folder_header + "'>");
		} else if(languageLx[0] == 'L=1'){
			$(".px_folder_header").html("<img src='fileadmin/templates/images/folders" + px_folder_header_activity + ".gif' alt='" + px_folder_header + "'>");
		} else {
			$(".px_folder_header").html("<img src='fileadmin/templates/images/ordner" + px_folder_header_activity + ".gif' alt='" + px_folder_header + "'>");
		}
	} else {
		$(".px_folder_header").html("<img src='fileadmin/templates/images/ordner" + px_folder_header_activity + ".gif' alt='" + px_folder_header + "'>");
	}

	// Blu-ray ID / Disk ID: open directly first subpage
	$("#submenu a.page126").click(function(){
		var newPageBasic = $("#submenu a.page100").attr("href");
		if(newPageBasic.match(/\?/) == "?"){
			window.location.href = basePath + newPageBasic + "&pxDiskID=pxStandard";
		} else{
			window.location.href = basePath + newPageBasic + "?pxDiskID=pxStandard";
		}
		return false;
	});
	// Quick select: open directly first subpage
	$("#submenu a.page125").click(function(){
		var newPageBasic = $("#submenu a.page100").attr("href");
		if(newPageBasic.match(/\?/) == "?"){
			window.location.href = basePath + newPageBasic + "&pxQuickSearchYear=pxStandard";
		} else{
			window.location.href = basePath + newPageBasic + "?pxQuickSearchYear=pxStandard";
		}
		return false;
	});

	// Folders: open directly first subpage
	$("#submenu a.page100").click(function(){
		var newPageBasic = $("#submenu a.page100").attr("href");
		window.location.href = basePath + newPageBasic + "?fId=pxStandard";
		return false;
	});

	// Container: open it
	$("#submenu a.page127").click(function(){
		var newPageBasic = $("#submenu a.page100").attr("href");
	//	window.location.href = newPageBasic + "?modus=container";
	//	window.location.href = newPageBasic + "&modus=container";
		window.location.href = basePath + newPageBasic + "&modus=container";
		return false;
	});

	// move the headline/title of a video item
	$(".tx-proxsysext-pi3-item").each(function(){
		var firstInfos = $(this).find("#firstInfos");
		$(this).find("h5").prependTo(firstInfos);
	})

	if (actualPage.match(/modus=container/) == "modus=container") {
		if((actualPage.match(/L=0/) == 'L=0') || (actualPage.match(/L=1/) == false)){
			$("#submenu a.page127 img").attr("src","fileadmin/templates/images/merkliste-active.gif");
		} else if(actualPage.match(/L=1/) == 'L=1'){
			$("#submenu a.page127 img").attr("src","fileadmin/templates/images/container-active.gif");
		}
		$("#col3_content_top .line2").prepend($(".px_label_actualFolder"));
	}

	if (actualPage.match(/search=/) == "search=") {
		$("#col3_content_top .line2").prepend($(".px_label_actualFolder"));
	}
*/
})

