$(document).ready(function(){
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);	
	};
	
	$("a.toggleLink").click(function(){
		$(this).toggleClass("add");
		$(this).parent().find('.toggleArea').slideToggle(500);return false;
	});

	$('body').click(function(e)
	{
	  var _target = $(e.target);
	  
	  if (_target.is('.share'))
	  {
		 $('#share ul.shareoptions').slideToggle(400);
		 return false;
	  }
	  else
	  {
		 $('#share ul.shareoptions').slideUp(400);
	  }
	  return true;
	});
	
	$("#Comments #add_comment .genericForm").submit(function()
	{
		var _parameters = $(this).serialize();
		var _this = this;
		
		_parameters += '&ajax=1';
		
		$.ajax({type: 'POST', url: _this.action, data: _parameters, dataType: 'json', success: function(_data) 
		{
			if (_data.ok == 1)
			{
				$(_this).hide();
				$('.error_content',$(_this).closest('div')).fadeOut(0).html('<div class="comment-success">'+_data.response+'</div>').fadeIn('slow');
			}
			else
			{
				$('.error_content',$(_this).closest('div')).fadeOut(0).html('<div class="comment-waring">'+_data.response+'</div>').fadeIn('slow');
			}
		}
		});
		return false;
	});
	
	$(".deleteComment").submit(function()
	{
		var _parameters = $(this).serialize();
		var _this = this;
		
		_parameters += '&ajax=1';
		
		$.ajax({type: 'POST', url: _this.action, data: _parameters, dataType: 'json', success: function(_data) 
		{
			if (_data.ok == 1)
			{
				$(_this).parent().slideUp('slow');
			}
		}
		});
		return false;
	});
	
	$("a.toggle").click(function(){
		$(this).toggleClass("add");
		$(this).parent().parent().parent().find('.mid').slideToggle(600);return false;
	});
	
	if ($("#tbxComment").length > 0 )
	{
		$('#tbxComment').markItUp(mySettings);
	}
	
});

function show_vidinfo(div)
{
	var arr_div = new Array();
	arr_div[0] = "videoinfo1";
	arr_div[1] = "videoinfo2";
	
	for(i=0;i<arr_div.length;i++)
	{
		if(div==arr_div[i])
		{
			document.getElementById('tab_'+arr_div[i]).style.background = "url(/templates/1/images/title_btn.png) no-repeat 0 -23px";
			document.getElementById(''+arr_div[i]).style.display = "block";	
		}
		else
		{
			document.getElementById('tab_'+arr_div[i]).style.background = "url(/templates/1/images/title_btn.png) no-repeat 0 0";
			document.getElementById(''+arr_div[i]).style.display = "none";
		}	
	}
}

// Videos Pagaination
function initPagination() {
	var num_entries = $('#ItemResults div.itemList').length;
	// Create pagination element
	$("#Pagination").pagination(num_entries, {
		num_edge_entries: 2,
		num_display_entries: 8,
		callback: pageselectCallback,
		items_per_page:1
	});
 }

$(function(){
	$('#embedLink').click(function(){
		$('#embedSelect').val(ytplayer.getVideoEmbedCode());
	});
});

// * 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;
}

function SelectAll(id)
{
    document.getElementById(id).focus();
    document.getElementById(id).select();
}

// 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);
