/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
/**
*
*/
(function(jQuery) {
	jQuery.fn.extend({
		isChildOf : function(filter_string) {
			var parents = jQuery(this).parents().get();
			for (j = 0; j < parents.length; j++) {
				if (jQuery(parents[j]).is(filter_string)) {
					return true;
				}
			}
			return false;
		}
	});
})(jQuery);
/**
 * 
 * 
 * 
 * 
 */
// NAMESPACE
if (typeof  ia_tunify == 'undefined' || !ia_tunify  ){ var ia_tunify = {}; };
// CORE
ia_tunify.initialize = function(o, selector, options){
	jQuery(selector).each(
		function(){
			var c = new o( this, options );
			if (typeof c.controllerName != 'undefined'){ this[c.controllerName] = c; }
		}
	);
}
ia_tunify.merge = function(){
	var o=arguments[0], a = arguments,p;
	for(var i=1, l=a.length; i<l; i++){
		for(p in a[i]){
			o[p] = a[i][p];
		}
	}
	return o;
};
/*
 * jQuery Slideshow Plugin v1.3
 * Author: Matt Oakes
 * URL: http://www.matto1990.com/jquery/slideshow/
 *
 * Modifications by Meinhard Benn (http://benn.org/):
 *  - fadetime setting
 */
jQuery.fn.slideshow = function(options) {
	var settings = {
		fadetime: 'slow',
		timeout: '2000',
		type: 'sequence',
		pauselink: null,
		playcallback: null,
		pausecallback: null
	};
	if (options) {
		jQuery.extend(settings, options);
	}
	
	var	pauseState = 0,
		current = 1,
		last = 0,
		timer = '';
	
	var change = function () {
		if ( pauseState == 0 ) {
			for (var i = 0; i < slides.length; i++) {
				jQuery(slides[i]).css('display', 'none');
			}
			
			jQuery(slides[last]).css('display', 'block').css('zIndex', '0');
			jQuery(slides[current]).css('zIndex', '1').fadeIn(settings.fadetime);
			
			if ( settings.type == 'sequence' ) {
				if ( ( current + 1 ) < slides.length ) {
					current = current + 1;
					last = current - 1;
				}
				else {
					
					//if(jQuery.browser.version == "6.0" || jQuery.browser.version == "7.0"){
					//	current = 1;	
					//} else {
						current = 0;
					//}
					last = slides.length - 1;
				}
			}
			else if ( settings.type == 'random' ) {
				last = current;
				while (	current == last ) {
					current = Math.floor ( Math.random ( ) * ( slides.length ) );
				}
			}
			else {
				// alert('type must either be \'sequence\' or \'random\'');
			}
			timer = setTimeout(change, settings.timeout);
		}
	};
	
	var pause = function() {
		if ( pauseState == 0 ) {
			pauseState = 1;
			clearTimeout(timer);
			if ( settings.playcallback != null ) {
				settings.pausecallback(jQuery('#' + settings.pauselink));
			}
		}
		else {
			pauseState = 0;
			change();
			if ( settings.playcallback != null ) {
				settings.playcallback(jQuery('#' + settings.pauselink));
			}
		}
		return false;
	};
	
	this.css('position', 'relative');
	var slides = this.find('img').get();
	jQuery.each(slides, function(i){
		jQuery(slides[i]).css('zIndex', slides.length - i ).css('position', 'absolute').css('top', '0').css('left', '0');
	});

	if ( settings.type == 'sequence' ) {
		timer = setTimeout(change, settings.timeout);
	}
	else if ( settings.type == 'random' ) {
		do {
			current = Math.floor ( Math.random ( ) * ( slides.length ) );
		} while ( current == 0 );
		timer = setTimeout(change, settings.timeout);
	}
	else {
		// alert('type must either be \'sequence\' or \'random\'');
	}
	
	if ( settings.pauselink != null ) {
		jQuery('#' + settings.pauselink).click(pause);
	}
	
	return this;
};

// EXPAND COLLAPSE
ia_tunify.ExpandCollapse = function(elm,options){
	this.controllerName = "_expandCollapse";
	this.options = ia_tunify.merge({closeTimeout : 1200}, options);
	this.elm = jQuery(elm);
	this._initialize();
};
ia_tunify.ExpandCollapse.prototype = {
	_brc : function(o){ return (jQuery.browser.version == "6.0" || jQuery.browser.version == "7.0") && o.elm.hasClass("login"); },
	_initialize: function() {
		var _self = this;
		var t = this.elm.find(this.options.trigger);
		var b = this.elm.find(this.options.box);
		var l = this.elm.find("li:first");
		
		l.addClass("closed");
		
		this.height = b.height() + 'px';
		
		b.css('overflow', 'hidden');
		b.css('position', 'static');
		b.css('height','0px');
		
		if( _self._brc(_self) ){ b.css('visibility', 'hidden'); }

		var f = function(e){
			e.preventDefault();
			e.stopPropagation();
			if(_self.timer != 'undefined'){ clearTimeout(_self.timer); }
			if( (b.height() == 0) ){
				if( _self._brc(_self) ){ 
					b.css('visibility', ''); 
					b.css('height',_self.height);
				} else {
					b.animate({height : _self.height }, 200, "swing", 
						function(){ 
							l.addClass("open"); 
							l.removeClass("closed"); 
							
							if(jQuery(l).parents("div:first").hasClass("navLang")){ 
								$(window)._scrollable();jQuery.scrollTo("max");
							};
					});
				}

				if( _self.options.closeGlobal && _self.options.closeGlobal == true){
					jQuery("body").click( 
						function(e){
							if( ! jQuery(e.target).isChildOf( ".login" ) ){
								if( _self._brc(_self) ){ 
									b.css('visibility', 'hidden'); 
									b.css('height', '0px');
								} else {				
									b.animate({height : '0px' }, 200, "swing", function(){ l.addClass("closed"); l.removeClass("open"); });
								}
								jQuery("body").unbind("click");
							}
						}
					);
				}

			} else {
				if( _self._brc(_self) ){ 
					b.css('visibility', 'hidden'); 
					b.css('height', '0px');
				} else {				
					b.animate({height : '0px' }, 200, "swing", function(){ l.addClass("closed"); l.removeClass("open"); });
				}
			}
		};
		if(this.options.closeTimeout > 0){
			this.elm.hover(this._removeCloseTimer, this._setCloseTimer);
		}
		t.click( f );
	},
	_removeCloseTimer : function(){
		var _self = this._expandCollapse;
		clearTimeout(_self.timer);0
	},
	_setCloseTimer : function(){
		var _self = this._expandCollapse;
		var f = function(){
			var b = _self.elm.find(_self.options.box);
			var l = _self.elm.find("li:first");
			if( _self._brc(_self) ){ 
				b.css('visibility', 'hidden'); 
				b.css('height', '0px');
			} else {	
				_self.elm.find(_self.options.box).animate({height : '0px' }, 200, "swing", function(){ l.addClass("closed"); l.removeClass("open"); });
			}
		};
		_self.timer = setTimeout(f, _self.options.closeTimeout);
	}
};

ia_tunify.stopVideo = function(){
	// realy only needed for IE
	// player1 is passed in SWFobject as name and id attribute, change to whatever used...
	try{ player1.sendEvent("PLAY","false");	}catch(err){}
};

// EXPAND COLLAPSE
ia_tunify.ExpandCollapseFaq = function(elm,options){
	this.controllerName = "_expandCollapseFaq";
	this.options = ia_tunify.merge({}, options);
	this.elm = jQuery(elm);
	this._initialize();
};
ia_tunify.ExpandCollapseFaq.prototype = {
	_initialize: function() {
		var c = this.elm.parents("li:first");
		var t = c.find(".heading a:first");
		var b = this.elm;
		//
		c.addClass("close");
		b.css('display', 'none');
		//
		var f = function(e){
			e.preventDefault();
			if(c.hasClass("close")){
				c.removeClass("close");
				c.addClass("open");
				b.css('display', 'block');
			} else {
				c.removeClass("open");
				c.addClass("close");
				b.css('display', 'none');
			}
		};
		t.click( f );
	}
};
ia_tunify.stopVideo = function(){
	// realy only needed for IE
	// player1 is passed in SWFobject as name and id attribute, change to whatever used...
	try{ player1.sendEvent("PLAY","false");	}catch(err){}
};

// BOOTSTRAP
jQuery(document).ready(function(){
	ia_tunify.initialize(ia_tunify.ExpandCollapseFaq, '.exColMain');
	//
	ia_tunify.initialize(ia_tunify.ExpandCollapse, '.login' , {trigger : '.page:first' , box : '.sub:first', closeTimeout : 0, closeGlobal: true} );
	ia_tunify.initialize(ia_tunify.ExpandCollapse, '.navLang' , {trigger : '.page:first' , box : '.sub:first', closeTimeout : 0} );
	//
	if(jQuery('#slideshow .img').length > 1){
		if(jQuery.browser.version == "6.0" || jQuery.browser.version == "7.0"){
			var el = jQuery('#slideshow .img:first').clone();
			el.appendTo('#slideshow');
		}
		jQuery('#slideshow').slideshow({timeout: 4000, fadetime: 1200 });
	}
});
