var addthis_localize = {
    share_caption: "RECORDING.de"
}

var addthis_config = {
   ui_click:true,
   services_exclude: 'more'
}


function siteMap_slide(t) {
   if ($('map_slider').getStyle('height').toInt()==44) {
       document.sitemap_morph.start({
           'height': 300 //Morphs the height from the current to 200px.
           
       });
   }
   else {
       document.sitemap_morph.start({
           'height': 44 //Morphs the height from the current to 100px.
       });
   }
   
}

function pic_scroller () {
   var pos = $('pic_scroll').getStyle('left').toInt() - 100;
   (pos==(0-1200)) ? document.online_pos=0-300 : document.online_pos=0;
   document.pic_scroll_morph.start({
           'left': pos //Morphs the height from the current to 100px.
       });   
}

function scrolltotop() {
   var scroller = new Fx.Scroll(document.body,{duration:750,offset:{'x':0,'y':0}});
      scroller.toTop();     
}

function centerWindow() {
	/* window resizer */
	if ($defined($('centerblock'))) {
		var mywidth;
		if (window.innerwidth) {
			mywidth = window.innertWidth;
		}
		else {
			mywidth = document.body.clientWidth;
		}
		
		if (mywidth<1240) {
			if (mywidth<1080) {
				newwidth=0;
			}
			else {
				newwidth=(mywidth-1080)/2
			}
			$('centerblock').setStyle('padding-left',newwidth);
		}
	}
		return false;
}

function showOneLayer(layer, linker) {
    $$('.forum_left_head_content').each(function(el) {
        el.setStyle('display','none');
    });
    
    $$('.sel_active').each(function(el) {
            el.setProperty('class','sel_inactive');
    });    
    $(linker).setProperty('class','sel_active');
    $(layer).setStyle('display','block');
    
}

function getCookie(name) { 
  var mein_cookie = document.cookie; 
  if (mein_cookie.indexOf(name) == -1) { 
    return null; 
  }
  var anfang = mein_cookie.indexOf(name) + name.length + 1;  
  var ende = mein_cookie.indexOf(";", anfang); 
  if (ende == -1) { 
    ende = mein_cookie.length; 
  }
  var laenge=ende-anfang;
  var cookie_wert = unescape(mein_cookie.substr(anfang,laenge));
  return cookie_wert; 
}

function saveToggleStatus() {
   var ablauf=new Date();
   var inzweiWochen = ablauf.getTime() + (14 * 24 * 60 * 60 * 1000);
   ablauf.setTime(inzweiWochen);
   
     var t=new Array();
     for (i=1;i<10;i++) {
         if ($defined($('element_'+i))==true) t[i]=$('element_'+i).getStyle('display');
            
     }
     document.cookie="togglers="+t.join('#') +";expires="+ablauf.toGMTString();
}

function getToggleStatus() {

   
   if (document.cookie && $defined($('toggle_button_1'))) {
      var tStatus=getCookie('togglers');
      if (tStatus!=undefined) {
         tStatus=tStatus.split('#');
      }
      else {
         tStatus=new Array();
      }
      
     for (i=1;i<10;i++) {
      if ($defined($('element_'+i))) {
            if (tStatus[i]=='none') {
               $('element_'+i).setStyle('display','none');
               $('toggle_button_'+i).set('src',mySite+'images/forum/forum_toggle_right.png');
            }
            else if (tStatus[i]=='block') {
               $('element_'+i).setStyle('display','block');
               $('toggle_button_'+i).set('src',mySite+'images/forum/forum_toggle.png');
            }
         }
      }
   }
}


function toggleCategory(t) {
   
   if ($('element_'+t).getStyle('display')=='block') {
      $('element_'+t).setStyle('display','none');
      $('toggle_button_'+t).set('src',mySite+'images/forum/forum_toggle_right.png');
   }
   else {
      $('element_'+t).setStyle('display','block');
      $('toggle_button_'+t).set('src',mySite+'images/forum/forum_toggle.png');
   }
   saveToggleStatus();
   /*
   var toggleFX=new Fx.Morph(t, {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
   if ($(t).getStyle('display')=='block') {
      toggleFX.start({
         'height':1
      })
   }
   else {
      toggleFX.start({
         'height':200
      })
   }
   */
   
}

/**
 * Danke Funktion
 */

function jsDanke(id,module,toID,fromID, but) {
    
    if (but>0) {
	var suffix="_"+but;
    }
    else {
	var suffix="";
    }
    
    var myFx = new Fx.Tween($('daanke'+suffix),{
	    duration:500,
	    transition: Fx.Transitions.easeIn
    });
       
    
    var newDanke= new Request.HTML({method:'post', url:mySite+'actions/rpc.php', encoding:'utf-8',
        onRequest: function(html) {
	    myFx.start('opacity',1,0);
	},
	onSuccess: function(html) {
            //Clear after loading
	    $('daanke'+suffix).set('text', '');
	    $('daanke'+suffix).setStyle('opacity',0);
	    $('daanke'+suffix).adopt(html);
	    myFx.cancel('opacity');
	    myFx.start('opacity',0,1);
	    $('daanke'+suffix).removeEvent('click');
        }
    });
    
    newDanke.send('id='+id+'&module='+module+'&toID='+toID+'&fromID='+fromID+'&sec=danke&but='+suffix);
}

/**
 * Danke Funktion
 */

function forum_preview(targetLayer) {
        
    var newPreview= new Request.HTML({method:'post', url:mySite+'actions/rpc.php', encoding:'utf-8',
	onSuccess: function(html) {
            //Clear after loading
			$(targetLayer).empty();
	    $(targetLayer).adopt(html);
		return false;
        }
    });
	tinyMCE.triggerSave();
    var content
	if (targetLayer=="entry_preview") {
		content=$('f_input_content').get('value');
	}
	else {
		content=$('f_topic_content').get('value');
	}

    newPreview.send('sec=post_preview&content='+content);
}

function update_not(targetForm, targetLayer) {
        
    var newNot= new Request.HTML({method:'post', url:mySite+'actions/rpc.php', encoding:'utf-8',
	onSuccess: function(html) {
        //Clear after loading
		$(targetLayer).empty();
		if ($defined($('hidden_forum'))) $('hidden_forum').dispose();
		if ($defined($('hidden_post'))) $('hidden_post').dispose()
		if ($defined($('hidden_bookmark'))) $('hidden_bookmark').dispose()
	    $(targetLayer).adopt(html);
		return false;
        }
    }).post($(targetForm));
}

/*
Forum related
*/
function antworten(t,u) {
    var subject = (t.substr(0,2)!='Re') ? "Re:"+t : t;
    $('f_input_subject').set('value',subject);
	$('f_input_edit').set('value',0);
   $('f_input_pid').set('value',u);
   tinyMCE.execCommand('mceFocus',false,'f_input_content');
}

function neuer_Beitrag(t) {
    var subject = (t.substr(0,2)!='Re') ? "Re:"+t : t;
    $('f_input_subject').set('value',subject);
	$('f_input_edit').set('value',0);
   tinyMCE.execCommand('mceFocus',false,'f_input_content');
   window.location.href='#post'
}

function show_new_topic_form() {
   $('accordion').setStyle('display','none');
   $$('.forum_select_right').setStyle('display','none');
   $$('.forum_left').setStyle('display','none');
   $('accordion1').setStyle('display','inline-block');
}

function checkForumAnswerForm() {
   var u=true;
   if ($('f_input_content').get('value')=="" && u==true) {
      u=false;
      alert ("Irgendwas willst Du doch posten ... !");
   }

   return u;
}

function checkForumTopicForm() {
   var u=true;
   if ($('f_input_topic_subject').get('value')=="") {
      u=false;
      alert ("Bitte einen Betreff angeben !");
   }
   if ($('f_topic_content').get('value')=="" && u==true) {
      u=false;
      alert ("Irgendwas willst Du doch posten ... !");
   }   
   return u;
}

function zitieren(t,u,v) {

    var subject = (t.substr(0,2)!='Re') ? "Re: "+t : t;
    $('f_input_subject').set('value',subject);
    $('f_input_pid').set('value',u);
	$('f_input_edit').set('value',0);
    
    var cnt=$('post_cite_'+v).get('text');
    var cite=cnt.split('#_#');
    var quote="";
    for (var i=0;i<cite.length;i++) {
      if (cite[i]!="") quote+=cite[i];  
    }
    
    //tinyMCE.setContent(quote);
    tinyMCE.execCommand('mceFocus',false,'f_input_content');
    if(tinyMCE.get('f_input_content').getContent()!="[br]" && tinyMCE.get('f_input_content').getContent()!="") quote="[br]"+quote;
    tinyMCE.execCommand('mceInsertContent',false, quote);
    tinyMCE.execCommand('mceCleanup',false, 'f_input_content');
    tinyMCE.execCommand('mceFocus',false,'f_input_content');
    return false;
}

function post_edit(t,u,v,flag) {
   $('f_input_pid').set('value',u);
   $('f_input_edit').set('value',42);
   var cnt=$('post_edit_'+v).get('text');
   
   // If First Topic - make it editable ...
   if (flag==1) {
        $('f_input_subject').set('value',t);
	    $('post_edit_title').setStyle('display','block');
		$('edit_title_id').set('value',1);
   }
   else {
        $('post_edit_title').setStyle('display','none');
		$('edit_title_id').set('value',0);
   }
   
   tinyMCE.execCommand('mceFocus',false,'f_input_content');
   tinyMCE.execCommand('mceSetContent',false, cnt);
   tinyMCE.execCommand('mceCleanup',false, 'f_input_content');
   tinyMCE.execCommand('mceFocus',false,'f_input_content');
   return false;
}

/*
t-topic_id
p-post_id
*/
function loeschen(t,u,v) {
   var check = confirm("Diesen Beitrag wirklich löschen?");
   if (check==true) {
      url=window.location.href;
      window.location.href=mySite+"actions/index.php?t="+t+"&p="+u+"&h="+v+"&u="+url;
   }
   return false;
}

/*
function forum_preview(layer, src_name) {
   //var mySite="http://recording.easylabs.de/";
   var mySite="http://192.168.2.9/recording.de/httpdocs/"; 
   var newPreview= new Request.HTML({method:'post', url:mySite+'dyn_data/get_preview.php', encoding:'utf-8',
        onSuccess: function(html) {
            //Clear after loading
            $(layer).set('text', '');
            // clearing classes
            
            //Injection
            $(layer).adopt(html);
        }
    });
   newPreview.send('cat='+kategorie+'&amount='+amount+'&view='+view);
}
*/

var Tips=new Class({Implements:[Events,Options],options:{onShow:function(A){A.setStyle("visibility","visible");},onHide:function(A){A.setStyle("visibility","hidden");
},showDelay:100,hideDelay:100,className:null,offsets:{x:16,y:16},fixed:false},initialize:function(){var C=Array.link(arguments,{options:Object.type,elements:$defined});
this.setOptions(C.options||null);this.tip=new Element("div").inject(document.body);if(this.options.className){this.tip.addClass(this.options.className);
}var B=new Element("div",{"class":"tip-top"}).inject(this.tip);this.container=new Element("div",{"class":"tip"}).inject(this.tip);var A=new Element("div",{"class":"tip-bottom"}).inject(this.tip);
this.tip.setStyles({position:"absolute",top:0,left:0,visibility:"hidden"});if(C.elements){this.attach(C.elements);}},attach:function(A){$$(A).each(function(D){var G=D.retrieve("tip:title",D.get("title"));
var F=D.retrieve("tip:text",D.get("rel")||D.get("href"));var E=D.retrieve("tip:enter",this.elementEnter.bindWithEvent(this,D));var C=D.retrieve("tip:leave",this.elementLeave.bindWithEvent(this,D));
D.addEvents({mouseenter:E,mouseleave:C});if(!this.options.fixed){var B=D.retrieve("tip:move",this.elementMove.bindWithEvent(this,D));D.addEvent("mousemove",B);
}D.store("tip:native",D.get("title"));D.erase("title");},this);return this;},detach:function(A){$$(A).each(function(C){C.removeEvent("mouseenter",C.retrieve("tip:enter")||$empty);
C.removeEvent("mouseleave",C.retrieve("tip:leave")||$empty);C.removeEvent("mousemove",C.retrieve("tip:move")||$empty);C.eliminate("tip:enter").eliminate("tip:leave").eliminate("tip:move");
var B=C.retrieve("tip:native");if(B){C.set("title",B);}});return this;},elementEnter:function(B,A){$A(this.container.childNodes).each(Element.dispose);
var D=A.retrieve("tip:title");if(D){this.titleElement=new Element("div",{"class":"tip-title"}).inject(this.container);this.fill(this.titleElement,D);}var C=A.retrieve("tip:text");
if(C){this.textElement=new Element("div",{"class":"tip-text"}).inject(this.container);this.fill(this.textElement,C);}this.timer=$clear(this.timer);this.timer=this.show.delay(this.options.showDelay,this);
this.position((!this.options.fixed)?B:{page:A.getPosition()});},elementLeave:function(A){$clear(this.timer);this.timer=this.hide.delay(this.options.hideDelay,this);
},elementMove:function(A){this.position(A);},position:function(D){var B=window.getSize(),A=window.getScroll();var E={x:this.tip.offsetWidth,y:this.tip.offsetHeight};
var C={x:"left",y:"top"};for(var F in C){var G=D.page[F]+this.options.offsets[F];if((G+E[F]-A[F])>B[F]){G=D.page[F]-this.options.offsets[F]-E[F];}this.tip.setStyle(C[F],G);
}},fill:function(A,B){(typeof B=="string")?A.set("html",B):A.adopt(B);},show:function(){this.fireEvent("show",this.tip);},hide:function(){this.fireEvent("hide",this.tip);
}});

window.addEvent('domready', function() {
         //new SmoothScroll({ duration:700 }, window);
		 centerWindow();
         
var myTips = new Tips($$('.toolTipElement'), {
                timeOut: 900,
                maxTitleChars: 60, /*I like my captions a little long*/
                maxOpacity: .9, /*let's leave a little transparancy in there */
                offsets:{'x':10,'y':-28},
                className:'shit'    
            });		 
		 
         getToggleStatus();
        
        /*
        Sitemap Morph
        */
        
        document.sitemap_morph = new Fx.Morph('map_slider', {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
        
        document.pic_scroll_morph = new Fx.Morph('pic_scroll', {duration: '300', transition: Fx.Transitions.Sine.easeOut, onComplete:function(){
                //and here we apply the highlight effect on complete
	        if (document.online_pos!=0) {
                    $('pic_scroll').setStyle('left',document.online_pos);
                    document.online_pos=0;
                }
	}});

         $('main_forum').setStyle('opacity','1');
		 
        if ($defined($("set1"))) {
         var tabs = new SimpleTabs('set1', {
                 selector: 'h4'
         });
        }
        if ($defined($("set2"))) {
        var tabs1 = new SimpleTabs('set2', {
		selector: 'h4'
	});
        }
        if ($defined($("set3"))) {
        var tabs3 = new SimpleTabs('set3', {
		selector: 'h4'
	});		 
		}
		//At the end - display on to sidebar content
        $$('.sidebar_set').each(function(el) {
         el.setStyle('opacity','1');
         // fade
         //el.fade(1);
        });
         //fading
         //$('main_forum').fade(1);
         
		// Highend Selectioner


	//gets the selected text
	var getSelection = function() {
		return $try(
			function() { return window.getSelection(); },
			function() { return document.getSelection(); },
			function() { 
					var selection = document.selection && document.selection.createRange();
					if(selection.text) { return selection.text; }
					return false;
		      }
		) || false;
	};
	
	var paste_selection = function(sel) {
			var myselection="";
			if (sel!="") {
				myselection="[quote]"+sel+"[/quote]";
				tinyMCE.execCommand('mceFocus',false,'f_input_content');
				tinyMCE.execCommand('mceInsertContent',false, myselection);
				window.location.href="#answer";
			}
			return true;
	}

	if ($defined($('f_input_content'))) {
		$('accordion').addEvent('mouseup',function(e) {
			var selection = getSelection();
			if(selection && (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
				if (!$defined($('selection_image'))) {
					selectionImage=new Element('a',{
						opacity:0,
						href:'#answer',
						title:"Hier klicken, um den ausgewählten Text zu zitieren.",
						id:'selection_image'
					}).inject(document.body,'top');
				}
					selectionImage.setStyles({
						top: e.page.y - 30,	//offsets
						left: e.page.x - 13,
						display:'block',//offsets
						opacity:0,
						width:22,
						height:19,
						zIndex:1002,
						position:'absolute'
					})
					selectionImage.addEvent('mousedown',function() {
						paste_selection(selection);	
					});
					
					selectionImage.tween('opacity',1);
			}
			$(document.body).addEvent('mousedown',function() {
				//hider
				if(selectionImage) { selectionImage.tween('opacity',0);selection=""; }
			});		
		});
	}


//////////////////////


        // openx fix ... move invisible_ad to header_ad
        $('header_ad').grab($('invisible_ad'));
        //$$('#header_ad div.invisible_ad').set('id','moved_ad');
        $$('#header_ad div.invisible_ad').setStyle('display','block');
});

window.addEvent('resize', function() {
	centerWindow();
});

	    tinyMCE.init({
            mode : "textareas",
            language : "de",
            theme : "advanced",
            plugins : "bbcode, emotions,paste",
            theme_advanced_toolbar_location : "top",
            editor_selector : "post_textarea",
            width:'517px',
            height:'300px',
            theme_advanced_toolbar_align : "left",
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,link, unlink,sub,sup,forecolor,image, code",
            theme_advanced_buttons1_add : "emotions",
            theme_advanced_buttons2 :"",
            theme_advanced_buttons3 :"",
            force_br_newlines : true,
            remove_redundant_brs : true,
            remove_linebreaks : false,
            entity_encoding : 'raw',
			strict_loading_mode : true,
			paste_auto_cleanup_on_paste : true,
			relative_urls : false,
			remove_script_host : false,
			document_base_url : "http://recording.de",                
            forced_root_block : ''
	    });