jQuery.fn.treeCheck = function() {
    return this.each(function() {
		$(this).click(function(){
			var classTo = $(this).attr("class");
			$checks = $(this).parents("li").eq(0).find("li input[@type=checkbox]." + classTo) ;
			if ( $(this).attr("checked") == true || $(this).attr("checked") == "checked" )
			{
				$checks.attr("checked",true) ;
			} else {
				$checks.attr("checked","") ;
			}
			return true;
		});
    });
};

jQuery.fn.treeSelect = function( containerElement , callBackElement ) {
    return this.each(function() {
		$(this).click(function(){
			if ( $(this).hasClass("selected") )
			{
				$(this).removeClass("selected") ;
				$(callBackElement).attr("value","");
			} else {
				$(containerElement).find("a.selected").removeClass("selected");
				$(this).addClass("selected")
				$(callBackElement).attr("value",$(this).attr("rel"));
			}
			return false ;
		});
    });
};
jQuery.fn.treeEdit = function( containerElement , callBackElement, nameElement ) {
    return this.each(function() {
		$(this).click(function(){
			if ( $(this).hasClass("selected") )
			{
				$(this).removeClass("selected") ;
				$(callBackElement).attr("value","");
				$(nameElement).attr("value","");
			} else {
				$(containerElement).find("a.selected").removeClass("selected");
				$(this).addClass("selected")
				$(callBackElement).attr("value",$(this).attr("rel"));
				$(nameElement).attr("value",$(this).html());
			}
			return false ;
		});
    });
};
jQuery(function(){
	$("#ruleSelector input[@type=checkbox]").treeCheck();
	$("#catSelector a").treeSelect( "#catSelector" , "#catSelector_input" );
	/* $("#catSelectorEdit a").treeEdit( "#catSelectorEdit" , "#catSelector_input", "#catSelector_input_name" ); */
	jQuery("a.confirm").click(function(){
		if ( confirm($(this).attr("title")) ) window.location = $(this).attr("href");
		else return false;
	});

	//$("select.rating").rating();
});


function writeBookMark( title, description )
{
	var p_url = window.location.href;
	var p_title = title ;
	var p_description = description
/**
	if (document.all && !window.opera){ //IE5+
	    document.write("<a href="javascript:window.external.AddFavorite('javascript:void(_search=open('" + p_url + "','_search'))', '" + p_title + "')">" + p_description + "</a>");
	} else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')){ //Gecko
	     document.write("<a href="javascript:window.sidebar.addPanel ('" + p_title + "', '" + p_url + "','');" title="" + p_title + "">" + p_description + "</a>");
	} else {
	   document.write("<a href="" + p_url + "" title="" + p_title + "" rel="sidebar">" + p_description + "</a>");
	}
*/
}
// JavaScript Document
/*************************************************
Star Rating System
First Version: 21 November, 2006
Second Version: 17 May, 2007
Author: Ritesh Agrawal (http://php.scripts.psu.edu/rja171/widgets/rating.php)
Inspiration: Will Stuckey's star rating system (http://sandbox.wilstuckey.com/jquery-ratings/)
Half-Star Addition: Karl Swedberg
Demonstration: http://examples.learningjquery.com/rating/
Usage: $('#rating').rating('url-to-post.php', {maxvalue:5, curvalue:0});

arguments
url : required -- post changes to
options
  increment : 1, // value to increment by
	maxvalue: number of stars
	curvalue: number of selected stars


************************************************/

jQuery.fn.rating = function(callback, options) {

	if(callback == null) return;

	var settings = {
    callback : callback, // post changes to
    increment : 1, // value to increment by
    maxvalue  : 5,   // max number of stars
    curvalue  : 0    // number of selected stars
  };

  if(options) {
    jQuery.extend(settings, options);
  };
  jQuery.extend(settings, {cancel: (settings.maxvalue > 1) ? true : false});


  var container = jQuery(this);

	jQuery.extend(container, {
    averageRating: settings.curvalue,
    callback: settings.callback
  });

  for ( var i = 1 ; i <= 5 ; i++ )
  {
  	container.append("<a rel='"+i+"' class='off votes'>&nbsp;</a>") ;
  }
  container.find("a").mouseover(function(){
		$(this).addClass("on");
  }).mouseout(function(){
		$(this).removeClass("on");
  }).click(function(){
		$(this).removeClass("on");
		settings.callback($(this).attr("rel"));
  });

};

jQuery.log = function () {}

$(function(){
 $('#MultipleFileUpload').MultiFile({
  accept:'pdf', max:3, STRING: {
   remove:'Entfernen',
   selected:'Datei: $file',
   denied:'Die Erweiterung $ext ist nicht erlaubt'
  }
 });
 var pageCount = 0 ;
 var currentPage = 1 ;
 if ( (pageCount = $(".bodytext .page").length) > 0 )
 {
	 $('div.bodytext').before(
		'<a id="topPager" class="imgLink" name="topPager">&nbsp;</a><div id="pageNavTop"><a style="display : none" class="back" href="">vorherige Seite</a> <a class="forward" href="">n&auml;chste Seite</a></div>'
	 );
	 $('div.bodytext').after(
		'<div id="pageNavBottom"><a  style="display : none"  class="back" href="">vorherige Seite</a> <a class="forward" href="">n&auml;chste Seite</a></div>'
	 );
	 $('#pageNavTop a.back, #pageNavBottom a.back').click(function(){
	 	jQuery.scrollTo(0);
	 	var d = $("div.bodytext div.page").eq(currentPage-1);
		d.css( 'display','none');
		var d = $("div.bodytext div.page").eq(currentPage-2);
		d.css( 'display','block');
		currentPage-- ;
		if ( currentPage == 1 ) $("#pageNavTop a.back, #pageNavBottom a.back").hide();
		if ( currentPage < pageCount+1 ) $('#pageNavTop a.forward, #pageNavBottom a.forward').show();
		return false;
	 });
	 $('#pageNavTop a.forward, #pageNavBottom a.forward').click(function(e){
		var d = $("div.bodytext div.page").eq(currentPage-1);
	 	jQuery.scrollTo(0);
		d.css( 'display','none');
		var d = $("div.bodytext div.page").eq(currentPage);
		d.css( 'display','block');
		currentPage++ ;
		if ( currentPage == pageCount ) $('#pageNavTop a.forward, #pageNavBottom a.forward').hide();
		if ( currentPage > 1 ) $('#pageNavTop a.back, #pageNavBottom a.back').show();
		return false;
	 });
	 $('div.bodytext div.page').css({display : 'none'}) ;
	 $('div.bodytext div.page:first').css({display : 'block'});
 }
});


/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Date: 2/19/2008
 * @author Ariel Flesler
 * @version 1.3.3
 */
;(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
;(function($){var g=location.href.replace(/#.*/,''),a=$.localScroll=function(a){$('body').localScroll(a)};a.defaults={duration:1e3,axis:'y',event:'click',stop:true};a.hash=function(b){b=$.extend({},a.defaults,b);b.hash=false;if(location.hash)setTimeout(function(){scroll(0,location,b)},0)};$.fn.localScroll=function(b){b=$.extend({},a.defaults,b);return(b.persistent||b.lazy)?this.bind(b.event,function(e){var a=e.target;a=$([a,a.parentNode]).filter(filter)[0];a&&scroll(e,a,b)}):this.find('a').filter(filter).bind(b.event,function(e){scroll(e,this,b)}).end().end();function filter(){var c=this;return!!c.href&&!!c.hash&&c.href.replace(c.hash,'')==g&&(!b.filter||$(c).is(b.filter))}};function scroll(e,a,c){var d=a.hash.slice(1),b=document.getElementById(d)||document.getElementsByName(d)[0];if(b){e&&e.preventDefault();var f=$(c.target||$.scrollTo.window());if(c.lock&&f.is(':animated'))return;if(c.onBefore)c.onBefore.call(a,e,b,f);if(c.stop)f.queue('fx',[]).stop();f.scrollTo(b,c);if(c.hash)f.queue(function(){location=a.hash})}}})(jQuery);
