$(document).ready(function(){

jQuery.fn.extend({
   check: function() {
     return this.each(function() { this.checked = true; });
   },
   uncheck: function() {
     return this.each(function() { this.checked = false; });
   }
 });



// toggle advanced search:	

	$("#search-toggle-advanced").click(function () {
		$("#search-box-body-news-2").slideToggle("fast");
		$(this).toggleClass("selected");
		return false;
	});

// toggle language menu
	$("#toggle-lang-box").click(function () {
		var target = $("#select-language");
		// calculate position of popup-container (use only with dimensions plugin present!)
		var posX = $(this).position().left + $(this).outerWidth() - target.outerWidth();
		target.css("left", posX);
		target.toggle();
		$(this).toggleClass("act");
		return false;
	});
	
// toggle login menu
	$("#toggle-login-box").click(function () {
		var target = $("#login-box");
		// calculate position of popup-container (use only with dimensions plugin present!)
		var posX = $(this).position().left + $(this).outerWidth() - target.outerWidth();
		target.css("left", posX);
		target.toggle();
		$(this).toggleClass("act");
		return false;
	});
	
// toggle login menu
	$("#toggle-login-box2").click(function () {
		var target = $("#login-box");
		// calculate position of popup-container (use only with dimensions plugin present!)
		var posX = $(this).position().left + $(this).outerWidth() - target.outerWidth();
		target.css("left", posX);
		target.toggle();
		$(this).toggleClass("act");
		return false;
	});	

// generic adjacent container toggle
	$('.toggle-container').next().hide();
	$('.toggle-container').click(function() {
		$(this).next().slideToggle('fast');
		$(this).toggleClass("expanded");
		return false;
	});


// generic adjacent profil container toggle
	$(".expandableTab-profil")
		.click(function() {
				$(this).siblings(".expand-profil").toggle();
				$(this).find(".active").removeClass('active');
				$(this).siblings().children().siblings().find(".expandableTab").toggle();
				if ($(this).is(".notoggleactive")) {
		//console.log('HMM');
					$(this).siblings(".expandableTab-profil").toggle();
					//$(this).siblings().siblings(".expandableTab-profil").toggleClass('active');
					$(this).toggle();		
				}
				else if ($(this).siblings(".expandableTab-profil").is('*')) {
		//console.log('YEP');			
					$(this).siblings(".expandableTab-profil").toggle();
					$(this).siblings().siblings(".expandableTab-profil").toggleClass('active');
					$(this).toggle();
				};
				
				return false;
			});
			//.siblings(".expand-profil").hide();
//TOM für geöffnete Container im Profil	
	
	$(".closeIt").hide();		
	
	
	
	$(".expandableIsOpen-profil").siblings(".expand-profil").show();
			if ($(".expandableIsOpen-profil").siblings(".expandableTab-profil").is('*')) {
				$(".expandableIsOpen-profil").siblings(".expandableTab-profil").toggle();
				$(".expandableIsOpen-profil").siblings().siblings(".expandableTab-profil").toggleClass('active');
				$(".expandableIsOpen-profil").toggle();
			}

		
// generic adjacent news container toggle
	$(".expandableTab")
		.click(function() {
			$(".expandableTab").parent().parent().parent().find(".expand-profil").show();
			$(this).toggle();
			if ($(this).parent().parent().parent().children(".expandableTab-profil").next().is('*')) {
				$(this).parent().parent().parent().children(".expandableTab-profil").toggle();
			};
			return false;
		})
		.siblings(".expand").hide(); 
		

// generic adjacent news container toggle
	$(".expandableTab-all")
		.click(function() {
				$(this).siblings(".expand").toggle();
				$(this).toggle();
				if ($(this).siblings().siblings(".expandableTab-all").is('*')) {
					$(this).siblings().siblings(".expandableTab-all").toggle();
					$(this).toggle();
				};
				return false;
			})
			.siblings(".expand").hide();
	

// blog container toggle
	$(".expandableTab-blog-all")
		.click(function() {
				$(this).siblings(".expand-blog").toggle();
				$(this).toggle();
				//$(this).siblings(".expandableTab-blog-all-close").toggle(); 
				if ($(this).siblings().siblings(".expandableTab-blog-all").is('*')) {
		//console.log('MU');			
					$(this).siblings().siblings(".expandableTab-blog-all").toggle();
					$(this).toggle();
				};
				return false;
			})
			.siblings(".expand-blog").hide();


	
// profil portfolios container toggle
	$(".gallery_box.prev").not(".hover").mouseover(function(){
		$(this).addClass("hover");
	});
	
	$(".gallery_box.prev").not(".active").mouseout(function(){
		$(this).removeClass("hover");
	});

	$(".gallery_box.prev").click(function(){
		$(".gallery_box.prev").removeClass('active');
		$(this).not($(this).filter(".active").removeClass("active")).addClass("active");
	});

	
	
// profil tooltips	
if ($('.gallery_box .galleryImage').cluetip) {
	$('.gallery_box .galleryImage').cluetip({
		//topOffset: -5,
		//leftOffset:-348,
		width:            336,      // The width of the clueTip
	    height:           'auto',   // The height of the clueTip
	    cluezIndex:       97,       // Sets the z-index style property of the clueTip
	    positionBy:       'auto',   // Sets the type of positioning: 'auto', 'mouse','bottomTop', 'fixed'
	    topOffset:        -5,       // Number of px to offset clueTip from top of invoking element
	    leftOffset:       -348,       // Number of px to offset clueTip from left of invoking element
	    local:            false,    // Whether to use content from the same page for the clueTip's body
	    hideLocal:        true,     // If local option is set to true, this determines whether local content
	                                // to be shown in clueTip should be hidden at its original location
	    attribute:        'rel',    // the attribute to be used for fetching the clueTip's body content
	    titleAttribute:   'title',  // the attribute to be used for fetching the clueTip's title
	    splitTitle:       '',       // A character used to split the title attribute into the clueTip title and divs
	                                // within the clueTip body. more info below [6]
	    showTitle:        true,     // show title bar of the clueTip, even if title attribute not set
	    cluetipClass:     'default',// class added to outermost clueTip div in the form of 'cluetip-' + clueTipClass.
	    hoverClass:       '',       // class applied to the invoking element onmouseover and removed onmouseout
	    waitImage:        true,     // whether to show a "loading" img, which is set in jquery.cluetip.css
	    cursor:           'help',
	    arrows:           false,    // if true, displays arrow on appropriate side of clueTip
	    dropShadow:       false,     // set to false if you don't want the drop-shadow effect on the clueTip
	    dropShadowSteps:  3,        // adjusts the size of the drop shadow
	    sticky:           true,    // keep visible until manually closed
	    mouseOutClose:    true,    // close when clueTip is moused out
	    activation:       'hover',  // set to 'click' to force user to click to show clueTip
	                                // set to 'focus' to show on focus of a form element and hide on blur
	    clickThrough:     false,    // if true, and activation is not 'click', then clicking on link will take user to the link's href,
	                                // even if href and tipAttribute are equal
	    tracking:         false,    // if true, clueTip will track mouse movement (experimental)
	    delayedClose:     0,        // close clueTip on a timed delay (experimental)
	    closePosition:    'title',    // location of close text for sticky cluetips; can be 'top' or 'bottom' or 'title'
	    closeText:        'close',  // text (or HTML) to to be clicked to close sticky clueTips
	    truncate:         0       // number of characters to truncate clueTip's contents. if 0, no truncation occurs
	});
}	
	
// generic adjacent dropdown menue member profil
if ($('ul.sub_menu').superfish)
	$('ul.sub_menu').superfish();	
		
	
	
// Toggle Edit View member profil	
	$('#showEdit_01 .btn_addto, #showEdit_01 .basic .iconPool .btn_edit, #showEdit_01 .btn_editClose, #showEdit_01 .btn_abort, #showEdit_01 .btn_file_upload').click(function() { 
		$('#showEdit_01 .basic').toggle(); 
		$('#showEdit_01 .edit').toggle();
		return false;
	});


	
	$('#showEdit_02 .contactLeft_account .btn_addto, #showEdit_02 .contactLeft_account .btn_edit, #showEdit_02 .contactLeft_account .btn_editClose, #showEdit_02 .contactLeft_account .btn_abort').click(function() { 
		$('#showEdit_02 .contactLeft_account.basic').toggle(); 
		$('#showEdit_02 .contactLeft_account.edit').toggle();
		return false;
	});
	$('#showEdit_02 .contactRight_account .btn_addto, #showEdit_02 .contactRight_account .btn_edit, #showEdit_02 .contactRight_account .btn_editClose, #showEdit_02 .contactRight_account .btn_abort, #office_delete').click(function() { 
		$('#showEdit_02 .contactRight_account.basic').toggle(); 
		$('#showEdit_02 .contactRight_account.edit').toggle();
		return false;
	});

	
	$('#showEdit_03 #btn_addto_left, #showEdit_03 .contactLeft_account .btn_edit, #showEdit_03 .contactLeft_account .btn_editClose, #showEdit_03 .contactLeft_account .btn_abort').click(function() { 
		$('#showEdit_03 .contactLeft_account.basic').toggle(); 
		$('#showEdit_03 .contactLeft_account.edit').toggle();
		return false;
	});
	$('#showEdit_03 #btn_addto_right, #showEdit_03 .contactRight_account .btn_edit, #showEdit_03 .contactRight_account .btn_editClose, #showEdit_03 .contactRight_account .btn_abort').click(function() { 
		$('#showEdit_03 .contactRight_account.basic').toggle(); 
		$('#showEdit_03 .contactRight_account.edit').toggle();
		return false;
	});
	
	
	$('#showEdit_04 .btn_addto, #showEdit_04 .basic .btn_edit, #showEdit_04 .btn_editClose, #showEdit_04 .btn_abort').click(function() { 
		$('#showEdit_04 .basic').toggle(); 
		$('#showEdit_04 .edit').toggle();
		return false;
	});
	
		
	$('#showEdit_05 .btn_addto, #showEdit_05 .btn_edit, #showEdit_05 .btn_editClose, #showEdit_05 .btn_abort').click(function() { 
		$('#showEdit_05 .basic').toggle(); 
		$('#showEdit_05 .edit').toggle();
		return false;
	});	

//TOM 02.2010 geändert auf Video upload
	$('#showEdit_06 .btn_video_upload, #showEdit_06 .btn_editClose, #showEdit_06 .btn_abort').click(function() { 
		$('#showEdit_06 .basic').toggle(); 
		$('#showEdit_06 .edit').toggle();
		return false;
	});	
	
//TOM 06.2010 Image u Video getrennt
	$('#showEdit_07 .jqimage .btn_image_upload, #showEdit_07 .jqfilm .btn_video_upload, #showEdit_07 .btn_editClose, #showEdit_07 .btn_abort').click(function() { 
		$('#showEdit_07 .basic').toggle(); 
		$('#showEdit_07 .edit').toggle();
		
		if ($('#showEdit_07 .edit').css('display') == "none"){
				clearFileUpload();
		}
		return false;
	});	
	
	$('#lb-creditsTwo1-save_btn, #lb-creditsThree1-save_btn, #lb-creditsThreeMedia-save_btn').click(function(){
		if (layereditQueue.length == 1 || layereditQueue.length == 0) {
			clearFileUpload();
		}
	});
	
	$('input[type="image"].btn_send_lightbox.de').mouseover(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_send_lightbox_over_de.gif");
	});
	
	$('input[type="image"].btn_send_lightbox.de').mouseout(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_send_lightbox_de.gif");
	});
	$('input[type="image"].btn_send_lightbox.en').mouseover(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_send_lightbox_over_en.gif");
	});
	$('input[type="image"].btn_send_lightbox.en').mouseout(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_send_lightbox_en.gif");
	});
	$('input[type="image"].btn_send_lightbox.fr').mouseover(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_send_lightbox_over_fr.gif");
	});
	$('input[type="image"].btn_send_lightbox.fr').mouseout(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_send_lightbox_fr.gif");
	});
	
	
	$('input[type="image"].btn_search.de').mouseover(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_search_over_de.gif");
	});
	$('input[type="image"].btn_search.de').mouseout(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_search_de.gif");
	});
	$('input[type="image"].btn_search.en').mouseover(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_search_over_en.gif");
	});
	$('input[type="image"].btn_search.en').mouseout(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_search_en.gif");
	});
	$('input[type="image"].btn_search.fr').mouseover(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_search_over_fr.gif");
	});
	$('input[type="image"].btn_search.fr').mouseout(function() {
		$(this).attr("src", "/css/default/img/buttons/btn_search_fr.gif");
	});
	
	
	
	
	$('.btn_load_previous').click(function() {
		loadpreviouscredits($(this).parents('form').attr('id').replace('form_', ''))
	});
	
	
	$("#aktuell").click(function() { 
			if($(this).is(":checked")) {
				//Ist angehakt - mach was 
				$('.bgBasic').removeClass('low');
				$('.opencloseEdit').removeClass('nichtDa');
				$.each($('.latestnews_haken'), function(i, item){
					item.readOnly = false;
					item.onkeydown = "return true;";
					item.onclick = "return true;";
					/*.attr('readonly', 'false');*/
				});
			}else {
				//Ist nicht angehakt - machs wieder r�ckg�ngig (bitte)
				$('.bgBasic').addClass('low');
				$('.opencloseEdit').addClass('nichtDa');
				$.each($('.latestnews_haken'), function(i, item){
					item.readOnly = true;
					item.onkeydown = "return false;";
					item.onclick = "return false;";
					/*.attr('readonly', 'true');*/
				});
			}	
		});

	
	$('#showUploader').click(function() {
		var uiLayer = YAHOO.util.Dom.getRegion('selectLink');
		var overlay = YAHOO.util.Dom.get('uploaderOverlay');
		YAHOO.util.Dom.setStyle(overlay, 'width', uiLayer.right-uiLayer.left + "px");
		YAHOO.util.Dom.setStyle(overlay, 'height', uiLayer.bottom-uiLayer.top + "px");
	});

	
	
	$('#category-links > li').click(function(){
		
		url = $(this).find('a').attr('href');
		$.getJSON(url, function(result) {
			$("#list-artists-by-categories").html('');

			for (i=0; i< result.length; i++){
				style = i == 0 ? "style=\'margin-top:20px;\'" : "";
				$("#list-artists-by-categories").append("<li class='overviewArtist moduleRow' "+style+"><a href='/artist/show/id/"+result[i]['artist_id']+"/src/member/'><span class='textPool widthExp'><b>"+result[i]['lastname']+", "+result[i]['firstname']+"</b>| "+result[i]['category_id']+" | "+result[i]['location_id']+"</span><span class='iconPool'>"+result[i]['span_icons']+"</span></a></li>");
			}
			
		});
		
		$('#category-links').hide();
		
		return false;
		
	});
	

		
		
	$('#category-links-edit > li').click(function(){
		
		url = $(this).find('a').attr('href');
		$.getJSON(url, function(result) {
			$("#list-artists-by-categories").html('');

			for (i=0; i< result.length; i++){
				style = i == 0 ? "style=\'margin-top:20px;\'" : "";
				$("#list-artists-by-categories").append("<li class='overviewArtist moduleRow' "+style+"><span class='textPool widthExp'><b>"+result[i]['lastname']+", "+result[i]['firstname']+"</b>| "+result[i]['category_id']+" | "+result[i]['location_id']+"</span><span class='buttonPool'><a href='/profile/artist/id/"+result[i]['artist_id']+"' class='btn_edit "+language+"'>bearbeiten</a><a href='#' class='btn_delete "+language+"'>löschen</a></span><span class='iconPool'>"+result[i]['span_icons']+"</span></li>");
			}
			
		});
		
		return false;

	});

	$('#list-artists-by-categories .btn_delete').click(function(){
		
		$(this).unbind('click');
		
		id = $(this).prev().attr('href').replace('/profile/artist/id/', '');
		
		showConfirm("deleteArtist("+id+");$('#artist_"+id+"').remove();");
		
		return false;
	});
	
	
	
});	











