$(document).ready(function(){
	// Widgets
	$(".colum_container").sortable({
		placeholder: "small_ui-selected",
		helper: 'clone',
		revert: true,
		containment: $("body"),
		receive: function(){$(".colum_container").css("height", "auto");},
		remove: function(){if ($(".colum_container").find("li").size() == 1) {$(".colum_container");}},
		update: function(){set_cookies();}
	});
	
	// News Accordion
	$('#news_menu').Accordion({
		header: 'h3.head',
		alwaysOpen: false,
		animated: true,
		showSpeed: 500,
		hideSpeed: 400
	});
	
	// TS Accordion
	$(".ts_menu").Accordion({
		active: 'h3.selected',
		header: 'h3.head',
		alwaysOpen: false,
		animated: true,
		showSpeed: 500,
		hideSpeed: 700
	});
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);	
	};
	
	$("#toggle_1").click(function(){
		$(this).toggleClass("add");
		$('#toggle_1info').slideToggle(500);return false;
	});
	
	$("#toggle_2").click(function(){
		$(this).toggleClass("add");
		$('#toggle_2info').slideToggle(500);return false;
	});
	
	$("#toggle_3").click(function(){
		$(this).toggleClass("add");
		$('#toggle_3info').slideToggle(500);return false;
	});
	
	$("#toggle_4").click(function(){
		$(this).toggleClass("add");
		$('#toggle_4info').slideToggle(500);return false;
	});
	
	$('body').click(function(e)
	{
	  var _target = $(e.target);
	
	  if (_target.is('.panelBtn'))
	  {
		 $('#Panel ul li ul.options').slideToggle('fast');
		 return false;
	  }
	  else
	  {
		 $('#Panel ul li ul.options').slideUp('fast');
	  }
	  return true;
	});
	
	$('#aboutMe').jScrollPane({showArrows:true,scrollbarWidth:8});
	
	$('#CommentBox').markItUp(mySettings);

});
	function set_cookies() {
	$.cookie('colum_container', $(".colum_container").sortable('serialize'), { expires: 365 , path: '/'});
}

// * li add and remover * //
function getLastVisible(bullets) {
  for(var i = 0 ; i < bullets.length ; i++) {
    if(bullets[i].style.display == "none") {
      return i - 1;
    }
  }
  return bullets.length - 1;
}

function getBullets(list_id) {
   var bullets=new Array();
   var counter=0;
   var all_bullets = document.getElementsByTagName("li");
   for(var i = 0 ; i < all_bullets.length ; i++) {
      if(all_bullets[i].parentNode.id == list_id) {
         bullets[counter] = all_bullets[i];
         counter++;
      }
   }
   return bullets;
}

function bullet(action,list_id) {
  var bullets = getBullets(list_id);
  var lastVisible = getLastVisible(bullets);
  if (action == "add") {
    if((lastVisible + 1) < bullets.length) {
      bullets[lastVisible + 1].style.display="block";
      return;
    }
  }
  else {
    if(lastVisible >= 0) {
      bullets[lastVisible].style.display="none";
      return;
    }
  }
}

/* Recruitment Form */
function change_stage(stage)
{
	document.getElementById('stage').value = stage;
	document.getElementById('stage1').style.display = (stage==1) ? 'block' : 'none';
	document.getElementById('stage2').style.display = (stage==2) ? 'block' : 'none';
	document.getElementById('stage3').style.display = (stage==3) ? 'block' : 'none';
	return false;
}

// JQuery Mouse Wheel
(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(f){var d=[].slice.call(arguments,1),g=0,e=true;f=c.event.fix(f||window.event);f.type="mousewheel";if(f.wheelDelta){g=f.wheelDelta/120}if(f.detail){g=-f.detail/3}d.unshift(f,g);return c.event.handle.apply(this,d)}})(jQuery);