jQuery.noConflict();

jQuery(document).ready(function(){
	oEvents.init();
	Preloader(preload);
});


var preload = ['./images/icon-favorite-act.gif', './images/event-past-slider.png', './images/icon-star-act.gif', './images/embed-act-lt.gif', './images/embed-act-rt.gif', './images/embed-act-lb.gif', './images/embed-act-rb.gif', './images/icon-evt-view2.gif', './images/icon-evt-view2-act.gif', './images/icon-evt-view1.gif', './images/icon-evt-view1-act.gif', './images/button-act-right.png', './images/button-act-left.png', './images/button-act-bg-ie.gif', './images/button-act-bg.png', './images/button-hover-right.png', './images/button-hover-left.png', './images/button-hover-bg.png', './images/button-hover-bg-ie.gif', './images/drop-top-right-bg.gif', './images/drop-top-right-bg-act.gif', './images/drop-top-left-bg.gif', './images/drop-top-left-bg-act.gif', './images/drop-top-bg.gif', './images/drop-top-bg-act.gif', './images/drop-top-arr.gif', './images/drop-top-arr-dis.gif', './images/drop-bottom-right-bg.gif', './images/drop-bottom-right-bg-act.gif', './images/drop-bottom-left-bg.gif', './images/drop-bottom-left-bg-act.gif', './images/drop-bottom-bg.gif', './images/drop-bottom-bg-act.gif', './images/drop-bottom-arr.gif', './images/drop-bottom-arr-dis.gif', './images/event-big-red-bg.png', './images/event-big-blue-bg.png', './images/event-big-disable-bg.jpg', './images/events-new-view.gif', './images/ajax-rating-blue.gif', './images/ajax-rating-red.gif'];

function Preloader(aImages){
	if(aImages.length >0){
		var img = new Image();
		img.src = aImages[0];
		img.onload = function(){
			aImages.shift();
			Preloader(aImages);
		}
	} else {
		return true;
	}
}



var oEvents = {
	aEventItems: new Array(),
	init: function(){
		this.initEventItems();
		this.oGlobal = (new Lam()).init();
	},
	initEventItems: function(){
		for (var i=0; i < this.aEventItems.length; i++) {
			this.aEventItems[i].init();
		};
	},
	append: function(sId){
		this.aEventItems.push(new evtItem(sId))
	},
	each: function(callback){
		for (var i=0; i < this.aEventItems.length; i++) {
			var b = callback.call(this.aEventItems[i], [i]);
			if(b == false) break;
		};
	},
	eachVisible: function(callback){
		for (var i=0; i < this.aEventItems.length; i++) {
			if(this.aEventItems[i].ptr.css("display") == "block"){
				var b = callback.call(this.aEventItems[i], [i]);
				if(b == false) break;
			}
		};
	},
	getPrevVisible: function(k){
		for (var i=k-1; i >= 0; i--) {
			if(this.aEventItems[i].ptr.css("display") == "block")
				return this.aEventItems[i];
		};
		return false;
	}
}


function Lam(){}
Lam.prototype = {
	init:function(){
		var _my = this;
		if(jQuery('div.inner div.events').length != 0){
			this.initEvents();
		}
		
		if(jQuery('div.search') != 0){
			new PlaceHolders();
		}
		
		// if(jQuery('div.bubble').length != 0){
		// 	setTimeout(function(){
		// 		new BubbleAnimate(jQuery(".bubble"), { width: 60, height: 30, left: jQuery(window).width()-300, top: 0 }, { width: 600, height: 300, left: 600, top: 440 });
		// 	}, 2000)
		// }
		
		if(jQuery('div.drop-menu').length != 0){
       		var cities = new Cities();
      		cities.init();
		}
		
		if(jQuery('span.codeForBlog').length != 0){
       		new CodeForBlog();
		}
		
		
		jQuery('div.button-wrapper').each(function(){
			new Button(jQuery(this));
		});
		if(jQuery('div.places').length != 0){
			var places = new Places();
			places.init();
		}
		
		if(jQuery('input.addToBlog').length != 0){
			new AddToBlog();
		}
		return this;
	},
	initEvents:function(){
		var _my = this;

		this.itemWidth = 140;

		this.events = jQuery('div.inner div.events');
		this.hideText = jQuery('#HideText');
		this.toggleView = jQuery('div.events-types-line div.icon-button div.button-block');
		this.toggleViewButton = this.toggleView.find('div.item');
		
		this.mosaicSrc = this.toggleViewButton.eq(0).find('img').attr('src');
		this.mosaicActSrc = this.mosaicSrc.replace(/.gif/, "-act.gif");
		this.listSrc = this.toggleViewButton.eq(1).find('img').attr('src');
		this.listActSrc = this.listSrc.replace(/.gif/, "-act.gif");
		
		this.toggleViewButton.click(function(){
			_my.evtToggleView(this);
		});
		
		this.evtBlocks = this.events.find('div.event-short');
		

		this.evtTypeLine = jQuery('div.events-types-line ul.events-types');
		this.evtTypeLi = this.evtTypeLine.find('li');
		this.evtTypeSpans = this.evtTypeLine.find('li span');
		this.evtTypeSpans.click(function(){
			_my.evtToggleTypes(this);
		});
		
		this.eventsHash = new Hash();
		$$('.event-short').each(function(evt){
			var t = evt.getAttribute('type');
			if(!_my.eventsHash[t]){
				_my.eventsHash[t] = new Array();
			}
			_my.eventsHash[t].push(evt.id);
		});

    	this.updateView();
	},
	updateView:function(){
		this.typesArray = new Array();
		if(jQuery.cookie('types') == null){
			for(var i=0; i<this.evtTypeLi.length; i++){
				if(i==0){
					this.evtTypeLi.eq(i).addClass('left');
				} else if(i==this.evtTypeLi.length-1){
					this.evtTypeLi.eq(i).addClass('right');
				} else {
					if(this.evtTypeLi.eq(i).is('.left')){
						this.evtTypeLi.eq(i).removeClass('left');
					} else if(this.evtTypeLi.eq(i).is('.right')){
						this.evtTypeLi.eq(i).removeClass('right');
					}
					this.evtTypeLi.eq(i).addClass('active');
				}
			}

			oEvents.each(function(){ this.ptr.show(); })
			this.showHideHead()

			for(var i=0; i<this.evtTypeSpans.length; i++){
				this.typesArray.push(this.evtTypeSpans.eq(i).attr('type'));
			}

			jQuery.cookie('evtTypes', this.typesArray.join(','), {expires:365});
			this.evtCookieStr = jQuery.cookie('evtTypes');

		} else if(jQuery.cookie('types') == 'true'){
			this.evtCookieStr = jQuery.cookie('evtTypes');
			this.typesTempArray = this.evtCookieStr.split(',');
			for(var i=0; i<this.typesTempArray.length; i++){
				for(var j=0; j<this.evtTypeSpans.length; j++){
					if(this.typesTempArray[i] == this.evtTypeSpans.eq(j).attr('type')){
						this.evtToggleTypes(this.evtTypeSpans.eq(j));
					}
				}
			}
		}
		
		switch(jQuery.cookie('view')){
			case 'mosaic':
				this.events.parents('div.inner').removeClass('toggle');
				this.toggleViewButton.eq(0).addClass('active').find('img').attr('src', this.mosaicActSrc);
				this.toggleViewButton.eq(1).removeClass('active').find('img').attr('src', this.listSrc);
				this.toggleView.addClass('l-active').removeClass('r-active');
				break;

			case 'list':
				this.events.parents('div.inner').addClass('toggle');
				this.toggleViewButton.eq(1).addClass('active').find('img').attr('src', this.listActSrc);
				this.toggleViewButton.eq(0).removeClass('active').find('img').attr('src', this.mosaicSrc);
				this.toggleView.addClass('r-active').removeClass('l-active');
				break;
		}

		oRating.each(function(){ this.update(); })

		var t = true;
		for(var i=0; i<this.evtBlocks.length; i++){
			if(this.evtBlocks.eq(i).css('display') == 'block'){
				t = false;
				break
			}
		}
		if(t){
			this.hideText.fadeIn('normal');
		}

	},
	evtToggleTypes:function(span){
		var _my = this;
		if(jQuery.cookie('types') == null){
			jQuery.cookie('types', 'true', {expires:365});
		}
		var k = null;
		var elem = jQuery(span);
		for(var j=0; j<this.evtTypeSpans.length; j++){
			if(this.evtTypeSpans.eq(j).html() == elem.html()){
				k = j;
			}
		}
		if(!elem.parents('li').is('.active')){
			elem.parents('li').addClass('active');
			this.evtSaveCookie();
			if(this.evtTypeSpans.eq(k-1).html() != null && this.evtTypeSpans.eq(k-1).parents('li').is('.active')){
				var t = k*2;
				if(this.evtTypeLi.eq(t).is('.right')){
					this.evtTypeLi.eq(t).removeClass('right');
				}
				this.evtTypeLi.eq(t).addClass('active');
			}
			if(!this.evtTypeSpans.eq(k-1).parents('li').is('.active')){
				var t = k*2;
				this.evtTypeLi.eq(t).addClass('left');
			}
			if(this.evtTypeSpans.eq(k+1).html() != null && this.evtTypeSpans.eq(k+1).parents('li').is('.active')){
				var t = k*2+2;
				if(this.evtTypeLi.eq(t).is('.left')){
					this.evtTypeLi.eq(t).removeClass('left');
				}
				this.evtTypeLi.eq(t).addClass('active');
			}
			if(!this.evtTypeSpans.eq(k+1).parents('li').is('.active')){
				var t = k*2+2;
				this.evtTypeLi.eq(t).addClass('right');
			}
			var elems = this.eventsHash[elem.attr('type')];
			if(elems){
				elems.each(function(e) { $(e).style.display = 'block'; } );
				this.showHideHead();
			} 
			var t = true;
			for(var i=0; i<this.evtBlocks.length; i++){
				if(this.evtBlocks.eq(i).css('display') == 'block'){
					t = false;
					break
				}
			}
			if(t == false){
				this.hideText.css({display:"none"});
			}
		} else if(elem.parents('li').is('.active')){
			var flag = false;
			for(var i=0; i<this.evtTypeSpans.length; i++){
				if(this.evtTypeSpans.eq(i).html() != this.evtTypeSpans.eq(k).html()){
					if(this.evtTypeSpans.eq(i).parents('li').is('.active')){
						flag = true;
					}
				}
			}
			if(flag == true){
				elem.parents('li').removeClass('active');
				this.evtSaveCookie();
				if(this.evtTypeSpans.eq(k-1).parents('li').is('.active')){
					var t = k*2;
					if(!this.evtTypeLi.eq(t).is('.right')){
						this.evtTypeLi.eq(t).addClass('right');
					}
					this.evtTypeLi.eq(t).removeClass('active');
				}
				if(!this.evtTypeSpans.eq(k-1).parents('li').is('.active')){
					var t = k*2;
					this.evtTypeLi.eq(t).removeClass('left');
				}
				if(this.evtTypeSpans.eq(k+1).parents('li').is('.active')){
					var t = k*2+2;
					if(!this.evtTypeLi.eq(t).is('.left')){
						this.evtTypeLi.eq(t).addClass('left');
					}
					this.evtTypeLi.eq(t).removeClass('active');
				}
				if(!this.evtTypeSpans.eq(k+1).parents('li').is('.active')){
					var t = k*2+2;
					this.evtTypeLi.eq(t).removeClass('right');
				}
				var elems = this.eventsHash[elem.attr('type')];
				if(elems){
					elems.each(function(e) { $(e).style.display = 'none'; } );
					this.showHideHead();
				}
				var t = true;
				for(var i=0; i<this.evtBlocks.length; i++){
					if(this.evtBlocks.eq(i).css('display') == 'block'){
						t = false;
						break
					}
				}
				if(t){
					this.hideText.fadeIn('normal');
				}
			}
		}
	},
	showHideHead:function(){
		var _my = this;
		
		oEvents.each(function(){
			this.data.h4.removeClass('first');
			this.data.h4.removeClass('h-visible');
		})

		oEvents.eachVisible(function(){
			this.data.h4.addClass('h-visible');
			this.data.h4.addClass('first');
			return false;
		})

		oEvents.eachVisible(function(i){
			var prev = oEvents.getPrevVisible(i);
			if(prev && this.data.date != prev.data.date){
				this.data.h4.addClass('h-visible');
			}
		})

	},
	evtSaveCookie:function(){
		this.typesArray = new Array();
		for(var i=0; i<this.evtTypeSpans.length; i++){
			if(this.evtTypeSpans.eq(i).parents('li').is('.active')){
				this.typesArray.push(this.evtTypeSpans.eq(i).attr('type'));
				jQuery.cookie('evtTypes', this.typesArray.join(','), {expires:365});
			}
		}
	},
	evtToggleView:function(elem){
		var elem = jQuery(elem);
		if(!elem.is('.active')){
			if(this.events.parents('.inner').is('.toggle')){
				this.events.parents('.inner').removeClass('toggle');
				this.toggleViewButton.eq(0).addClass('active').find('img').attr('src', this.mosaicActSrc);
				this.toggleViewButton.eq(1).removeClass('active').find('img').attr('src', this.listSrc);
				this.toggleView.addClass('l-active').removeClass('r-active');
				jQuery.cookie('view', 'mosaic', {expires: 365});
			} else if(!this.events.parents('.inner').is('.toggle')){
				this.events.parents('.inner').addClass('toggle');
				this.toggleViewButton.eq(1).addClass('active').find('img').attr('src', this.listActSrc);
				this.toggleViewButton.eq(0).removeClass('active').find('img').attr('src', this.mosaicSrc);
				this.toggleView.addClass('r-active').removeClass('l-active');
				jQuery.cookie('view', 'list', {expires: 365});
			}
		}
		
		oRating.each(function(){ this.update(); })
		
	}
}

function CodeForBlog(){
	this.init();
}

CodeForBlog.prototype = {
	init:function(){
		this.spans = jQuery('span.codeForBlog');
		this.spans.hover(function(){
			jQuery(this).css({textDecoration:'none'});
		}, function(){
			jQuery(this).css({textDecoration:'underline'});
		})
	}
}

function PlaceHolders(){
	this.init();
}

PlaceHolders.prototype = {
	init:function(){
		var _my = this;
		if(jQuery.browser.safari){
			jQuery('div.search').removeClass('all-browsers');
		}
		// this.searchInp = jQuery('div.search input');
		// this.arrAttr = new Array();
		// this.searchInp.each(function(i){
		// 	_my.arrAttr[i] = _my.searchInp.eq(i).attr('value');
		// 	_my.searchInp.eq(i).focus(function(){
		// 		if(_my.searchInp.eq(i).attr('value') == _my.searchInp.eq(i).attr('placeholder')){
		// 			_my.searchInp.eq(i).attr('value', '');
		// 		}
		// 	}).blur(function(){
		// 		if(_my.searchInp.eq(i).attr('value') == ''){
		// 			_my.searchInp.eq(i).attr('value', _my.arrAttr[i]);
		// 		}
		// 	})
		// });
	}
}

function AddToBlog(){
	this.init();
}

AddToBlog.prototype = {
	init:function(){
		var _my = this;
		this.inputs = jQuery('input.addToBlog');
		this.inputs.click(function(){
			jQuery(this).select();
		});
	}
}

function Places(){
	
}

Places.prototype = {
	init:function(){
		var _my = this;
		this.places = jQuery('div.places');
		this.staticBlock = this.places.find('div.static');
		this.movedBlock = this.staticBlock.find('ul.moved');
		this.movedBlockHeight = this.movedBlock.height();
		this.staticBlockHeight = (this.movedBlock.find('li').eq(0).height()+1)*this.staticBlock.attr('num')-1;
		this.staticBlock.height(this.staticBlockHeight);
		this.topArr = this.places.find('div.top');
		this.topArr.addClass('t-act')
		this.bottomArr = this.places.find('div.bottom');
		this.slowSpeed = 7;
		this.fastSpeed = 12;
		this.intTime = 30;
		this.deltaHeight = this.staticBlockHeight - this.movedBlockHeight;
		this.bottomArrWrap = this.bottomArr.find('div.wrapper');
		this.bottomArrBlock = this.bottomArr.find('div.grey-block');
		this.topArrWrap = this.topArr.find('div.wrapper');
		this.topArrBlock = this.topArr.find('div.grey-block');
		this.topLeft = this.topArr.find('img.left');
		this.topRight = this.topArr.find('img.right');
		this.bottomLeft = this.bottomArr.find('img.left');
		this.bottomRight = this.bottomArr.find('img.right');
		this.bottomArr.hover(function(){
			_my.aniScroll(_my.slowSpeed, -1);
		}, function(){
			_my.aniScroll(0, 0);
		}).mousedown(function(){
			_my.aniScroll(_my.fastSpeed, -1);
		}).mouseup(function(){
			_my.aniScroll(_my.slowSpeed, -1);
		});
		this.topArr.hover(function(){
			_my.aniScroll(_my.slowSpeed, 1);
		}, function(){
			_my.aniScroll(0, 0);
		}).mousedown(function(){
			_my.aniScroll(_my.fastSpeed, 1);
		}).mouseup(function(){
			_my.aniScroll(_my.slowSpeed, 1);
		});
	},
	aniScroll:function(speed, dir){
		var _my = this;
		var speed = speed;
		var dir = dir;
		if(dir == -1){
			_my.bottomArrWrap.css({backgroundColor:'#cacaca'});
			_my.bottomArrBlock.css({backgroundColor:'#cacaca'});
			_my.bottomLeft.attr('src', './images/embed-act-lb.gif');
			_my.bottomRight.attr('src', './images/embed-act-rb.gif');
			_my.topLeft.attr('src', './images/embed-lt.gif');
			_my.topRight.attr('src', './images/embed-rt.gif');
			_my.topArr.removeClass('t-act');
		} else if(dir == 1){
			_my.topArrWrap.css({backgroundColor:'#cacaca'});
			_my.topArrBlock.css({backgroundColor:'#cacaca'});
			_my.topLeft.attr('src', './images/embed-act-lt.gif');
			_my.topRight.attr('src', './images/embed-act-rt.gif');
			_my.bottomLeft.attr('src', './images/embed-lb.gif');
			_my.bottomRight.attr('src', './images/embed-rb.gif');
			_my.bottomArr.removeClass('b-act');
		} else {
			_my.topArrWrap.css({backgroundColor:'#eaeaea'});
			_my.bottomArrWrap.css({backgroundColor:'#eaeaea'});
			_my.topArrBlock.css({backgroundColor:'#eaeaea'});
			_my.bottomArrBlock.css({backgroundColor:'#eaeaea'});
			_my.topLeft.attr('src', './images/embed-lt.gif');
			_my.topRight.attr('src', './images/embed-rt.gif');
			_my.bottomLeft.attr('src', './images/embed-lb.gif');
			_my.bottomRight.attr('src', './images/embed-rb.gif');
		}
		clearInterval(this.aniInt);
		if(dir != 0){
			this.aniInt = setInterval(function(){
				var tempTop = parseInt(_my.movedBlock.css('top'));
				if(tempTop <=0 && tempTop >= _my.deltaHeight){
					if(tempTop+speed*dir <= 0 && tempTop+speed*dir >= _my.deltaHeight){
						_my.movedBlock.css({top:tempTop+speed*dir});
					} else if(tempTop+speed*dir < 0 + speed*dir && dir == 1){
						clearInterval(_my.aniInt);
						_my.movedBlock.css({top:0});
						_my.topArr.addClass('t-act');
					} else if(tempTop+speed*dir > _my.deltaHeight+speed*dir && dir == -1){
						clearInterval(_my.aniInt);
						_my.movedBlock.css({top:_my.deltaHeight+1});
						_my.bottomArr.addClass('b-act');
					}
				}
			}, this.intTime);
		}
	}
}


var oRating = {
	ratingQueue: new Array(),
	append:function(sId){
	  var i = 0;
		for(i=0; i<this.ratingQueue.length; i++){
			if(this.ratingQueue[i].sId == sId){
			  this.ratingQueue[i].reload();
				return;
			}
		}
    this.ratingQueue.push(new Rating(sId));
	},
	each: function(callback){
		for (var i=0; i < this.ratingQueue.length; i++) {
			var b = callback.call(this.ratingQueue[i], [i]);
			if(b == false) break;
		};
	}
}

function Rating(sId){
	this.init(sId);
}

Rating.prototype = {
	init:function(sId){
		this.sId = sId;
		this.left = 0;
		this.reload();
	},
	reload: function(){
		this.ptr = jQuery('#'+this.sId);
		this.disabled = false;
		this.is = {
			flag: false,
			clickFlag: true,
			noClick: true,
			on: false
		}
		if(this.ptr.is('.go')){
			this.is.on = true;
		}
		this.data = {
			parent: this.ptr,
			wrap: null,
			knob: {
				ptr: jQuery('#' + this.sId + ' div.knob'),
				center: 0
			},
			slider: {
				ptr: jQuery('#' + this.sId + ' div.slider'),
				center: 0
			},
			value: jQuery('#' + this.sId + ' p.value')
		};
		this.data.wrap = this.data.parent.find('div.wrap');
		this.update();
		this.events();
	},
	events: function(){
		var oThis = this;
	    this.data.knob.ptr
			.mousedown(function(){
				oThis.is.flag = true;
				oThis.is.clickFlag = true;
				return false;
	    	})
			.click(function(){
				oThis.toggleKnob();
	    	})
			.mouseup(function(evt){
				oThis.fixKnob(evt);
	    	});
	
	    jQuery(document)
			.mousemove(function(evt){
        		oThis.knobMove(evt);
			})
			.mouseup(function(){
				oThis.is.flag = false;
			});
	},
	getState: function(bool){
		if(bool)
			return { k: 34, s: -3 }
		else
			return { k: 71, s: 34 }
	},
	update: function(){
		this.data.knob.center = this.data.knob.ptr.width()/2;
		this.data.slider.center = this.data.slider.ptr.width()/2;
		this.left = this.data.wrap.offset().left;
	},
	switchParent: function(bool){
		if (this.is.on != bool && this.data.slider.ptr.attr('handler') && !this.disabled) {
		  if(bool) {
  		  this.data.value.html("<img src='./images/ajax-rating-blue.gif' alt='' />"); 		    
		  } else {
  		  this.data.value.html("<img src='./images/ajax-rating-red.gif' alt='' />");		    
		  }
		  eval(this.data.slider.ptr.attr('handler'));
		  this.disabled = true;
		}
		if(bool){
			this.data.parent.removeClass('notgo').addClass('go');
			this.is.on = true;
		} else {
			this.data.parent.removeClass('go').addClass('notgo');
			this.is.on = false;
		}
	},
	knobMove:function(evt){
	  if(this.disabled) return;
		var oThis = this;
		this.is.clickFlag = false;
		if(this.is.flag == true){
			
			var x = evt.pageX - this.left;
			var _kleft = 0;
			var _sleft = 0;
			
			if(x>50 && -x+140>51){
				_kleft = x-this.data.knob.center;
				_sleft = x-this.data.slider.center+1;
			} else if(x<=50 && -x+140>51){
				_kleft = this.getState(true).k;
				_sleft = this.getState(true).s;
				this.switchParent(true);
			} else if(x>50 && -x+140<=51){
				_kleft = this.getState(false).k;
				_sleft = this.getState(false).s;
				this.switchParent(false);
			}
			
			this.data.knob.ptr.css({left: _kleft });
			this.data.slider.ptr.css({left: _sleft });

		}
	},
	fixKnob:function(evt){
	  if(this.disabled) return;
		var oThis = this;
		
		var x = evt.pageX - this.left;
		var _kleft = 0;
		var _sleft = 0;
		var _bswidth = true;

		if(x < 140/2){
			_kleft = this.getState(true).k;
			_sleft = this.getState(true).s;
		} else {
			_kleft = this.getState(false).k;
			_sleft = this.getState(false).s;
			_bswidth = false;
		}

		this.data.knob.ptr.animate({ left: _kleft }, 100, 'linear', function(){
			oThis.switchParent(_bswidth);
		});
		this.data.slider.ptr.animate({ left: _sleft }, 100, 'linear');
		
	},
	toggleKnob:function(){
	  if(this.disabled) return;
		var oThis = this;
		
		if(this.is.clickFlag == true && this.is.noClick == true){
			this.is.noClick = false;

			var _kleft = this.getState(true).k;
			var _sleft = this.getState(true).s;
			var _bswidth = true;

			if(this.is.on){
				_kleft = this.getState(false).k;
				_sleft = this.getState(false).s;
				_bswidth = false;
			}

			this.data.knob.ptr.animate({ left: _kleft }, 200, 'linear', function(){
				oThis.switchParent(_bswidth);
				oThis.is.noClick = true;
			});
			this.data.slider.ptr.animate({ left: _sleft }, 200, 'linear');

			
		}
	}
}

function Button(elem){
	this.init(elem);
}

Button.prototype = {
	init:function(elem){
		this.button = elem;
		this.butBlock = this.button.find('div.button-block');
		if(this.button.is('.icon-button') && jQuery('div.inner div.events').length == 0){
			this.initIcons(0);
		} else if(this.button.is('.icon-button') && jQuery('div.inner div.events').length != 0){
			this.initIcons(1);
		} else if(this.button.find('div.button-ani').length != 0){
			this.initAni();
		} else if(this.button.find('div.button-switch').length != 0){
			this.initSwitch();
		} else {
			this.initStatic();
		}
	},
	initSwitch:function(){
		var _my = this;
		this.posFlag = false;
		this.firstSpanWidth = this.button.find('.in-center p span').eq(0).width();
		this.rightIcon = this.button.find('.r-icon');
		this.leftIcon = this.button.find('.l-icon');
		this.movedP = this.button.find('.in-center p');
		this.leftCorn = this.button.find('.left');
		this.rightCorn = this.button.find('.right');
		this.clickFlag = true;
		this.rightCorn.mouseover(function(){
			_my.rightHov();
		});
		this.leftCorn.mouseover(function(){
			_my.leftHov();
		});
		this.rightIcon.mouseover(function(){
			_my.rightHov();
		});
		this.leftIcon.mouseover(function(){
			_my.leftHov();
		});
		this.button.hover(function(){
			_my.button.addClass('hover');
		}, function(){
			_my.button.removeClass('hover');
		}).mousedown(function(){
			_my.butDown();
		}).mouseup(function(){
			_my.button.removeClass('l-active').removeClass('r-active');
		});
		jQuery(window).mouseup(function(){
			_my.button.removeClass('l-active').removeClass('r-active');
		});
	},
	butDown:function(){
		var _my = this;
		if(this.clickFlag == true){
			if(this.posFlag == false){
				this.button.addClass('l-active');
			} else {
				this.button.addClass('r-active');
			}
		}
	},
	leftHov:function(){
		var _my = this;
		if(_my.posFlag == true){
			this.clickFlag = false;
			_my.movedP.animate({left:0}, 300,'easeOutQuint', function(){
				_my.posFlag = false;
				_my.clickFlag = true;
			});
		}
	},
	rightHov:function(){
		var _my = this;
		if(_my.posFlag == false){
			this.clickFlag = false;
			_my.movedP.animate({left:-_my.firstSpanWidth}, 300,'easeOutQuint', function(){
				_my.posFlag = true;
				_my.clickFlag = true;
			});
		}
	},
	initStatic:function(){
		var _my = this;
		this.iconFlag = false;
		if(this.button.is('.button-small-icon')){
			this.iconFlag = true;
			this.normalSrc = this.button.find('.s-icon').attr('src');
			this.normalSrc.replace(/-act.gif/, ".gif");
			this.actSrc = this.normalSrc.replace(/.gif/, "-act.gif");
		}
		this.button.hover(function(){
			_my.button.addClass('hover');
		}, function(){
			_my.button.removeClass('hover');
		}).mousedown(function(){
			_my.button.addClass('active');
			if(_my.iconFlag == true){
				_my.button.find('.s-icon').attr('src', _my.actSrc);
			}
		}).mouseup(function(){
			_my.button.removeClass('active');
			if(_my.iconFlag == true){
				_my.button.find('.s-icon').attr('src', _my.normalSrc);
			}
		});
		jQuery(window).mouseup(function(){
			_my.button.removeClass('active');
		});
	},
	initAni:function(){
		var _my = this;
		this.allLinks = this.button.find('a');
		this.firstLink = this.allLinks.eq(0);
		this.firstLinkAttr = this.firstLink.attr('href');
		this.firstLink.attr('href', 'javascript:void(0)');
		this.lastLink = this.allLinks.eq(this.allLinks.length - 1);
		this.buttonUl = this.button.find('ul');
		this.ulWidth = this.buttonUl.width();
		this.buttonUl.width(1);
		this.startWidth = this.button.find('p span').width() + 6;
		this.buttonP = this.button.find('p');
		this.finWidth = this.buttonP.width();
		this.buttonP.width(this.startWidth);
		this.bFlag = false;
		this.button.click(function(){
			_my.button.removeClass('hover');
			setTimeout(function(){
				_my.button.find('div.icon').css({display:'none'});
			}, 200);
			_my.buttonP.animate({width:_my.finWidth}, 200, 'easeInQuad', function(){
				_my.buttonUl.animate({width:_my.ulWidth}, 600, 'easeOutQuad', function(){
					_my.firstLink.attr('href', _my.firstLinkAttr);
					_my.button.removeClass('hover');
					_my.bFlag = true;
				});
			});
		}).hover(function(){
			if(_my.bFlag == false){
				_my.button.addClass('hover');
			}
			clearTimeout(_my.aniTimeout);
		}, function(){
			_my.button.removeClass('hover');
			_my.aniTimeout = setTimeout(function(){
				_my.buttonUl.animate({width:1}, 600, 'easeInQuad', function(){
					_my.button.find('div.icon').css({display:'block'});
					_my.buttonP.animate({width:_my.startWidth}, 200, 'easeOutQuad', function(){
						_my.bFlag = false;
					});
				});
			}, 700);
		});
		this.firstLink.hover(function(){
			_my.button.find('div.button-ani').addClass('l-hover');
		}, function(){
			_my.button.find('div.button-ani').removeClass('l-hover');
		}).mousedown(function(){
			if(_my.bFlag == true){
				_my.button.find('div.button-ani').addClass('l-active');
			}
		}).mouseup(function(){
			_my.button.find('div.button-ani').removeClass('l-active').addClass('l-hover');
		});
		this.lastLink.hover(function(){
			_my.button.find('div.button-ani').addClass('r-hover');
		}, function(){
			_my.button.find('div.button-ani').removeClass('r-hover');
		}).mousedown(function(){
			_my.button.find('div.button-ani').addClass('r-active');
		}).mouseup(function(){
			_my.button.find('div.button-ani').removeClass('r-active').addClass('r-hover');
		});
		this.button.find('a').each(function(){
			jQuery(this).mousedown(function(){
				if(_my.bFlag == true){
					jQuery(this).addClass('active');
				}
			}).mouseup(function(){
				jQuery(this).removeClass('active');
			});
			jQuery(window).mouseup(function(){
				jQuery(this).removeClass('active');
			});
		});
	},
	initIcons:function(state){
		this.state = state;
		var _my = this;
		this.flag = false;
		this.items = this.button.find('div.item');
		this.normalSrc = [];
		this.actSrc = [];
		if(this.state == 0){
			for(var i=0; i<this.items.length; i++){
				this.normalSrc[i] = this.items.eq(i).find('img').attr('src');
				this.normalSrc[i].replace(/-act.gif/, ".gif");
				this.actSrc[i] = this.normalSrc[i].replace(/.gif/, "-act.gif");
			}
			if(this.button.attr('id') != undefined){
				this.blockId = this.button.attr('id');
				this.wrapper = jQuery('div.'+this.blockId);
				this.defClasses = this.wrapper.attr('class');
				this.regExp = new RegExp(_my.blockId+':([^,]+)(,?)');
				this.butCookie = jQuery.cookie('lam-button');
				this.flag = true;
				if(this.butCookie && this.butCookie.match(RegExp(_my.blockId+':')) ){
					for(var i=0; i<this.items.length; i++){
						if(this.items.eq(i).attr('type') == this.butCookie.match(this.regExp)[1]){
							this.clickIcon(this.items.eq(i));
							break
						}
					}
				} else {
					this.clickIcon(this.items.eq(0));
				}
			}
			this.items.hover(function(){
				var elem = jQuery(this);
				if(!elem.is('.active')){
					elem.addClass('hover');
					if(elem.find('.i-left').length != 0){
						_my.butBlock.addClass('l-hover');
					} else if(elem.find('.i-right').length != 0){
						_my.butBlock.addClass('r-hover');
					}
				}
			}, function(){
				var elem = jQuery(this);
				elem.removeClass('hover');
				if(elem.find('.i-left').length != 0){
					_my.butBlock.removeClass('l-hover');
				} else if(elem.find('.i-right').length != 0){
					_my.butBlock.removeClass('r-hover');
				}
			}).click(function(){
				_my.clickIcon(this);
			});
		} else {
			this.items.hover(function(){
				var elem = jQuery(this);
				if(!elem.is('.active')){
					elem.addClass('hover');
					if(elem.find('.i-left').length != 0){
						_my.butBlock.addClass('l-hover');
					} else if(elem.find('.i-right').length != 0){
						_my.butBlock.addClass('r-hover');
					}
				}
			}, function(){
				var elem = jQuery(this);
				elem.removeClass('hover');
				if(elem.find('.i-left').length != 0){
					_my.butBlock.removeClass('l-hover');
				} else if(elem.find('.i-right').length != 0){
					_my.butBlock.removeClass('r-hover');
				}
			}).click(function(){
				var elem = jQuery(this);
				elem.removeClass('hover');
			});
		}
	},
	clickIcon:function(elem){
		var _my = this;
		var elem = jQuery(elem);
		elem.removeClass('hover');
		if(_my.flag == true){
			_my.wrapper.attr('class', _my.defClasses)
			_my.wrapper.addClass(elem.attr('type'));
			if(_my.butCookie){
				if(_my.butCookie.indexOf(_my.blockId) != -1){
					jQuery.cookie('lam-button', _my.butCookie.replace(_my.regExp, _my.blockId+':'+elem.attr('type')+'$2'), {expires:365, path:'/'});
				} else {
					jQuery.cookie('lam-button', _my.butCookie+','+_my.blockId+':'+elem.attr('type'), {expires:365, path:'/'});
				}
			} else {
				jQuery.cookie('lam-button', _my.blockId+':'+elem.attr('type'), {expires:365, path:'/'});
			}
		}
		if(this.state == 0){
			_my.items.removeClass('active');
			elem.addClass('active');
			for(var i=0; i<_my.items.length; i++){
				_my.items.eq(i).find('img').attr('src', _my.normalSrc[i]);
				if(elem.html() == _my.items.eq(i).html()){
					_my.items.eq(i).find('img').attr('src', _my.actSrc[i]);
					if(i == 0){
						_my.butBlock.addClass('l-active');
						_my.butBlock.removeClass('r-active');
					} else if(i == _my.items.length-1){
						_my.butBlock.addClass('r-active');
						_my.butBlock.removeClass('l-active');
					} else {
						_my.butBlock.removeClass('r-active');
						_my.butBlock.removeClass('l-active');
					}
				}
			}
		}
	}
}

function evtItem(sId){ this.sId = sId; }
evtItem.prototype = {
	init:function(){
		this.is = {
			flag: false,
			clickFlag: true,
			noClick: true,
			on: false
		}
		this.ptr = jQuery("#" + this.sId);
		this.data = {
			parent: this.ptr.find('div.rating'),
			h4: this.ptr.find('h4'),
			date: ""
		};
		this.data.date = this.data.h4.text().match(/(\d+) (.*)/)[0];
		this.data.wrap = this.data.parent.find('div.wrap');
	}
}

function Cities(){}

Cities.prototype = {
	init:function(){
		var _my = this;
		this.cityButton = jQuery('div.content div.head h1 span');
		this.cityMenu = jQuery('div.content div.head div.drop-menu');

		this.cityTopArr = this.cityMenu.find('div.top');
		this.cityBottomArr = this.cityMenu.find('div.bottom');

		this.cityStaticBlock = this.cityMenu.find('div.cities');
		this.cityMovedBlock = this.cityStaticBlock.find('ul');
		this.cityMovedBlockHeight = this.cityMovedBlock.height();
		this.cityElems = this.cityMovedBlock.find('li');
		this.cityStaticBlockPos = this.cityStaticBlock.offset().top;
		this.cityStaticBlockHeight = this.cityStaticBlock.height();
		for(var i=0; i<this.cityElems.length; i++){
			if(this.cityElems.eq(i).is('.active')){
				this.actCity = this.cityElems.eq(i);
				i = this.cityElems.length;
			}
		}
		this.slowSpeed = 7;
		this.fastSpeed = 12;
		this.intTime = 30;
		if(this.cityElems.length <= 10){
			this.cityStaticBlock.css({height:this.cityMovedBlockHeight});
			this.cityTopArr.find('div.button').addClass('disable');
			this.cityBottomArr.find('div.button').addClass('disable');
		} else {
			this.cityStaticBlock.css({height:350});
			if(this.cityMovedBlock.offset().top >= this.cityStaticBlockPos){
				this.cityTopArr.find('div.button').addClass('disable');
			} else if(this.cityMovedBlockPos + this.cityMovedBlockHeight <= this.cityStaticBlockPos + this.cityStaticBlock.height()){
				this.cityBottomArr.find('div.button').addClass('disable');
			}
		}
		this.cityButton.click(function(){
			_my.cityMenu.css({display:'none', visibility:'visible'});
			_my.cityMenu.show('normal');
		}).mouseover(function(){
			jQuery(this).css({textDecoration:'underline'});
		}).mouseout(function(){
			jQuery(this).css({textDecoration:'none'});
		});
		this.cityMenu.mouseout(function(){
			_my.showTimeout = setTimeout(function(){
				_my.cityMenu.hide('normal');
			}, 50);
		}).mouseover(function(){
			clearTimeout(_my.showTimeout);
		});
		
		
		this.cityBottomArr.hover(function(){
			clearTimeout(_my.cityTimeout);
			_my.speedAni = _my.slowSpeed;
			_my.toggleScroll(-1);
		}, function(){
			_my.cityTimeout = setTimeout(function(){
				_my.toggleScroll(0);
			}, 50);
		}).mousedown(function(){
			_my.speedAni = _my.fastSpeed;
		});

		this.cityTopArr.mouseover(function(){
			clearTimeout(_my.cityTimeout);
			_my.speedAni = _my.slowSpeed;
			_my.toggleScroll(1);
		}).mouseout(function(){
			_my.cityTimeout = setTimeout(function(){
				_my.toggleScroll(0);
			}, 50);
		}).mousedown(function(){
			_my.speedAni = _my.fastSpeed;
		});
		
		this.movedStartPos = parseInt(this.cityMovedBlock.css('top'));
		
		jQuery(document).mouseup(function(){
			_my.speedAni = _my.slowSpeed;
		})
	},
	toggleScroll:function(d){
		var _my = this;
		var dir = d;
		if(d == 0){
			clearInterval(this.moveInt);
			this.cityBottomArr.removeClass('b-act');
			this.cityTopArr.removeClass('t-act');
		} else {
			clearInterval(this.moveInt);
			if(d == -1){
				this.cityTopArr.find('div.button').removeClass('disable');
				if(!this.cityBottomArr.find('div.button').is('.disable')){
					this.cityBottomArr.addClass('b-act');
				}
			} else if(d== 1){
				this.cityBottomArr.find('div.button').removeClass('disable');
				if(!this.cityTopArr.find('div.button').is('.disable')){
					this.cityTopArr.addClass('t-act');
				}
			}
			this.moveInt = setInterval(function(){
				_my.scrollCities(dir);
			}, this.intTime);
		}
	},
	scrollCities:function(d){
		var dir = d;
		var startPos = parseInt(this.cityMovedBlock.css('top'));
		var tempTop = startPos - this.movedStartPos;
		if(dir == 1 && startPos+this.speedAni <= 0){
			this.cityMovedBlock.css({top:tempTop + this.speedAni*dir});
		} else if(dir == -1 && startPos + this.cityMovedBlockHeight - this.speedAni > this.cityStaticBlockPos + this.cityStaticBlockHeight){
			this.cityMovedBlock.css({top:tempTop + this.speedAni*dir});
		} else if(dir == -1 && startPos + this.cityMovedBlockHeight - this.speedAni <= this.cityStaticBlockPos + this.cityStaticBlockHeight){
			clearInterval(this.moveInt);
			this.cityMovedBlock.css({top:-this.cityMovedBlockHeight+this.cityStaticBlockHeight});
			this.cityBottomArr.find('div.button').addClass('disable');
			this.cityBottomArr.removeClass('b-act');
		} else if(dir == 1 && startPos+this.speedAni >= 0){
			clearInterval(this.moveInt);
			this.cityMovedBlock.css({top:0});
			this.cityTopArr.find('div.button').addClass('disable');
			this.cityTopArr.removeClass('t-act');
		}
	}
}


	// var b = new BubbleAnimate($(".bubble"), { width: 0, height: 0, left: 400, top: 300 }, { width: 600, height: 300, left: 400, top: 300 });

function BubbleAnimate(obj, from, to){
	var oThis = this;
	if(jQuery.browser.msie){
		this.opFlag = false;
	} else {
		this.opFlag = true;
	}
	this.root = obj;
	this.content = this.root.find(".b_content");

	this.from = from;
	this.to = to;

	this.bc = this.root.find(".b_c");
	this.pt = parseInt(this.bc.css("padding-top"));
	this.pl = parseInt(this.bc.css("padding-left"));
	this.eh = this.root.find(".b_t div").height();
	this.ew = this.root.find(".b_l div").width();
	
	this.oh = this.root.find(".b_t, .b_b");
	this.ot = this.root.find(".b_r div div, .b_l");
	this.ob = this.root.find(".b_r div, .b_l div");

	this.ow = this.root.find(".b_r, .b_l");
	this.or = this.root.find(".b_t div, .b_b div");
	this.ol = this.root.find(".b_t div div, .b_b");
	
	this.calc = {
		w: this.from.width,
		h: this.from.height
	}

	this.content.css({
		width: Math.round(oThis.calc.w),
		height: Math.round(oThis.calc.h)
	});

	if(this.opFlag){
		this.root.css({
			left: this.from.left - this.root.width()/2,
			top: this.from.top - this.root.height()/2,
			opacity: 0
		})
	}else{
		this.root.css({
			left: this.from.left - this.root.width()/2,
			top: this.from.top - this.root.height()/2
		})
	}
	
	
	this.setLimit();
	
	this.oAni = new Animate(function(now, prev){
		oThis.calc = {
			w: oThis.calc.w + ((oThis.to.width-oThis.from.width)*(now-prev)),
			h: oThis.calc.h + ((oThis.to.height-oThis.from.height)*(now-prev))
		}
		oThis.content.css({
			width: Math.round(oThis.calc.w),
			height: Math.round(oThis.calc.h)
		});
		
		oThis.setLimit();
		if(oThis.opFlag){
			oThis.root.css({
				left: oThis.from.left + (oThis.to.left-oThis.from.left)*now - oThis.root.width()/2,
				top: oThis.from.top + (oThis.to.top-oThis.from.top)*now - oThis.root.height()/2,
				opacity: 1*now
			})
		} else {
			oThis.root.css({
				left: oThis.from.left + (oThis.to.left-oThis.from.left)*now - oThis.root.width()/2,
				top: oThis.from.top + (oThis.to.top-oThis.from.top)*now - oThis.root.height()/2
			})
		}
		
	}, 5000, function(){
		
	})
}
BubbleAnimate.prototype = {
	setLimit: function(){
		var t = Math.round(this.pt + this.calc.h/2);
		if(t > this.eh) t = this.eh;
		
		var l = Math.round(this.pl + this.calc.w/2);
		if(l > this.ew) l = this.ew;
		
		this.oh.css({ height: t/2+9 });
		this.ot.css({ top: t/2+1 });
		this.ob.css({ bottom: t/2+1 });

		this.ow.css({ width: l/2+9 });
		this.or.css({ right: l/2+9 });
		this.ol.css({ left: l/2+9 });
	}
}

function auto_complete_update_element_callback(element, value) {
 $A(value.getElementsByTagName('span')).each(function(element) {
   var classNames = element.className.split(' ');
   if(classNames.length == 1 && $(element.className)) {
     $(element.className).value = element.innerHTML;
   }
 });
}


