jQuery(function(){
	initDrop();
	jQuery('div.slides').gallery({
		autoRotation:6000,
		slideElement:1,
		listOfSlides:'div.g1-holder > ul.g1 > li',
		switcher:'div.switcher ul > li'
	});
	initTabs();
	
	if(typeof jQuery.fancybox != 'undefined'){
		jQuery('a[rel=fancy], a[rel=fancy-newsletter], a[rel=fancy-gr], .post a:has(img)').fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'easingIn'      : 'easeOutBack',
			'easingOut'     : 'easeInBack'
		});
		jQuery('a[rel=fancy-video]').click(function(){
			jQuery.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'			: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
					'wmode'				: 'transparent',
					'allowfullscreen'	: 'true'
				}
			});
			return false;
		});
	}
	
	hoverFade();
});

function initTabs() {
	jQuery('ul.parts-nav').each(function(){
		var _list = jQuery(this);
		var _links = _list.find('a.tab');

		_links.each(function() {
			var _link = jQuery(this);
			var _href = _link.attr('href');
			var _tab = jQuery(_href);

			if(_link.parent().hasClass('active')) _tab.show();
			else _tab.hide();

			_link.click(function(){
				_links.parent().filter('.active').each(function(){
					jQuery(jQuery(this).removeClass('active').find('> a.tab').attr('href')).animate({opacity:0}, 250).hide().css('opacity', 1);
					jQuery(this).find('> a.tab').css({
						backgroundColor: '#ffffff',
						color: '#666666'
					});
				});
				_link.parent().addClass('active');
				_tab.show().css('opacity', 0).animate({opacity:1}, 250);
				return false;
			});
		});
	});
}

function hoverFade(){
	jQuery('.post a.img-holder').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#bdbdbd',
			borderBottomColor:'#d6d6d6',
			borderLeftColor:'#d6d6d6',
			borderRightColor:'#d6d6d6',
			borderTopColor:'#d6d6d6'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#E0E0E0',
			borderBottomColor:'#d3d3d3',
			borderLeftColor:'#d3d3d3',
			borderRightColor:'#d3d3d3',
			borderTopColor:'#d3d3d3'
		}, {queue:false, duration:250});
	});
	jQuery('.more-articles li h4 a').mouseenter(function(){
		jQuery(this).animate({
			borderBottomColor:'#2f6cbe',
			color:'#2f6cbe'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			borderBottomColor:'#fafafa',
			color:'#686767'
		}, {queue:false, duration:250});
	});
	jQuery('.social a').mouseenter(function(){
		jQuery(this).find('strong').animate({
			borderBottomColor:'#616161'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).find('strong').animate({
			borderBottomColor:'#ffffff'
		}, {queue:false, duration:250});
	});
	jQuery('div.btn-search').mouseenter(function(){
		jQuery(this).find('span.bg-search').stop().animate({opacity:0}, {queue:false, duration:250, complete:function(){jQuery(this).hide()}});
	}).mouseleave(function(){
		jQuery(this).find('span.bg-search').show().stop().animate({opacity:1}, {queue:false, duration:250});
	});
	jQuery('.more-articles a.img-holder').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#bdbdbd',
			borderBottomColor:'#d6d6d6',
			borderLeftColor:'#d6d6d6',
			borderRightColor:'#d6d6d6',
			borderTopColor:'#d6d6d6'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#fff',
			borderBottomColor:'#d3d3d3',
			borderLeftColor:'#d3d3d3',
			borderRightColor:'#d3d3d3',
			borderTopColor:'#d3d3d3'
		}, {queue:false, duration:250});
	});
	jQuery('.article a.img-holder').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#bdbdbd',
			borderBottomColor:'#d6d6d6',
			borderLeftColor:'#d6d6d6',
			borderRightColor:'#d6d6d6',
			borderTopColor:'#d6d6d6'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#E0E0E0',
			borderBottomColor:'#d3d3d3',
			borderLeftColor:'#d3d3d3',
			borderRightColor:'#d3d3d3',
			borderTopColor:'#d3d3d3'
		}, {queue:false, duration:250});
	});
	jQuery('#footer .col a').mouseenter(function(){
		jQuery(this).animate({
			borderBottomColor:'#999999'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			borderBottomColor:'#ededed'
		}, {queue:false, duration:250});
	});
	jQuery('.parts-nav li a').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#3989c4',
			color:'#ffffff'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		if(!jQuery(this).parent().hasClass('active')){
			jQuery(this).animate({
				backgroundColor:'#ffffff',
				color:'#666666'
			}, {queue:false, duration:250});
		}
	});
	jQuery('.tags li:not(.active) a').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#3989c4'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#ffffff'
		}, {queue:false, duration:250});
	});
	jQuery('.article .footer dd a').mouseenter(function(){
		jQuery(this).animate({
			borderBottomColor:'#4b4b4b'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			borderBottomColor:'#F0F0F0'
		}, {queue:false, duration:250});
	});
	jQuery('.post .info dd a').mouseenter(function(){
		jQuery(this).animate({
			borderBottomColor:'#4b4b4b'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			borderBottomColor:'#F0F0F0'
		}, {queue:false, duration:250});
	});
	jQuery('.article h2 > a').mouseenter(function(){
		jQuery(this).animate({
			color:'#2f6cbe',
			borderBottomColor:'#2f6cbe'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			color:'#4b4b4b',
			borderBottomColor:'#fff'
		}, {queue:false, duration:250});
	});
	jQuery('.content a.read-more').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#3e80c3'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#5FA5D8'
		}, {queue:false, duration:250});
	});
	jQuery('#add-comment .read-more, .newsletter a.read-more').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#3e80c3'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#eeeeee'
		}, {queue:false, duration:250});
	});
	jQuery('.pagination li:not(.prev):not(.active):not(.next)').find(' > a').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#2881c4'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#bad6ea'
		}, {queue:false, duration:250});
	});
	jQuery('.pagination li:not(.prev):not(.active):not(.next)').mouseenter(function(){
		jQuery(this).animate({
			borderBottomColor:'#1a67a1',
			borderLeftColor:'#1a67a1',
			borderRightColor:'#1a67a1',
			borderTopColor:'#1a67a1'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			borderBottomColor:'#9ec2dc',
			borderLeftColor:'#9ec2dc',
			borderRightColor:'#9ec2dc',
			borderTopColor:'#9ec2dc'
		}, {queue:false, duration:250});
	});
	jQuery('.pagination li.prev a, .pagination li.next a').mouseenter(function(){
		jQuery(this).animate({
			backgroundColor:'#2881c4'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			backgroundColor:'#4F97CC'
		}, {queue:false, duration:250});
	});
	jQuery('.pagination li.prev, .pagination li.next').mouseenter(function(){
		jQuery(this).animate({
			borderBottomColor:'#1a67a1',
			borderLeftColor:'#1a67a1',
			borderRightColor:'#1a67a1',
			borderTopColor:'#1a67a1'
		}, {queue:false, duration:250});
	}).mouseleave(function(){
		jQuery(this).animate({
			borderBottomColor:'#4289BE',
			borderLeftColor:'#4289BE',
			borderRightColor:'#4289BE',
			borderTopColor:'#4289BE'
		}, {queue:false, duration:250});
	});
}

function initDrop(){
	jQuery('.nav-panel > ul > li').each(function(){
		var _this = jQuery(this);
		var drop = _this.find('ul.drop');
		_this.mouseenter(function(){
			drop.fadeIn(300).queue(false);
		}).mouseleave(function(){
			drop.fadeOut(300).queue(false);
		});
	});
}
(function($) {
	jQuery.fn.gallery = function(options) { return new Gallery(this.get(0), options); };
	function Gallery(context, options) { this.init(context, options); };
	Gallery.prototype = {
		options:{},
		init: function (context, options){
			this.options = jQuery.extend({
				infinite: false,								//true = infinite gallery
				duration: 700,									//duration of effect it 1000 = 1sec
				slideElement: 1,								//number of elements for a slide
				autoRotation: false,							//false = option is disabled; 1000 = 1sec
				effect: false,									//false = slide; true = fade
				listOfSlides: 'ul > li',						//elements galleries
				switcher: false,								//false = option is disabled; 'ul > li' = elements switcher
				disableBtn: false,								//false = option is disabled; 'hidden' = class adds an buttons "prev" and "next"
				nextBtn: 'a.link-next, a.btn-next, a.next',		//button "next"
				prevBtn: 'a.link-prev, a.btn-prev, a.prev',		//button "prev"
				circle: true,									//true = cyclic gallery; false = not cyclic gallery
				direction: false,								//false = horizontal; true = vertical
				event: 'click',									//event for the buttons and switcher
				IE: false,										//forced off effect it "fade" in IE
				autoHeight: false								//auto height on fade
			}, options || {});
			var _el = jQuery(context).find(this.options.listOfSlides);
			if (this.options.effect) this.list = _el;
			else this.list = _el.parent();
			this.switcher = jQuery(context).find(this.options.switcher);
			this.nextBtn = jQuery(context).find(this.options.nextBtn);
			this.prevBtn = jQuery(context).find(this.options.prevBtn);
			this.count = _el.index(_el.filter(':last'));
			
			if (this.options.switcher) this.active = this.switcher.index(this.switcher.filter('.active:eq(0)'));
			else this.active = _el.index(_el.filter('.active:eq(0)'));
			if (this.active < 0) this.active = 0;
			this.last = this.active;
			
			this.woh = _el.outerWidth(true);
			if (!this.options.direction) this.installDirections(this.list.parent().width());
			else {
				this.woh = _el.outerHeight(true);
				this.installDirections(this.list.parent().height());
			}
			
			if (!this.options.effect) {
				this.rew = this.count - this.wrapHolderW + 1;
				if (!this.options.direction) this.anim = '{marginLeft: -(this.woh * this.active)}';
				else this.anim = '{marginTop: -(this.woh * this.active)}';
				eval('this.list.css('+this.anim+')');
			}
			else {
				this.rew = this.count;
				this.list.css({opacity: 0}).removeClass('active').eq(this.active).addClass('active').css({opacity: 1}).css('opacity', 'auto');
				this.switcher.removeClass('active').eq(this.active).addClass('active');
				if(this.options.autoHeight) this.list.parent().css({height: this.list.eq(this.active).outerHeight()});
			}
			this.flag = true;
			if (this.options.infinite){
				this.count++;
				this.active += this.count;
				this.list.append(_el.clone());
				this.list.append(_el.clone());
				eval('this.list.css('+this.anim+')');
			}
			
			this.initEvent(this, this.nextBtn, true);
			this.initEvent(this, this.prevBtn, false);
			if (this.options.disableBtn) this.initDisableBtn();
			if (this.options.autoRotation) this.runTimer(this);
			if (this.options.switcher) this.initEventSwitcher(this, this.switcher);
		},
		initDisableBtn: function(){
			this.prevBtn.removeClass('prev-'+this.options.disableBtn);
			this.nextBtn.removeClass('next-'+this.options.disableBtn);
			if (this.active == 0 || this.count+1 == this.wrapHolderW) this.prevBtn.addClass('prev-'+this.options.disableBtn);
			if (this.active == 0 && this.count == 1 || this.count+1 <= this.wrapHolderW) this.nextBtn.addClass('next-'+this.options.disableBtn);
			if (this.active == this.rew) this.nextBtn.addClass('next-'+this.options.disableBtn);
		},
		installDirections: function(temp){
			this.wrapHolderW = Math.ceil(temp / this.woh);
			if (((this.wrapHolderW - 1) * this.woh + this.woh / 2) > temp) this.wrapHolderW--;
		},
		fadeElement: function(){
			if (jQuery.browser.msie && this.options.IE){
				this.list.eq(this.last).css({opacity:0});
				this.list.removeClass('active').eq(this.active).addClass('active').css({opacity:'auto'});
			}
			else{
				this.list.eq(this.last).animate({opacity:0}, {queue:false, duration: this.options.duration});
				this.list.removeClass('active').eq(this.active).addClass('active').animate({
					opacity:1
				}, {queue:false, duration: this.options.duration, complete: function(){
					jQuery(this).css('opacity','auto');
				}});
			}
			if(this.options.autoHeight) this.list.parent().animate({height: this.list.eq(this.active).outerHeight()}, {queue:false, duration: this.options.duration});
			if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');
			this.last = this.active;
		},
		scrollElement: function($this){
			if (!$this.options.infinite) eval('$this.list.animate('+$this.anim+', {queue:false, duration: $this.options.duration});');
			else eval('$this.list.animate('+$this.anim+', $this.options.duration, function(){ $this.flag = true });');
			if ($this.options.switcher) $this.switcher.removeClass('active').eq($this.active / $this.options.slideElement).addClass('active');
		},
		runTimer: function($this){
			if($this._t) clearTimeout($this._t);
			$this._t = setInterval(function(){
				if ($this.options.infinite) $this.flag = false;
				$this.toPrepare($this, true);
			}, this.options.autoRotation);
		},
		initEventSwitcher: function($this, el){
			el.bind($this.options.event, function(){
				$this.active = $this.switcher.index(jQuery(this)) * $this.options.slideElement;
				if($this._t) clearTimeout($this._t);
				if ($this.options.disableBtn) $this.initDisableBtn();
				if (!$this.options.effect) $this.scrollElement($this);
				else $this.fadeElement();
				if ($this.options.autoRotation) $this.runTimer($this);
				return false;
			});
		},
		initEvent: function($this, addEventEl, dir){
			addEventEl.bind($this.options.event, function(){
				if ($this.flag){
					if ($this.options.infinite) $this.flag = false;
					if($this._t) clearTimeout($this._t);
					$this.toPrepare($this, dir);
					if ($this.options.autoRotation) $this.runTimer($this);
				}
				return false;
			});
		},
		toPrepare: function($this, side){
			if (!$this.options.infinite){
				if (($this.active == $this.rew) && $this.options.circle && side) $this.active = -$this.options.slideElement;
				if (($this.active == 0) && $this.options.circle && !side) $this.active = $this.rew + $this.options.slideElement;
				for (var i = 0; i < $this.options.slideElement; i++){
					if (side) { if ($this.active + 1 <= $this.rew) $this.active++; }
					else { if ($this.active - 1 >= 0) $this.active--; }
				};
			}
			else{
				if ($this.active >= $this.count + $this.count && side) $this.active -= $this.count;
				if ($this.active <= $this.count-1 && !side) $this.active += $this.count;
				eval('$this.list.css('+$this.anim+')');
				if (side) $this.active += $this.options.slideElement;
				else $this.active -= $this.options.slideElement;
			}
			if (this.options.disableBtn) this.initDisableBtn();
			if (!$this.options.effect) $this.scrollElement($this);
			else $this.fadeElement();
		},
		stop: function(){
			if (this._t) clearTimeout(this._t);
		},
		play: function(){
			if (this._t) clearTimeout(this._t);
			if (this.options.autoRotation) this.runTimer(this);
		}
	}
}(jQuery));
(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);
