VerticalModuleController = Class.create({
	initialize : function(headings, descriptions, buttonTexts, popupTitles){
		
		this.headings = headings;
		this.descriptions = descriptions;
		this.buttonTexts = buttonTexts;
		this.popupTitles = popupTitles;
		this.pictures = new Array("images/blocks/big/vertical_bigpicture_1.jpg","images/blocks/big/vertical_bigpicture_2.jpg","images/blocks/big/vertical_bigpicture_3.jpg","images/blocks/big/vertical_bigpicture_4.jpg","images/blocks/big/vertical_bigpicture_5.jpg","images/blocks/big/vertical_bigpicture_6.jpg");

		this.mouseoverId;
		this.period = 1000;
		this.secondsBeforSwitch = 4;
		
		this.maxCount = 7;
		this.count = this.maxCount;
		this.currentId = 1;
		this.currentPictureClassId;
		this.oldId;
		this.freeze = 0;
		
		this.counter();
		
		var pointer = this;
//		this.prestarter = setTimeout(function () {pointer.prestart()}, 8000);
		
		
		
//		this.preloader = setInterval(function () {pointer.preload()}, 1000);
//		this.pic = new Image();
//		this.pic.src = "images/blocks/big/vertical_big_pictures.jpg";
		
		this.slider;
		this.slider = setInterval(function () {pointer.counter()}, this.period);
		
	},
	preload : function() {
		if(this.pic.complete) {
			clearInterval(this.preloader);
			var pointer = this;
			this.slider = setInterval(function() { pointer.counter() }, this.period);
		}
	},
	prestart : function() {
		var pointer = this;
		this.slider = setInterval(function() { pointer.counter() }, this.period);
	},
	
	counter : function() {
		
		if (this.freeze == 0) {
			if($('verticalCounter').style.display == 'none'){
				$('verticalCounter').style.display = 'none';
			}
			if(this.count != ''){
				$('verticalCounter').innerHTML = this.count;
			}
			if(this.count == this.maxCount){
				this.switchToNextPicture();
			}
			if(this.count>1){
				this.count--;
			}
			else{
				this.count=this.maxCount;
			}
		}
	},
	switchToNextPicture : function(){
		
		this.currentPictureClassId = this.currentId;
		if (this.currentId > 1) {
			this.oldId = this.currentId -1;
		} else {
			this.oldId = 6;
		}
		$('verticalButton_' + this.oldId).className = 'verticalButton inactive';

		if(this.mouseoverId != null){
			$('verticalButton_' + this.mouseoverId).className = 'verticalButton inactive';
		}
		
		$('verticalButton_' + this.currentId).className = 'verticalButton active';

		$('testImage').src = this.pictures[this.currentPictureClassId-1];
//		$('verticalBigPicture').className = 'picture_' + this.currentPictureClassId + ' noneBorder';
		//$('verticalBigPicture').className = 'noneBorder';
		$('testImage').className = 'imageLink noneBorder';
		$('verticalHeading').innerHTML = this.headings[this.currentPictureClassId-1];
		$('verticalFootnote').innerHTML = this.descriptions[this.currentPictureClassId-1];
		$('verticalBigButton').innerHTML = this.buttonTexts[this.currentPictureClassId-1];
		
		if (this.currentId < 6) {
			this.currentId++;
		} else {
			this.currentId = 1;
		}
		
	},
	mouseover : function(element){
			
		if(this.freeze == 0) {
			clearInterval(this.slider);
			this.count = '';
			$('verticalCounter').style.display = 'none';
			if (this.currentId > 1) {
				this.oldId = this.currentId -1;
			} else {
				this.oldId = 6;
			}
	
			if(this.mouseoverId != null){
				$('verticalButton_' + this.mouseoverId).className = 'verticalButton inactive';
			}
			this.mouseoverId = element.id.substring(15);
			this.currentPictureClassId = this.mouseoverId;
				
			$('verticalButton_' + this.oldId).className = 'verticalButton inactive';
	
			$('verticalButton_' + this.mouseoverId).className = 'verticalButton active';
	
			$('testImage').src = this.pictures[this.currentPictureClassId-1];
			//$('verticalBigPicture').className = 'noneBorder';
			$('testImage').className = 'imageLink noneBorder';
			$('verticalHeading').innerHTML = this.headings[this.currentPictureClassId-1];
			$('verticalFootnote').innerHTML = this.descriptions[this.currentPictureClassId-1];
			$('verticalBigButton').innerHTML = this.buttonTexts[this.currentPictureClassId-1];
		
		}
		
		
	},
	mouseoverPicture : function() {
		if (this.freeze == 0) {
			clearInterval(this.slider);
			$('testImage').src = this.pictures[this.currentPictureClassId-1];
			//$('verticalBigPicture').className = 'orangeBorder';
			$('testImage').className = 'imageLink orangeBorder';
//			$('verticalBigPicture').className = 'picture_' + this.currentPictureClassId + ' orangeBorder';
		}
	},
	mouseout : function(){
		if (this.freeze == 0) {
			if(this.count == ''){
				this.count = this.maxCount;
			}
			$('testImage').src = this.pictures[this.currentPictureClassId-1];
			//$('verticalBigPicture').className = 'noneBorder';
			$('testImage').className = 'imageLink noneBorder';
	
			var pointer = this;
			this.slider = setInterval(function() { pointer.counter() }, this.period);
		}
	},
	click : function(clickId) {
		
		
		if (this.freeze == 0) {
			id = this.currentPictureClassId;
		} else {
			id = clickId;
		}
		
		this.freeze = 1;
		clearInterval(this.slider);
		
	
		// internet popup
		if (id == 1) {
			document.getElementById('popupLoanFormDiv').style.display = 'none';
			document.getElementById('popupMobileFormDiv').style.display = 'none';
			document.getElementById('popupCreditCardFormDiv').style.display = 'none';
			
			document.getElementById('middleTop').innerHTML = this.popupTitles[id-1];
			document.getElementById('popupId').style.left = '514px';
			document.getElementById('popupId').style.top = '132px';
			document.getElementById('popupInternetFormDiv').style.display = 'block';
		}
		
		// loan popup
		if (id == 2) {
			document.getElementById('popupInternetFormDiv').style.display = 'none';
			document.getElementById('popupMobileFormDiv').style.display = 'none';
			document.getElementById('popupCreditCardFormDiv').style.display = 'none';
			
			document.getElementById('middleTop').innerHTML = this.popupTitles[id-1];
			document.getElementById('popupId').style.left = '514px';
			document.getElementById('popupId').style.top = '126px';
			document.getElementById('popupLoanFormDiv').style.display = 'block';
		}
		
		// car insurance 
		if (id == 3) {
			location.href = "komunikacyjne/wybor";
		}
		
		// mobile popup
		if (id == 4) {
			document.getElementById('popupInternetFormDiv').style.display = 'none';
			document.getElementById('popupLoanFormDiv').style.display = 'none';
			document.getElementById('popupCreditCardFormDiv').style.display = 'none';
			
			document.getElementById('middleTop').innerHTML = this.popupTitles[id-1];
			document.getElementById('popupId').style.left = '514px';
			document.getElementById('popupId').style.top = '125px';
			document.getElementById('popupMobileFormDiv').style.display = 'block';
		}
		
		// credit card popup
		if (id == 5) {
			document.getElementById('popupInternetFormDiv').style.display = 'none';
			document.getElementById('popupLoanFormDiv').style.display = 'none';
			document.getElementById('popupMobileFormDiv').style.display = 'none';
			
			document.getElementById('middleTop').innerHTML = this.popupTitles[id-1];
			document.getElementById('popupId').style.left = '514px';
			document.getElementById('popupId').style.top = '150px';
			document.getElementById('popupCreditCardFormDiv').style.display = 'block';
		}

		// property insurance
		if (id == 6) {
			location.href = "majatkowe/wybor";
		}
		
		// show popup window
		if (id != 3 && id != 6) {
			document.getElementById('popupId').style.display = 'block';
		}
		
	},
	closePopup : function() {
		if(this.count == ''){
			this.count = this.maxCount;
		}
		$('testImage').src = this.pictures[this.currentPictureClassId-1];
		//$('verticalBigPicture').className = 'noneBorder';
		$('testImage').className = 'imageLink noneBorder';
//		$('verticalBigPicture').className = 'picture_' + this.currentPictureClassId + ' noneBorder';

		var pointer = this;
		this.slider = setInterval(function() { pointer.counter() }, this.period);
		
		this.freeze = 0;
		
		document.getElementById('popupId').style.display = 'none';
	}
});