$jnc = jQuery.noConflict();
/*--- faid gall function ---*/
function faidGall(){
	var _hold = $jnc('#gallery');
	if(_hold.length){
		var _list = _hold.find('.list > li');
		var btn_prev = _hold.find('span.back');
		var btn_next = _hold.find('span.next');
		btn_prev.css('opacity', 0).hide();
		btn_next.css('opacity', 0).hide();
		if(_list.length > 1){
			btn_prev.show();
			btn_next.show();
			var _a = _list.index(_list.filter('.active:eq(0)'));
			if(_a == -1) _a = 0;
			_list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1);
			_list.eq(_a).html('<img src="'+_list.eq(_a).html()+'" alt="" />');
			_list.get(_a)._f = true;
			if(_a == 0) btn_prev.hide();
			else btn_prev.show();
			if(_a == _list.length - 1) btn_next.hide();
			else btn_next.show();
			var t_x = 0;
			var btn_f1 = true;
			var btn_f2 = true;
			_hold.mouseenter(function(e){
				t_x = _hold.offset().left + _hold.width()/2;
				if(e.pageX > t_x){
					if($jnc.browser.msie) btn_next.css('opacity','auto');
					else btn_next.animate({opacity:1}, {queue:false, duration:200});
					btn_f1 = false;
				}
				else{
					if($jnc.browser.msie) btn_prev.css('opacity','auto');
					else btn_prev.animate({opacity:1}, {queue:false, duration:200});
					btn_f2 = false;
				}
			}).mousemove(function(e){
				if(e.pageX > t_x){
					if(btn_f1){
						btn_f1 = false;
						btn_f2 = true;
						if($jnc.browser.msie) btn_prev.css('opacity', 0);
						else btn_prev.animate({opacity:0}, {queue:false, duration:200});
						if($jnc.browser.msie) btn_next.css('opacity','auto');
						else btn_next.animate({opacity:1}, {queue:false, duration:200});
					}
				}
				else{
					if(btn_f2){
						btn_f2 = false;
						btn_f1 = true;
						if($jnc.browser.msie) btn_next.css('opacity', 0);
						else btn_next.animate({opacity:0}, {queue:false, duration:200});
						if($jnc.browser.msie) btn_prev.css('opacity','auto');
						else btn_prev.animate({opacity:1}, {queue:false, duration:200});
					}
				}
			}).mouseleave(function(){
				if($jnc.browser.msie){
					btn_prev.css('opacity', 0);
					btn_next.css('opacity', 0);
				}
				else{
					btn_prev.animate({opacity:0}, {queue:false, duration:200});
					btn_next.animate({opacity:0}, {queue:false, duration:200});
				}
				btn_f1 = true;
				btn_f2 = true;
			});
			btn_prev.click(function(){
				if(_a > 0) changeEl(_a - 1);
				return false;
			});
			btn_next.click(function(){
				if(_a < _list.length - 1) changeEl(_a + 1);
				return false;
			});
			var post_f = false;
			var post_hold = $jnc('div.gallery-post:eq(0)');
			if(post_hold.length){
				post_f = true;
				var _link = post_hold.find('div.headline a');
				var post_nav = post_hold.find('div.image > a');
				_link.attr('href', post_nav.eq(_a).attr('href'));
				post_nav.click(function(){
					changeEl(post_nav.index(this));
					return false;
				});
			}
		}
		var gall_f = true;
		function changeEl(_ind){
			if(gall_f && _ind != _a){
				gall_f = false;
				if(_list.get(_ind)._f){
					_list.removeClass('active').animate({opacity:0}, {queue:false, duration:800});
					_list.eq(_ind).addClass('active').animate({opacity:1}, {queue:false, duration:800});
					gall_f = true;
				}
				else{
					_list.eq(_ind).html('<img src="'+_list.eq(_ind).html()+'" alt="" />');
					_list.get(_ind)._f = true;
					setTimeout(function(){
						_list.removeClass('active').animate({opacity:0}, {queue:false, duration:800});
						_list.eq(_ind).addClass('active').animate({opacity:1}, {queue:false, duration:800});
						gall_f = true;
					}, 500);
				}
				_list.eq(_ind).addClass('active').animate({opacity:1}, {queue:false, duration:800});
				if(post_f){
					_link.attr('href', post_nav.eq(_ind).attr('href'));
					$jnc(window).scrollTop(_hold.offset().top - 30);
				}
				_a = _ind;
				if(_ind == 0) btn_prev.hide();
				else btn_prev.show();
				if(_ind == _list.length - 1) btn_next.hide();
				else btn_next.show();
			}
		}
	}
}
/*--- ---*/
function gall2(){
	var _hold = $jnc('#gallery-in');
	if(_hold.length){
		_hold.find('.list > li').html('<img src="'+_hold.find('.list > li').html()+'" alt="" />');
		var btn_prev = _hold.find('span.back-post').css('opacity', 0);
		var btn_next = _hold.find('span.next-post').css('opacity', 0);
		var t_x = 0;
		var btn_f1 = true;
		var btn_f2 = true;
		_hold.mouseenter(function(e){
			t_x = _hold.offset().left + _hold.width()/2;
			if(e.pageX > t_x){
				if($jnc.browser.msie) btn_next.css('opacity','auto');
				else btn_next.animate({opacity:1}, {queue:false, duration:200});
				btn_f1 = false;
			}
			else{
				if($jnc.browser.msie) btn_prev.css('opacity','auto');
				else btn_prev.animate({opacity:1}, {queue:false, duration:200});
				btn_f2 = false;
			}
		}).mousemove(function(e){
			if(e.pageX > t_x){
				if(btn_f1){
					btn_f1 = false;
					btn_f2 = true;
					if($jnc.browser.msie) btn_prev.css('opacity', 0);
					else btn_prev.animate({opacity:0}, {queue:false, duration:200});
					if($jnc.browser.msie) btn_next.css('opacity','auto');
					else btn_next.animate({opacity:1}, {queue:false, duration:200});
				}
			}
			else{
				if(btn_f2){
					btn_f2 = false;
					btn_f1 = true;
					if($jnc.browser.msie) btn_next.css('opacity', 0);
					else btn_next.animate({opacity:0}, {queue:false, duration:200});
					if($jnc.browser.msie) btn_prev.css('opacity','auto');
					else btn_prev.animate({opacity:1}, {queue:false, duration:200});
				}
			}
		}).mouseleave(function(){
			if($jnc.browser.msie){
				btn_prev.css('opacity', 0);
				btn_next.css('opacity', 0);
			}
			else{
				btn_prev.animate({opacity:0}, {queue:false, duration:200});
				btn_next.animate({opacity:0}, {queue:false, duration:200});
			}
			btn_f1 = true;
			btn_f2 = true;
		});
	}
}
/*--- accordion function ---*/
function initAccordion(){
	$jnc('.accordion-holder').each(function(){
		var _list = $jnc(this).children();
		var _a = _list.index(_list.filter('.open:eq(0)'));
		_list.each(function(_i){
			var _el = $jnc(this);
			_el.removeClass('open');
			this._btn = _el.children('.headline');
			this._box = _el.children('.slide').hide();
			if(_i == _a){
				this._box.show();
				_el.addClass('open');
			}
			this._btn.click(function(){
				if(_a != -1){
					_list.eq(_a).removeClass('open');
					_list.get(_a)._box.stop().animate({height: 0}, 400, function(){
						$jnc(this).css({display: 'none', height: 'auto'});
					});
				}
				if(_a != _i){
					_list.eq(_i).addClass('open');
					if(!_list.get(_i)._box.is(':animated')){
						_list.get(_i)._box.show();
						_list.get(_i)._h = _list.get(_i)._box.height();
						_list.get(_i)._box.height(0);
					}
					_list.get(_i)._box.stop().animate({ height: _list.get(_i)._h}, 400, function(){
						$jnc(this).height('auto');
					});
					_a = _i;
				}
				else{
					_a = -1;
				}
				return false;
			});
		});
	});
}
/*--- slide box function ---*/
function slideBox(){
	$jnc('div.comments').each(function(){
		var _f = false;
		var _btn = $jnc(this).find('.show-all a:eq(0)');
		var _box = $jnc(this).find('div.hide');
		var _text = _btn.html();
		var _h;
		_btn.click(function(){
			if(_f){
				_f = false;
				this.innerHTML = _text;
				_box.stop().animate({ height: 0}, 400, function(){ $jnc(this).css({display:'none', height: 'auto'});});
			}
			else{
				_f = true;
				this.innerHTML = 'Hide';
				if(!_box.is(':animated')){
					_box.show();
					_h = _box.height();
					_box.height(0);
				}
				_box.stop().animate({ height: _h}, 400, function(){ $jnc(this).height('auto');});
			}
			return false;
		});
	});
}
$jnc(document).ready(function(){
	initAccordion();
	faidGall();
	slideBox();
	gall2();
});