// JavaScript Document

var Global = {
	
	  init: function(){
			
			  // _blank targets 
				$$('a._blank').each(function(element){
						element.onclick = function(event){
							  event = new Event(event);
								event.preventDefault();
								window.open(element.getProperty('href'));
						}
				});
				
				// block link
				var linkBlocks = $$('.link-block, .make-clickable');
				if (linkBlocks){
					linkBlocks.each(function(element){
					  element.addEvent('click', function(event){
						  event = new Event(event);
							event.preventDefault();
							window.location = this.getElement('a').getProperty('href');
						});
						element.setStyle('cursor', 'pointer');
					});
				}
							
		}
};

var Products = {
	 
	  init: function(){
			
		  	$$('.product-item').each(function(element){
						element.setStyle('cursor', 'pointer');
				    element.onclick = function(event){
							  event = new Event(event);
								event.preventDefault();
								window.location = this.getElement('a').getProperty('href');
						}
						if (window.ie6) {
							  element.addEvent('mouseenter', function(){
										this.setStyles({
											  'border' : '1px solid #B6CDE1',
												'padding' : '14px 15px 0px 10px'
									  });
								});
								
								element.addEvent('mouseleave', function(){
										this.setStyles({
											  'border' : 'none',
												'padding' : '15px 16px 1px 11px'
									  });
								});
						}
			  });
		}
};

var Dock = {
	  
		init: function(){

				var collection = $$('#dock ul a');
				collection.each(function(element, index){
				    var fx = new Fx.Style(element,'opacity', { duration: 200, wait: false });
						var bubble = element.getElement('span');
						var bubbleFx = new Fx.Style(bubble, 'opacity', { duration: 50, wait: false });
						bubbleFx.set(0);
						bubble.setStyle('display','block');
						if (index != 5) fx.set(0.5);
						
						element.addEvent('mouseenter', function(){
					      if (index != 5) fx.start(1);
								bubbleFx.start(1);
						});
						element.addEvent('mouseleave', function(){
						    if (index != 5) fx.start(0.5);
								bubbleFx.start(0);
					  });
			  });
		}
};

var Video = {
	
	  init: function(){
			  
				var collection = $$('.video-item a.play');
				var divs = $$('.video-item div');
				collection.each(function(element, index){
						var divId = divs[index].getProperty('id').replace('flash-','');
				    element.addEvent('click', function(event){
						    event = new Event(event);
								event.preventDefault();
								var so = new SWFObject(divId+'.swf', 'flash-'+divId, '280', '210', '8.0.23', '', true);
                so.addParam('wmode','transparent');
		            so.write('flash-'+divId);
						});
				});
				
				var collection = $$('.video-item img');
				var divs = $$('.video-item div');
				collection.each(function(element, index){
						var divId = divs[index].getProperty('id').replace('flash-','');
				    element.addEvent('click', function(event){
						    event = new Event(event);
								event.preventDefault();
								var so = new SWFObject(divId+'.swf', 'flash-'+divId, '280', '210', '8.0.23', '', true);
                so.addParam('wmode','transparent');
		            so.write('flash-'+divId);
						});
				});
		}
};

window.addEvent('domready', function(){

  if (!$('page-homepage')) Global.init();
	
	if ($$('.product-item')) { Products.init(); }
	if ($('dock')) { Dock.init(); }
	
	if ($$('.video-item')) { Video.init(); }
	
	// hover 
	if (window.ie6 && $('lb-01')){
		$$('#lb-01 .roleta').each(function(element){
			element.addEvent('mouseenter', function(){
				element.getElement('.wrapper').setStyle('display','block');
			});
			element.addEvent('mouseleave', function(){
	      element.getElement('.wrapper').setStyle('display','none');
			});
		});
	}
	
	if ($('hra-tetris')){
		 var so = new SWFObject("tetris.swf", "hra", "400", "380", "8.0.23", "", true);
		 so.addParam('wmode','transparent');
		 so.write("hra");
	}
	
	if ($('hra-blechy')){
		var so = new SWFObject("blechy.swf", "hra", "770", "435", "8.0.23", "", true);
    so.write("hra");
	}
	
	// clickable blocks
	if ($$('.clickable')){
				$$('.clickable').each(function(item){
					item.setStyle('cursor', 'pointer');
					var anchor = item.getElement('a');
					if (anchor){
						item.addEvent('click', function(){
							window.location = anchor.get('href');
						});
						anchor.addEvent('click', function(event){
							event.stopPropagation();
						});
					}
					
				});
	}
	
});