var transparentImage = "images/transparent.gif";
function fixTrans(){
	if (typeof document.body.style.maxHeight == 'undefined') {
	var imgs = document.getElementsByTagName("img");
	for (i = 0; i < imgs.length; i++){	
		if (imgs[i].src.indexOf(transparentImage) != -1){
			return;
		}
		if (imgs[i].src.indexOf(".png") != -1){
				var src = imgs[i].src;
				imgs[i].src = transparentImage;
				imgs[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
			}
		} 
	}
}
if (document.all && !window.opera) attachEvent("onload", fixTrans);
function ieHover(){
	var nav = document.getElementById("centers-of-excellence-box");
	if (nav){
		var nodes = nav.getElementsByTagName("li");
		for (var i = 0; i < nodes.length; i++){
			nodes[i].onmouseover = function (){
				if (this.className.indexOf("hover") == -1){
					this.className += " hover";
				}
			}
			nodes[i].onmouseout = function (){
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}
if (window.attachEvent && !window.opera) window.attachEvent("onload", ieHover);

function _fontResize(){
	var _element = document.body;
	_default = 120;
	_curent = _default;
	_max = 200;
	_min = 50;
	_element.style.fontSize = _default + '%';
	var _step = 10;
	var _aaa = document.getElementById('aaa');
	var _btn = _aaa.getElementsByTagName('a');
	for (var j = 0; j < _btn.length; j++){
		_btn[j].onclick = function(){
			if(this.className == 'zoom_in'){
				_curent += _step;
				if(_curent > _max)
				_curent = _max;
				_element.style.fontSize = _curent + '%';
			}
			else if(this.className == 'zoom_out'){
				_curent -= _step;
				if(_curent < _min)
				_curent = _min;
				_element.style.fontSize = _curent + '%';
			}
			else{
				_element.style.fontSize = _default + '%';
				_curent = _default;
			}
		}
	}
}
if (window.addEventListener) window.addEventListener("load", _fontResize, false);
else if (window.attachEvent) window.attachEvent("onload", _fontResize);


$(document).ready(function(){
	gal1 = $('div#gallery').gallery({
		duration: 500,
		autoRotation: 8000,
		listOfSlides: 'div.inner > ul.list > li',
		switcher: 'ul#gallery-nav > li',
		effect: 'fade'
	});
	gal2 = $('div.gallery-box').gallery({
		duration: 500,
		autoRotation: 8000,
		listOfSlides: 'div.slide > ul > li',
		switcher: 'ul.swicher > li'
	});
	gal3 = $('div.tab-hold').gallery({
		duration: 500,
		autoRotation: 8000,
		listOfSlides: 'ul.gallery-top > li',
		effect: 'fade'
	});
	randomSlide();
	/*
	gal4 = $('div.gallery-holder').gallery({
		duration: 500,
		autoRotation: 8000,
		listOfSlides: 'ul.gallery-top > li',
		effect: 'fade'
	});
	*/
});
function randomSlide(){
	var _slide = $('div.gallery-holder ul.gallery-top li');
	_slide.hide();
	_slide.eq(Math.floor(Math.random()*_slide.length)).show();
}
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							for (var i = 0; i < this.tabs.length; i++)
							{
								var tab = document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1));
								if (tab)
								{
									tab.style.display = "none";
								}
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", initTabs, false);
else if (window.attachEvent && !window.opera)
	window.attachEvent("onload", initTabs);
(function($) {
	$.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 = $.extend({
				duration: 700,
				slideElement: 1,
				autoRotation: false,
				effect: false,
				listOfSlides: 'ul > li',
				switcher: false,
				disableBtn: false,
				nextBtn: 'a.link-next, a.btn-next, a.next',
				prevBtn: 'a.link-prev, a.btn-prev, a.prev',
				circle: true,
				direction: false,
				IE: false
			}, options || {});
			var _el = $(context).find(this.options.listOfSlides);
			if (this.options.effect) this.list = _el;
			else this.list = _el.parent();
			this.switcher = $(context).find(this.options.switcher);
			this.nextBtn = $(context).find(this.options.nextBtn);
			this.prevBtn = $(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.list.css({marginLeft: -(this.woh * this.active)})
				else this.list.css({marginTop: -(this.woh * this.active)})
			}
			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.disableBtn) {
				if (this.count < this.wrapHolderW) this.nextBtn.addClass(this.options.disableBtn);
				if (this.active == 0) this.prevBtn.addClass(this.options.disableBtn);
			}
			
			this.initEvent(this, this.nextBtn, this.prevBtn, true);
			this.initEvent(this, this.prevBtn, this.nextBtn, false);
			
			if (this.options.autoRotation) this.runTimer(this);
			
			if (this.options.switcher) this.initEventSwitcher(this, this.switcher);
		},
		installDirections: function(temp){
			this.wrapHolderW = Math.ceil(temp / this.woh);
			if (((this.wrapHolderW - 1) * this.woh + this.woh / 2) > temp) this.wrapHolderWwrapHolderW--;
		},
		fadeElement: function(){
			if ($.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(){
					$(this).css('opacity','auto');
				}});
			}
			if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');
			this.last = this.active;
			Cufon.refresh('.tab-hold .tabset ul li a');
		},
		scrollElement: function(){
			if (!this.options.direction) this.list.animate({marginLeft: -(this.woh * this.active)}, {queue:false, duration: this.options.duration})
			else this.list.animate({marginTop: -(this.woh * this.active)}, {queue:false, duration: this.options.duration})
			if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');
		},
		runTimer: function($this){
			if($this._t) clearTimeout($this._t);
			$this._t = setInterval(function(){
				$this.toPrepare($this, true);
			}, this.options.autoRotation);
		},
		initEventSwitcher: function($this, el){
			el.click(function(){
				$this.active = $this.switcher.index($(this));
				if($this._t) clearTimeout($this._t);
				if (!$this.options.effect) $this.scrollElement();
				else $this.fadeElement();
				if ($this.options.autoRotation) $this.runTimer($this);
				Cufon.refresh('.tab-hold .tabset ul li a');
				return false;
			});
		},
		initEvent: function($this, addEventEl, addDisClass, dir){
			addEventEl.click(function(){
				if($this._t) clearTimeout($this._t);
				if ($this.options.disableBtn &&($this.count > $this.wrapHolderW)) addDisClass.removeClass($this.options.disableBtn);
				$this.toPrepare($this, dir);
				if ($this.options.autoRotation) $this.runTimer($this);
				return false;
			});
		},
		toPrepare: function($this, side){
			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) {
						if ($this.options.disableBtn && ($this.count > $this.wrapHolderW)) $this.nextBtn.addClass($this.options.disableBtn);
					}
					else $this.active++;
				}
				else{
					if ($this.active - 1 < 0) {
						if ($this.options.disableBtn && ($this.count > $this.wrapHolderW)) $this.prevBtn.addClass($this.options.disableBtn);
					}
					else $this.active--;
				}
			};
			if ($this.active == $this.rew && side) if ($this.options.disableBtn &&($this.count > $this.wrapHolderW)) $this.nextBtn.addClass($this.options.disableBtn);
			if ($this.active == 0 && !side) if ($this.options.disableBtn &&($this.count > $this.wrapHolderW)) $this.prevBtn.addClass($this.options.disableBtn);
			if (!$this.options.effect) $this.scrollElement();
			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));

$(document).ready(function(){
	initAccordeon();
})
// multiAccordeon init
function initAccordeon() {
	$('ul.accordion').Accordeon({
		activeClass:'active',
		opener:'a.opener',
		slider:'div.slide',
		slideSpeed: 400
	});
}

// multiAccordeon plugin
jQuery.fn.Accordeon = function(_options){
	// default options
	var _options = jQuery.extend({
		activeClass:'active',
		opener:'.opener',
		slider:'.slide',
		slideSpeed: 400,
		animStart:false,
		animEnd:false,
		event:'click'
	},_options);
	
	return this.each(function(){
		// options
		
		jQuery(this).find('>li').each(function(){
		
			var _holder = jQuery(this);
			var _slideSpeed = _options.slideSpeed;
			var _activeClass = _options.activeClass;
			var _opener = jQuery('>'+_options.opener, _holder);
			var _slider = jQuery('>'+_options.slider, _holder);
			var _animStart = _options.animStart;
			var _animEnd = _options.animEnd;
			var _event = _options.event;
			
			if(_slider.length) {
				if(_holder.hasClass(_activeClass)) {_slider.show();}
				else {_slider.hide();}
				
				_opener.bind(_event,function(){
					_holder.siblings().find('li').removeClass(_activeClass);
					if(!_slider.is(':animated')) {
						if(typeof _animStart === 'function') _animStart();
						if(!_holder.hasClass(_activeClass)){
							_holder.siblings().removeClass(_activeClass).find(_options.slider).slideUp(_slideSpeed,function(){
								if(typeof _animEnd === 'function') _animEnd();
							});
							_holder.addClass(_activeClass);
							_slider.slideDown(_slideSpeed,function(){
								if(typeof _animEnd === 'function') _animEnd();
							});
						}
					}
					return false;
				});
			}
		});
	});
}
