var timer;
function mt(name,domain,subject,body){
	location.href = "mailto:"+name+"@"+domain+'?subject='+subject+'&body='+body;
}
$(document).ready(function(){
//	alert("a");
	$('#menue ul li').hover(function(){
		$(this).find("ul").show(100);
	},function(){
		$(this).find("ul").hide(100);
	});

    if ($("#admintoolbox").length == 0) {
        $('a.lightbox').lightBox();
    }
    
});

    function goToItem(index){
      var next = $('#content'+index);
      var contentSlider = next.parent();
      var active = contentSlider.find('.contents.active');
      var activeButton = contentSlider.find('.button.active');

      active.removeClass('active').fadeOut(400, function () {
          activeButton.removeClass('active');
          next.addClass('active').fadeIn(300);
          $('#goto'+index).addClass('active');
          contentSlider.find('.active');

      });
    }

    function nextItem(contentSlider){
      var currentId = contentSlider.find('.contents.active').attr('id').substr(7);
      var anz = contentSlider.find('.contents').size();
      var newId = 1;
      if(currentId < anz) newId = parseInt(currentId)+1;
      goToItem(newId);
    }

    function prevItem(contentSlider){
      var currentId = contentSlider.find('.contents.active').attr('id').substr(7);
      var newId = currentId-1;
      if(currentId == 0){
            newId = contentSlider.find('.contents').size();
      }
      goToItem(newId);

    }

$(document).ready(function() {
    $('.menu.dynamic ul li').hover(function() {
        $(this).children('ul').show();
    }, function(){
        $(this).children('ul').hide();
    });
    $('#contentLeft').click(function() {
        timer = 0;
        prevItem($(this).parent().parent());
    });
    $('#contentRight').click(function() {
        timer = 0;
        nextItem($(this).parent().parent());
    });

    $('img.preview').click(function () {
        var _new = $(this).attr("src");
        var _old = $("#detailImage").attr("src");

        $("#detailImage").attr("src",_new).stop(true,true).hide().fadeIn();
        $(this).attr("src",_old);
    });

    $('.slider .button').click(function () {
	  var goTo = $(this).attr('id').substr(4);
	  goToItem(goTo);
    });

    setInterval("nextItem($('.ContentSlider'))",5000);
	if($('#overlay').length > 0 && $.cookie('show_ad') != '0'){
	/*Advertise*/
	TINY.box.show($('#overlay').html(),0,0,0,1)
	$.cookie('show_ad', '0',1);
	}
    
  $('.multiSelValue').hide();
  $('.multiSelect,.multisel,.addremove').show();
  $('.multiSelect').attr('disabled','disabled');
  
 if($('.multisel').length > 0){
	$('form').find('.multisel').change(function(){
	  var name = $(this).attr('name').substring(0,$(this).attr('name').length-3),
	  match = $('[name=\''+name+'\']').val().match(','+$(this).val()+',');
	  if(match)
		$('[name=\''+name+'but\']').val('-');
	  else
		$('[name=\''+name+'but\']').val('+');

	});
	$('form').find('.addremove').click(function(){
	  var name = $(this).attr('name').substring(0,$(this).attr('name').length-3),
	  eltxt = $('[name=\''+name+'txt\']'),
	  el = $('[name=\''+name+'\']'),
	  sel1 = $('[name=\''+name+'sel\']').val(),
	  sel2 = $('[name=\''+name+'sel\'] :selected').text(),
	  add;

	  if($(this).val() == '-'){
		el.val(el.val().replace(','+sel1+',', ''));
		if(el.val().substr(-1) != ',') el.val(el.val()+',');
		if(el.val().substr(0,1) != ',') el.val(','+el.val());
		el.val(el.val().replace(',,', ''));

		eltxt.val(eltxt.val().replace(sel2, ''));
		eltxt.val(eltxt.val().replace(',,', ''));
		if(eltxt.val().substr(0,1) == ',') eltxt.val(eltxt.val().substring(1));
		if(eltxt.val().substr(-1) == ',') eltxt.val(eltxt.val().substring(0,eltxt.val().length-1));
	  }else{
		add = '';
		if(el.val() == '')el.val(',');
		if(eltxt.val() != '')add = ',';
		el.val(el.val()+sel1+',');
		eltxt.val(eltxt.val()+add+sel2);
	  }
	  $(this).parent().find('.multisel').trigger('change');
	});

  }
});




var speed = 50;
var pic, numImgs, arrLeft, i, totalWidth, n, myInterval;

$(window).load(function(){
	
        pic = $("#slider").children("div.item");
	numImgs = pic.length;
	arrLeft = new Array(numImgs);

	for (i=0;i<numImgs;i++){

		totalWidth=0;
		for(n=0;n<i;n++){
			totalWidth += $(pic[n]).width();
		}

		arrLeft[i] = totalWidth;
		$(pic[i]).css("left",totalWidth);
	}

	myInterval = setInterval("flexiScroll()",speed);
	$('#imageloader').hide();
	$(pic).show();
});

function flexiScroll(){

	for (i=0;i<numImgs;i++){
		arrLeft[i] -= 1;

		if (arrLeft[i] == -($(pic[i]).width())){
			totalWidth = 0;
			for (n=0;n<numImgs;n++){
				if (n!=i){
					totalWidth += $(pic[n]).width();
				}
			}
			arrLeft[i] = totalWidth;
		}
		$(pic[i]).css("left",arrLeft[i]);
	}
}
