var newsSliderClass = function() {
};
newsSliderClass.prototype = {
	init : function() {
		var objThis = this;
		this.mouseOver = 1;
		this.showNews = 1;
		this.inList = 0;
		this.newsCount = $('.news').length;
		this.isList = 'n';
		this.isNewsId = 1;
		this.onClick = 0;
		$('.news_img').hide();
		$('.news_text').hide();
		$('.news_overlay').hide();
		$('.news').hide();
		$('#slide_list').hide();
		$('.news_' + this.showNews).show();
		$('.news_overlay_' + this.showNews).show();
		$('#news_' + this.showNews).show();
		$('#news_text_' + this.showNews).show();
		$('#news_' + this.showNews).css( {
			'z-index' : '2'
		});
		$('#news_text_' + this.showNews).css( {
			'z-index' : '2'
		});

		
		
		
		if (objThis.newsCount > 1 && objThis.inList == 0) {
			objThis.startSlide();
		}
		$('.news_overlay').mouseenter(function() {
			objThis.stopSlide();
		}).mouseleave(function() {
			if (objThis.newsCount > 1 && objThis.inList == 0) {
			 objThis.startSlide();
			}
		});
		if (objThis.newsCount > 1 && objThis.inList == 0) {
			$('.news_img').bind('click', function() {
				objThis.onClick = 1;
				objThis.showNext();
			});
		}
		this.bindAction();
		
		this.changeTopicNow();
		
		$('#news_1').show();
		$('#right_content_topic_end').css(
				{
					'left' : parseInt($('#right_content_topic').css('width')
							.replace("px", "")) + 10 + 'px',
					'display' : 'block'
				});
	},
	bindAction : function() {
		$('#click_to_action_overlay').bind('mouseenter', function() {
			if (objThis.mouseOver == 1) {
				objThis.bounceButton_step1();
				objThis.mouseOver = 0;
			}
		});
		var objThis = this;
		$('#click_to_action').show();
		$('#click_to_action_overlay').show();
		$('#click_to_action_overlay').css( {
			'cursor' : 'pointer'
		});
		$('#click_to_action_overlay').bind('click', function() {
			objThis.goToList();
		});
	},
	unbindAction : function() {
		$('#click_to_action').hide();
		$('#click_to_action_overlay').hide();
		$('#click_to_action_overlay').css( {
			'cursor' : 'pointer'
		});
		$('#click_to_action_overlay').unbind('click');
	},
	startSlide : function() {
		this.interval = window.setTimeout("newsSlider.showNext()", 14000);
		this.intervalBounce = window.setTimeout(
				"newsSlider.bounceButton_step1()", 4000);
	},
	stopSlide : function() {
		window.clearTimeout(this.interval);
		window.clearTimeout(this.intervalBounce);
	},
	bounceButton_step1 : function() {

		$('#click_to_action_step2').show();
		window.setTimeout("newsSlider.bounceButton_step2()", 70);
	},
	bounceButton_step2 : function() {

		$('#click_to_action_step3').show();
		window.setTimeout("newsSlider.bounceButton_step3()", 70);
	},
	bounceButton_step3 : function() {

		$('#click_to_action_step4').show();
		window.setTimeout("newsSlider.bounceButton_step4()", 70);
	},
	bounceButton_step4 : function() {

		$('#click_to_action_step4').hide();
		window.setTimeout("newsSlider.bounceButton_step5()", 70);
	},
	bounceButton_step5 : function() {

		$('#click_to_action_step3').hide();
		window.setTimeout("newsSlider.bounceButton_step6()", 70);
	},
	bounceButton_step6 : function() {
		window.setTimeout("newsSlider.bounceButton_step7()", 100);
		$('#click_to_action_step2').hide();

	},
	bounceButton_step7 : function() {
		this.mouseOver = 1;
	},
	showNext : function() {
		if (this.inList != 1) {
			this.finishedSlide();
			this.showNews++;
			if (this.showNews > this.newsCount) {
				this.showNews = 1;
			}
			$('.news_' + this.showNews).show();
			$('.news_overlay_' + this.showNews).show();
			$('#news_' + this.showNews).toggle('slide', '', 'slow');
			window.setTimeout("newsSlider.changeText()", 350);
			this.changeTopic('n', this.showNews);

			if (this.newsCount > 1 && this.inList == 0 && this.onClick == 0) {
				this.startSlide();
			} else {
				this.onClick = 0;
			}
		}
	},
	goToList : function() {
		var objThis = this;
		this.inList = 1;
		objThis.stopSlide();
		$('#slide_list').css( {
			'z-index' : '3'
		});
		this.unbindAction();
		$('#slide_list').show();
		$('.slide_listing').each(function() {
			var objThis_2 = objThis;
			$(this).bind('click', function() {
				objThis_2.backToShow($(this).attr('id').replace('list_entry_',''));
			});
		});

		this.isList = 'y';
		this.isNewsId = this.showNews;
		this.changeTopicNow();
		$('#right_content_topic').bind('click', function() {
			objThis.backToShow(0);
		});
		$('#right_content_topic').css( {
			'cursor' : 'pointer'
		});
	},
	backToShow : function(startId) {
		if (startId > 0) {
			if (startId > this.newsCount) {
				startId = 1;
			}
			this.showNews = startId;
		}

		
		$('#right_content_topic').unbind('click');
		$('#right_content_topic').css( {
			'cursor' : 'default'
		});
		$('.slide_listing').each(function() {
			$(this).unbind('click');
		});
		this.bindAction();
		this.inList = 0;

		this.finishedSlide();
		$('.news_' + this.showNews).show();
		$('.news_overlay_' + this.showNews).show();
		$('#news_' + this.showNews).show();
		$('#news_text' + this.showNews).show();
		if (this.newsCount > 1 && this.inList == 0) {
			this.startSlide();
		}
		$('#slide_list').hide();
		this.isList = 'n';
		this.isNewsId = this.showNews;
		this.changeTopicNow();
	},
	finishedSlide : function() {
		var showNews = this.showNews;
		$('.news_img').each(function() {
			if ($(this).attr('id') != 'news_' + showNews) {
				$(this).css( {
					'z-index' : '2'
				});
				$(this).hide();
			} else {
				$(this).css( {
					'z-index' : '1'
				});
				$(this).show();
			}
		});
		$('.news_text').each(function() {
			if ($(this).attr('id') != 'news_text_' + showNews) {
				$(this).css( {
					'z-index' : '2'
				});
				$(this).hide();
			} else {
				$(this).css( {
					'z-index' : '1'
				});
				$(this).show();
			}
		});
		$('.news').each(function() {
			if ($(this).attr('id') != 'news_div_' + showNews) {
				$(this).css( {
					'z-index' : '2'
				});
				$(this).hide();
			} else {
				$(this).css( {
					'z-index' : '1'
				});
				$(this).show();
			}
		});
		$('.news_overlay_').each(function() {
			if ($(this).attr('id') != 'news_div_overlay_' + showNews) {
				$(this).css( {
					'z-index' : '2'
				});
				$(this).hide();
			} else {
				$(this).css( {
					'z-index' : '1'
				});
				$(this).show();
			}
		});

	},
	changeText : function() {
		var showNews = this.showNews;
		$('.news_text').each(function() {
			if ($(this).attr('id') != 'news_text_' + showNews) {
				$(this).css( {
					'z-index' : '2'
				});
				$(this).hide();
			} else {
				$(this).css( {
					'z-index' : '1'
				});
				$(this).show();
			}
		});
	},
	changeTopic : function(list, newsId) {
		this.isList = list;
		this.isNewsId = newsId;
		window.setTimeout("newsSlider.changeTopicNow()", 280);
	},
	changeTopicNow : function() {

		$('.top_topic').hide();
		$('.sub_topic_news').hide();
		if (this.isList == 'y') {
			$('#top_topic_0').show();
			$('#sub_topic_0').show();
			$('#sub_topic_0').css( {
				'margin-left' : '28px'
			});
			$('#sub_topic_0').css( {
				'width' : '232px'
			});
		} else {
			$('#top_topic_' + this.isNewsId).show();
			$('#sub_topic_' + this.isNewsId).show();
			if ($('#space_all_sub').val() == 1) {
				$('#sub_topic_' + this.isNewsId).css( {
					'margin-left' : '18px'
				});
			} else {
				$('#sub_topic_' + this.isNewsId).css( {
					'margin-left' : '0px'
				});
			}

		}
		$('#right_content_topic_end').css(
				{
					'left' : parseInt($('#right_content_topic').css('width')
							.replace("px", "")) + 10 + 'px',
					'display' : 'block'
				});
	}

};
var newsSlider = new newsSliderClass();
$(document).ready(function() {
	newsSlider.init();
});

