var PAPASTAMKOS = {
	builtMainMenu : function() {
		var flashvars = {};
		var flashvars2 = {};
		var links = $$('#mainMenuContainer a');
		links.each(function(item,index){
			flashvars2['linkTEXT_'+index] = flashvars['linkTEXT_'+index] = item.innerHTML.replace(/&amp;/g,'%26').replace(/&/g,'%26');
			flashvars2['linkHREF_'+index] = flashvars['linkHREF_'+index] = item.href.replace(/&amp;/g,'%26').replace(/&/g,'%26');
			if(item.className == 'active'){
				flashvars2.activeLink = flashvars.activeLink = index;
			}			
		});
		flashvars2.linksTOTAL = flashvars.linksTOTAL =  links.length;
		flashvars.isMainMenu = 'true';
		swfobject.embedSWF("swf/mainMenu.swf", "mainMenu", "100%", "100%", "8.0.0","swf/expressInstall.swf", flashvars, {wmode:'transparent'}, {});	
		flashvars2.c1 = '0xbababa';
		flashvars2.c2 = '0x71c3ce';
		flashvars2.isMainMenu = 'false';
		swfobject.embedSWF("swf/mainMenu.swf", "footerMenu", "100%", "100%", "8.0.0","swf/expressInstall.swf", flashvars2, {wmode:'transparent'}, {});
		swfobject.embedSWF("swf/clock1.swf", "clock1", "46", "40", "8.0.0","swf/expressInstall.swf", {}, {wmode:'transparent'}, {});
	},
	mainSWF : function() {
		if($('mainSWF')){
			var flashvars = {
				xmlURL : 'main.xml'
			};
			swfobject.embedSWF("swf/mainSWF.swf", "mainSWF", "100%", "100%", "8.0.0","swf/expressInstall.swf", flashvars, {wmode:'transparent'}, {});	
		}
	},
	titleSWF : function() {
		var colors = {
			color1 : {c1:'0x565656',c2 : '0x121212',c3 : '0xff9a4b',c4 : '0xea6e0e'},
			color2 : {c1:'0xffffff',c2 : '0xc9c9c9',c3 : '0xff9a4b',c4 : '0xea6e0e'},
			color3 : {c1:'0xffffff',c2 : '0xd9d9d9',c3 : '0xff9a4b',c4 : '0xea6e0e'}
		};
		$$('.titleSWF').each(function(item,index){
			var id = 'titleSWF_'+index;
			var newSWFtitleElem = new Element('div', {'id': id});
			var newSWFtitle = item.innerHTML.replace(/%/g,'%25').replace(/&amp;/g,'%26').replace(/&/g,'%26');
			item.innerHTML = '';
			item.appendChild(newSWFtitleElem,'bottom');
			var classes = item.className.split(' ');
			var colObj = colors.color1;
			if(classes.length>1){
				if(colors[classes[1]]){
					colObj = colors[classes[1]];
				}
			}
			var flashvars = {
				c1 : colObj.c1,
				c2 : colObj.c2,
				c3 : colObj.c3,
				c4 : colObj.c4,
				innerHTML : newSWFtitle,
				s : item.getStyle('font-size').toInt(),
				tp : item.getStyle('top').toInt(),
				lft : item.getStyle('left').toInt(),
				algn : item.hasClass('center') ? 'center' : 'left'
			};
			item.setStyle('top',0);
			item.setStyle('left',0);
			item.setStyle('text-indent',0);
			if(item.href){
				flashvars.href = item.href;
			}
			swfobject.embedSWF("swf/titleSWF.swf", id, "100%", item.getStyle('height').toInt(), "8.0.0","swf/expressInstall.swf", flashvars, {wmode:'transparent'}, {});

		});	
	},
	builtScrollers : function(){
		$$('.scrollable').each(function(item,index){
			var mask = item.getElement('.mask');
			var movable = item.getElement('.movable');
			var h1 = movable.getStyle('height').toInt();
			var h2 = mask.getStyle('height').toInt();
			item.pos = 0;
			item.maxPos = Math.floor(h1/h2) + Math.ceil(h1%h2/h1) - 1;
			if(item.maxPos > 0){
				item.move =  h2;
				item.tween = new Fx.Tween(movable,{
					link : 'cancel',
					duration: 800,
					transition: 'expo:in:out'
				});
				item.tween.start('top',0);	
				item.moveDown = item.getElement('.moveDown');
				item.moveUp =  item.getElement('.moveUp');
				item.moveDown.setStyle('display','block');
				item.moveUp.setStyle('display','block');
				item.moveDown.name = 'moveDown';
				item.moveUp.name = 'moveUp';
				item.moveUp.addClass('moveUpDisabled');
				item.moveDown.parent = item.moveUp.parent = item;
				item.moveDown.onmouseover = item.moveUp.onmouseover = function(){
					if(!this.hasClass(this.name+'Disabled')){
						this.addClass(this.name+'Hover');
					}
				}
				item.moveDown.onmouseout = item.moveUp.onmouseout = function(){
					this.removeClass(this.name+'Hover');
				}
				item.moveUp.onclick = function(){
					if(this.parent.pos > 0){
						this.parent.pos--;
						this.parent.tween.start('top',-this.parent.pos*this.parent.move);
						this.parent.moveDown.removeClass('moveDownDisabled');
						if(this.parent.pos == 0){
							this.addClass('moveUpDisabled');
						}
					}
				}
				item.moveDown.onclick = function(){
					if(this.parent.pos < this.parent.maxPos){
						this.parent.pos++;
						this.parent.tween.start('top',-this.parent.pos*this.parent.move);
						this.parent.moveUp.removeClass('moveUpDisabled');
						if(this.parent.pos == this.parent.maxPos){
							this.addClass('moveDownDisabled');
						}
					}
				}
			}
		});
	},
	builtArticleTitle : function(){
		var item = $('articleTitle');
		if(item){
			var colors = {
				color1 : {c1:'0x565656',c2 : '0x121212',c3 : '0xff9a4b',c4 : '0xea6e0e'},
				color2 : {c1:'0xffffff',c2 : '0xc9c9c9',c3 : '0xff9a4b',c4 : '0xea6e0e'}
			};
			var newSWFtitle = item.innerHTML.replace(/%/g,'%25').replace(/&amp;/g,'%26').replace(/&/g,'%26');;
			var classes = item.className.split(' ');
			var colObj = colors.color1;
			if(classes.length>1){;
				if(colors[classes[1]]){
					colObj = colors[classes[1]];
				}
			}
			var flashvars = {
				c1 : colObj.c1,
				c2 : colObj.c2,
				c3 : colObj.c3,
				c4 : colObj.c4,
				innerHTML : newSWFtitle,
				s : item.getStyle('font-size').toInt(),
				tp : item.getStyle('top').toInt(),
				lft : item.getStyle('left').toInt()
			};
			item.setStyle('top',0);
			item.setStyle('left',0);
			if(item.href){
				flashvars.href = item.href;
			}
			var newHeight = (item.getStyle('height').toInt()/28)*30;
			swfobject.embedSWF('swf/articleTitle.swf', 'articleTitle', "100%", newHeight, '8.0.0', 'swf/expressInstall.swf', flashvars, {wmode:'transparent'}, {});
		}
	},
	builtAutoEraseFields : function(){
		var autoEraseFields = $$('input.autoEraseMe','textarea.autoEraseMe');
		autoEraseFields.each(function(item,index){
			item.defaultValue = item.value;
			item.onclick = item.onfocus =  function(){
				if(this.value == this.defaultValue){
					this.value = "";
				}
				else{
					this.select();
				}
			}
			item.onblur = function(){
				if(this.value == ""){
					this.value = this.defaultValue;
				}
			}
		});
	},
	builtEpikerotita : function(){
		var epik = $('epikerotita');
		if(epik){
			var items = epik.getElements('div.item');
			var navigation = epik.getElement('div.navigation');
			var movable = epik.getElement('div.movable');
			var isMoving = false;
			var buttons = new Array();
			var dummy;
			var epikerotitaNextElemnt = null;
			var isPaused = false;
			epikerotitaTween = new Fx.Tween(movable,{
				link : 'cancel',
				duration: 1000,
				transition: 'expo:in:out',
				onComplete: function(tweenElement){
					if(epikerotitaNextElemnt){
						epikerotitaCurrentItem.setStyle('display','none');
						epikerotitaCurrentItem = epikerotitaNextElemnt;
						tweenElement.setStyle('top', 0);
						if(epikerotitaCurrentItem == items[0]){
							items[0].setStyle('visibility','visible');
						}
						if(dummy){
							movable.setStyle('top',0);
							dummy.dispose();
						}
						isMoving = false;
					}
				}
			});
			epikerotitaTween.start('top', 0);
			function goTo(trgt,a){
				$clear(periodos);
				var theCase = false;
				var theOtherCase = false;
				trgt.setStyle('display','block');
				if(a == 'next' && trgt.index == 0){
					dummy = items[0].clone().inject(movable);
					trgt.setStyle('visibility','hidden');
					movable.setStyle('top','-380px');
					theCase = true;
				}
				if(a == 'previous' && trgt.index == items.length-1){
					dummy = items[items.length-1].clone().inject(movable, 'top');
					theOtherCase = true;
				}

				if((trgt.index > epikerotitaCurrentItem.index || theCase) && !theOtherCase){
					if(theCase){
					epikerotitaTween.start('top',-760);		
					}
					else{
					epikerotitaTween.start('top',-380);	
					}
				}
				else{
					epikerotitaTween.set('top',-380);
					epikerotitaTween.start('top',0);	
				}
				epikerotitaNextElemnt = trgt;
				isMoving = true;
				if(!isPaused){
					periodos = autoRotation.periodical(7000);
				}
			}
			function goNext(){
				if(!isMoving){
					var idx = epikerotitaCurrentItem.index + 1;
					if(idx == buttons.length){
						idx = 0;
					}
					buttons[idx].fireEvent('click', 'next');
				}		
			}
			function goPrevious(){
				if(!isMoving){
					var idx = epikerotitaCurrentItem.index - 1;
					if(idx == -1){
						idx = buttons.length-1;
					}
					buttons[idx].fireEvent('click', 'previous');
				}	
			} 
			items.each(function(item,index){
				item.index = index;
				var theTitle = item.getElement('h1 a');
				if(theTitle){
					var flashvars = {
						innerHTML : theTitle.innerHTML.replace(/%/g,'%25').replace(/&amp;/g,'%26').replace(/&/g,'%26'),
						href : theTitle.href.replace(/%/g,'%25').replace(/&amp;/g,'%26').replace(/&/g,'%26')
					}
					theTitle.id = 'epikerotita_title_'+index;
					swfobject.embedSWF('swf/epikertotitaTitle.swf', theTitle.id, "270", "141", '8.0.0', 'swf/expressInstall.swf', flashvars, {wmode:'transparent'}, {});									
					item.getElement('h1').setStyle('visibility','visible');
					var newAnchor = new Element('div', {
						 'html': '0'+(index+1),
						 'events': {
							  'click': function(a){
								  if(!isMoving && !this.hasClass('selected')){
									  goTo(this.trgt,!a?0:a);
									  navigation.getElement('div.selected').removeClass('selected');
									  this.className = 'selected';
								  }
							  },
							  'mouseenter': function(){
									this.addClass('hover');
							  },
							  'mouseleave': function(){
									this.removeClass('hover');  
							  }
						 }
					});
					if(index){
						item.setStyle('display', 'none');	
					}
					else{
						epikerotitaCurrentItem = item;
						newAnchor.className = 'selected';
					}
					newAnchor.trgt = item;
					newAnchor.inject(navigation);
					buttons.push(newAnchor);
				}
			});
			
			if(items.length > 1){
				var previousAnchor = new Element('div', {
					 'html': '&lsaquo;',
					 'events': {
						  'click': goPrevious,
						  'mouseenter': function(){
								this.addClass('hover');
						  },
						  'mouseleave': function(){
								this.removeClass('hover');  
						  }
					 }
				});
				var nextAnchor = new Element('div', {
					 'html': '&rsaquo;',
					 'events': {
						  'click': goNext,
						  'mouseenter': function(){
								this.addClass('hover');
						  },
						  'mouseleave': function(){
								this.removeClass('hover');  
						  }
					 }
				});
				var pauseAnchor = new Element('div', {
					 'html': 'pause',
					 'class': 'pause',
					 'events': {
						  'click': function(){
								if(!isPaused){
									$clear(periodos);
									isPaused = true;
									this.set('text', 'play');
								}
								else{
									isPaused = false;
									this.set('text', 'pause');
									goNext();	
								}
						  },
						  'mouseenter': function(){
								this.addClass('hover');
						  },
						  'mouseleave': function(){
								this.removeClass('hover');  
						  }
					 }
				});
				previousAnchor.inject(navigation, 'top');
				nextAnchor.inject(navigation);
				pauseAnchor.inject(navigation);
			}
			function autoRotation(){
				if(!isMoving){
					goNext();
				}
			}
			var periodos = autoRotation.periodical(7000);
		}
	},
	builtAritclesListTitles : function(){
		var artList = $('artList');
		if(artList){
			var titles = artList.getElements('h1 a');
			titles.each(function(item,index){
				var flashvars = {
					innerHTML : item.innerHTML.replace(/%/g,'%25').replace(/&amp;/g,'%26').replace(/&/g,'%26'),
					href : item.href.replace(/%/g,'%25').replace(/&amp;/g,'%26').replace(/&/g,'%26')
				}
				item.id = 'artlist_title_'+index;
				swfobject.embedSWF('swf/articleListTitle.swf', item.id, "307", "142", '8.0.0', 'swf/expressInstall.swf', flashvars, {wmode:'transparent'}, {});									
				item.setStyle('visibility','visible');
			});
		}
	},
	bookmark : function(title,url){
		if (window.sidebar){
			window.sidebar.addPanel(title, url, "");
		}
		else if(window.opera && window.print){
			var a = document.createElement('a');
			a.setAttribute('href',url);
			a.setAttribute('title',title);
			a.setAttribute('rel','sidebar');
			a.click();
		} 
		else if(document.all){
			window.external.AddFavorite(url, title);
		}
	},
	incFontSize : function(id){
		var e = $(id);
		if(e){
			var crnSize = e.getStyle('font-size').toInt();
			if(crnSize < 16){
				e.setStyle('font-size', crnSize+1);
			}
		}
	},
	decFontSize : function(id){
		var e = $(id);
		if(e){
			var crnSize = e.getStyle('font-size').toInt();
			if(crnSize > 10){
				e.setStyle('font-size', crnSize-1);
			}
		}
	},
	horizontalScroller : function(obj){
		var scroller = $(obj.id);
		
		var items = scroller.getElements('.imgHolder');
		scroller.totalWidth = items.length*(items[0].getStyle('margin-right').toInt()+items[0].getStyle('width').toInt())-items[0].getStyle('width').toInt();
		var mask = scroller.getElement('.mask');
		scroller.movable = scroller.getElement('.movable');
		scroller.maskWidth = mask.getStyle('width').toInt();
		scroller.pos = 0;
		scroller.maxPos = Math.floor(scroller.totalWidth / scroller.maskWidth) + Math.ceil(scroller.totalWidth % scroller.maskWidth / scroller.totalWidth) - 1;
		scroller.movePrevious =  scroller.getElement('.previousArrow').getElement('div');
		scroller.moveNext = scroller.getElement('.nextArrow').getElement('div');
		scroller.moveNext.parent = scroller.movePrevious.parent = scroller;
		scroller.move =  560;
		
		if(scroller.maxPos > 0){
			scroller.moveNext.addClass('active');
			scroller.tween = new Fx.Tween(scroller.movable,{
				link : 'cancel',
				duration: 1000,
				transition: 'expo:in:out'
			});
			scroller.tween.start('left',0);
			scroller.movePrevious.onmouseover = scroller.moveNext.onmouseover = function(){
				if(this.hasClass('active')){
					this.addClass('hover');
				}
			}
			scroller.movePrevious.onmouseout = scroller.moveNext.onmouseout = function(){
				this.removeClass('hover');
			}	
			scroller.movePrevious.onclick = function(){
				if(this.parent.pos > 0){
					scroller.moveNext.addClass('active');
					this.parent.pos--;
					this.parent.tween.start('left',-this.parent.pos*this.parent.move);
					if(this.parent.pos == 0){
						this.className = 'disabled';
					}
				}
			}
			scroller.moveNext.onclick = function(){
				if(this.parent.pos < this.parent.maxPos){
					scroller.movePrevious.addClass('active');
					this.parent.pos++;
					this.parent.tween.start('left',-this.parent.pos*this.parent.move);
					if(this.parent.pos == this.parent.maxPos){
						this.className = 'disabled';
					}
				}
			}
		}
	
	},
	builtNextPreviousItems : function(){
		$$('div.serialMove').each(function(container, index){
			var movable = container.getElement('div.movable');
			var nextButton = container.getElement('div.next');
			var previousButton = container.getElement('div.previous');
			if(nextButton && previousButton && movable){
				var items = movable.getElements('div.item');
				container.maxPos = items.length - 1;
				if(container.maxPos > 0){
					container.curPos = 0;
					container.move = container.getStyle('width').toInt();
					container.isMoving = false;
					container.tween = new Fx.Tween(movable,{
						link : 'cancel',
						duration: 800,
						transition: 'expo:in:out',
						onComplete: function(){
							container.previousItem.setStyle('display', 'none').setStyle('float', 'left');
							items[container.curPos].setStyle('float', 'left');
							movable.setStyle('left', 0);
							container.isMoving = false;
						}
					});
					container.tween.set('left', 0);
					items.each(function(item,index){
						if(index > 0){
							item.setStyle('display', 'none');	
						}
					});
					nextButton.addEvents({
						'click': function(){
							if(!container.isMoving){
								container.isMoving = true;
								container.previousItem = items[container.curPos];
								container.curPos++;
								if(container.curPos > container.maxPos){
									container.curPos = 0;
									items[container.curPos].setStyle('float', 'right');
								}
								items[container.curPos].setStyle('display', 'block')
								container.tween.start('left', 0, -container.move);
							}
						}
					});
					previousButton.addEvents({
						'click': function(){
							if(!container.isMoving){
								container.isMoving = true;
								container.previousItem = items[container.curPos];
								container.curPos--;
								if(container.curPos < 0){
									container.curPos = container.maxPos;
									container.previousItem.setStyle('float', 'right');
								}
								items[container.curPos].setStyle('display', 'block')
								container.tween.set('left', -container.move);
								container.tween.start('left', -container.move, 0);
							}
						}
					});
				}
			}
		});
	},
	builtPromoBoxes: function() {
		$$('div.promoTitle').each(function(item, index){
			var id = 'promoTitle' + index;
			var newSWF = new Element('div', {'id': id});
			var newSWFtitles = item.innerHTML.replace(/%/g,'%25').replace(/&amp;/g,'%26').replace(/&/g,'%26').split('/');;
			item.innerHTML = '';
			var flashvars = {
				title1: newSWFtitles[0],
				title2: newSWFtitles[1]
			}
			item.appendChild(newSWF,'bottom');
			swfobject.embedSWF("swf/promoBoxTitle.swf", id, "100%", "100%", "8.0.0","swf/expressInstall.swf", flashvars, {wmode:'transparent'}, {});	
			item.setStyle('text-indent', 0);
		});
	}
}
window.addEvent('domready', function(){
	PAPASTAMKOS.builtMainMenu();
	var mySlider;
	var tmp = $('homePromoBoxes');
	if(tmp){
		mySlider = new EternalSlider('homePromoBoxes',{
			elementsType: 'div',
			elementsClass: 'promoBox',
			itemsSpread: 520,
			duration: 800,
			itemMoveButtonClass: 'moveButton',
			offsetLeft: $('siteOffsetLeft').offsetLeft -6,
			previousButton: 'previousHomePromo',
			nextButton: 'nextHomePromo',
			itemOnShow: function(item, slider){
				var rightSide = item.getElement('div.rightSide');
				if(rightSide){
					var tween1 = new Fx.Tween(item.getElement('div.content'),{
						link : 'cancel',
						duration: 800,
						transition: 'quad:out',
						fps: 100
					});
					var tween2 = new Fx.Tween(item.getElement('div.rightSide'),{
						link : 'cancel',
						duration: 800,
						transition: 'quad:out',
						fps: 100,
						onComplete: function(){
							slider.isMoving = false;	
						}
					});
					tween1.start('width', 224, 428);
					tween2.start('left', 200, 0);
				}
				else{
					slider.isMoving = false;
				}
			},
			itemOnHide: function(item, slider){
				var rightSide = item.getElement('div.rightSide');
				if(rightSide){
					var tween1 = new Fx.Tween(item.getElement('div.content'),{
						link : 'cancel',
						duration: 500,
						transition: 'expo:in:out',
						onComplete: function(){
							slider.goMove();	
						}
					});
					var tween2 = new Fx.Tween(item.getElement('div.rightSide'),{
						link : 'cancel',
						duration: 500,
						transition: 'expo:in:out'
	
					});
					tween1.start('width', 428, 224);
					tween2.start('left', 0, 200);
				}
				else{
					slider.goMove();	
				}
			}
		});
		tmp.setStyle('left', 0);
	}
	PAPASTAMKOS.builtPromoBoxes();
	PAPASTAMKOS.mainSWF();
	PAPASTAMKOS.titleSWF();
	PAPASTAMKOS.builtScrollers();
	PAPASTAMKOS.builtArticleTitle();
	PAPASTAMKOS.builtAutoEraseFields();
	PAPASTAMKOS.builtEpikerotita();
	PAPASTAMKOS.builtAritclesListTitles();
	PAPASTAMKOS.builtNextPreviousItems();
});
	
