// JavaScript Document

window.slider = {
	count : 0,
	init : function(){
		slider.count = $('div.autoSliderItem').length;
		slider.curIndex = 1;
		$('div#autoSlider').onImagesLoaded(function(_this){
			slider.timeOut = window.setTimeout('slider.fadeNext()', slider.timeOutTime);
		});
		$('div.autoSliderItem').each(function(i, el){
			$(el).css({'visibility':'visible'});
			if(i > 0){
				$(el).css({'visibility':'visible','display':'none'});
			}
		});
	},
	timeOut : null,
	timeOutTime : 2000,
	curIndex : 1,
	addCurIndex : function(){
		slider.curIndex = slider.curIndex + 1;
		if(slider.curIndex > slider.count-1){
			slider.curIndex = 0;
		}
	},
	fadeNext : function(){
		//Clear the Timeout:
		window.clearTimeout(slider.timeOut);
		
		var _el = $('div.autoSliderItem:eq('+slider.curIndex+')');
		_el.css({'z-index':'1'});
		var _myData = {'element': _el};
		
		slider.addCurIndex();
		var _newEl = $('div.autoSliderItem:eq('+slider.curIndex+')');
		_newEl.css({'display':'none'}).css({'z-index':'2'});
		_newEl.animate({
				opacity:'show',
				mydata : _myData
			},
			{
				duration: 4000,
				'easing':'easeInOutSine',
				complete : function(){
					this.mydata.element.css({'display':'none','z-index':1});
					slider.timeOut = window.setTimeout('slider.fadeNext()', slider.timeOutTime);
				}
			});
	}
};
jQuery.fn.onImagesLoaded = function(_cb) { 
  return this.each(function() {
 
    var $imgs = (this.tagName.toLowerCase()==='img')?$(this):$('img',this),
        _cont = this,
            i = 0,
    _done=function() {
      if( typeof _cb === 'function' ) _cb(_cont);
    };
 
    if( $imgs.length ) {
      $imgs.each(function() {
        var _img = this,
        _checki=function(e) {
          if((_img.complete) || (_img.readyState=='complete'&&e.type=='readystatechange') )
          {
            if( ++i===$imgs.length ) _done();
          }
          else if( _img.readyState === undefined ) // dont for IE
          {
            $(_img).attr('src',$(_img).attr('src')); // re-fire load event
          }
        }; // _checki \\
 
        $(_img).bind('load readystatechange', function(e){_checki(e);});
        _checki({type:'readystatechange'}); // bind to 'load' event...
      });
    } else _done();
  });
};
$(document).ready(function(){
	$('.continueButton .button a').click(function(event){
		event.stopPropagation();
		event.preventDefault();
		$('#frmLanguage').submit();
	});
	$(document).pngFix(); 
	slider.init();
	$("select#languageSelectBoxCountry").jgdDropdown({
  callback: function(obj, val) { 
   /*$('div#selectLanguage').empty().html('<img src="images/landing/ajax-loader.gif" style="margin-top:5px;" />').load('/landing_ajax.asp?country='+val, function(){
    $("select#languageSelectBoxLanguage").jgdDropdown();
   })*/;
  },
  clsLIExpand : false
 });
	$("select#languageSelectBoxLanguage").jgdDropdown({
		callback: function(obj, val) { 
			
		},
		clsLIExpand : false
	});
});
