﻿var imgs;
var divs;
var mainImg;

function initialize() {
	// get the hidden contents
	imgs = $$('#hidden_content img');
	divs = $$('#hidden_content div.csc-textpic-text');
	// Erase the div (lots of inserted divs by typo3)
	$$('#hidden_content div').each(function(el) {
		el.dispose();
	});
	mainImg = $$('#main_content_top img');
	imgtext = $('text_over_image');
	menus = $$('#sub_navigation a');
	
	var counter = 0;
	
	imgs.each(function(el){
	    el.inject($('hidden_content'));
	    divs[counter].inject($('hidden_content'));
	    el.hide();
	    divs[counter].hide();
	    counter++;
	});

	var index;
	menus.each(function(el) {
		index = menus.indexOf(el);
		if (index <= imgs.indexOf(imgs.getLast())) {
			el.addEvents( {
				mouseover : function() {
						index = menus.indexOf(this);
						mainImg.hide();
						imgtext.hide();
						imgs[index].show();
						divs[index].show();
						// console.log('mouseover');
					},
				mouseout : function() {
						index = menus.indexOf(this);
						mainImg.show();
						imgtext.show();
						imgs[index].hide()
						divs[index].hide();
						//console.log('mouseout');
					}
			});
		}
	});
	
	// A jelenlegi kep megtartasa
	/*
	if (Cookie.read('bigpic')==null) {
		Cookie.write('bigpic',  $$('#main_content_top div.csc-textpic-imagewrap').get('html'), {duration: 1/24/60*5});
	} else {
		$$('#main_content_top div.csc-textpic-imagewrap').set('html', Cookie.read('bigpic'));
	}
	 */
	if (Cookie.read('bigpic')==null) {
		Cookie.write('bigpic',  mainImg.get('src'));
	} else {
		mainImg.set('src', Cookie.read('bigpic'));
	}
}

window.addEvent('domready', function() {
	Element.implement( {
		// implement show
		show : function() {
			this.fade('in');
			this.setStyle('display', 'block');
		},
		// implement hide
		hide : function() {
			this.fade('out');
			this.setStyle('display', 'none');
		}
	});
	initialize();
});

