if(navigator.userAgent.indexOf('MSIE') != -1)
{
	var ie = true;
}
else
{
	var ie = false;
}

	Element.extend(
	{
		hide: function() 
		{
			return this.setStyle('display', 'none');
		},
		
		show: function() 
		{
			// alert (this.key);
			
			
			var third = (ie == false)?	5 : 2;
			
			

			 this.setStyle('position', 'absolute');
			 this.setStyle('margin-top', '17px');
			 
			
			if(ie != false)
			{
				this.setStyle('margin-left', '-83px');
				if(this.key > third)	this.setStyle('margin-left', '-338px');				
			}
			else
			{
				this.setStyle('margin-left', '0px');
				if(this.key > third)	this.setStyle('margin-left', '-255px');
			}
			

			 this.setStyle('padding', '3px');
			 this.setStyle('z-index', '999');
			 this.setStyle('background', this.getParent().getStyle('background-color')); // + ' url(/skin/submenu.gif) no-repeat ' + pos);
			
			 this.setStyle('width', '332px');
			
			var first = (ie == false)?		1 : 0;
			
			if(this.key == first)
			{
				this.setStyle('width', '416px');
				
				$ES('li', this).each(function(item){
					//if(ie != false)	item.setStyle('letter-spacing','-1px')
					item.setStyle('width', '198px');
					item.setStyle('height', '285px');
				});
			}
			 //this.setStyle('height', '150px');
			 this.addClass(this.getParent().className);
			
			return this.setStyle('display', '');
		}
	});

	var DropdownMenu = new Class({	
		initialize: function(element)
		{
			$A($(element).childNodes).each(function(el, key)
			{
				if(el.nodeName.toLowerCase() == 'li')
				{
					$A($(el).childNodes).each(function(el2)
					{
						if(el2.nodeName.toLowerCase() == 'ul')
						{
							$(el2).hide();
							
							el.addEvent('mouseenter', function()
							{
								el2.key = key;
								el2.show();
								return false;
							});
	
							el.addEvent('mouseleave', function()
							{
								el2.hide();
							});
							new DropdownMenu(el2);
						}
					});
				}
			});
			return this;
		}
	});
	
function loadVideo(video)
{
		  var scroll = new Fx.Scroll(window, {
					 wait: false,
					 duration: 1000,
					 offset: {'x': 0, 'y': -10},
					 transition: Fx.Transitions.Quad.easeInOut
		  });
	
	var flashvars = {
		flashvideo: '/assets/' + video
	};
	var params = {
	  menu: "false",
	  wmode: "transparent",
	  play: true
	};
	var attributes = {
	  id: "banner",
	  name: "banner"
	};
	
	var vWidth = 510;
	var vHeight = 320;
	
   var videoDiv = new Element('div', {
		  'id' : 'prVideo'
	});
	videoDiv.addClass('span-13');

	var videoHolder = new Element('div', {
		  'id' : 'videoHolder'
	});

		  videoHolder.injectInside(videoDiv);
	
	if(location.href.indexOf('press') != -1)
	{
		  if($('prVideo'))
		  {
					 $('prVideo').replaceWith(videoDiv);
		  }
		  else
		  {
					 videoDiv.injectAfter($E('div.intro', $('content')));
		  }
		  videoDiv.setStyle('margin', '20px -20px');
   }
	else
	{
		  if(ie == false)
		  {
					 if($('prVideo'))
					 {
								$('prVideo').replaceWith(videoDiv);
					 }
					 else
					 {
								videoDiv.injectInside($('latestVideo'));
					 }
					 videoDiv.setStyle('margin', '20px -40px');
		  }
		  else
		  {
					 if($('prVideo'))
					 {
								$('prVideo').replaceWith(videoDiv);
					 }
					 else
					 {
								videoDiv.injectAfter($('latestVideo'));
					 }
					 videoDiv.setStyle('margin', '20px -20px');
		  }
	}
   
	var closeBtn = new Element('a', {
				'id' : 'close',
		      'href' : '#',
		      'styles': {
					 'display': 'block',
					 'background': '#7c7c7c',
					 'border-top' : '1px solid #666',
					 'border-bottom' : '1px solid #666',
					 'color' : '#FFF',
					 'margin' : '0 11px',
					 'padding-right' : '4px',
					 'text-align' : 'right'
				},
				'events': {
					 'click': function(){
						  $('prVideo').remove();
						  return false;
					 }
				}
   });
   
   closeBtn.innerHTML = 'X'; 
	closeBtn.injectTop($('prVideo'));

	swfobject.embedSWF("/skin/movie.swf", "videoHolder", vWidth, vHeight, "8.0.0", false, flashvars, params, attributes);
	
		//	var playerVersion = swfobject.getFlashPlayerVersion(); // returns a JavaScript object
		//	var output = "Q: Do I have Flash player 9.0.18 or higher installed?\nA: " + swfobject.hasFlashPlayerVersion("9.0.18");
		//	output = output + "\nYou have Flash player " + playerVersion.major + "." + playerVersion.minor + "." + playerVersion.release + " installed";
		//	alert(output);
	
	scroll.toElement($('prVideo'));
}	

window.addEvent('domready', function(){


	new DropdownMenu($('navMenu'))

   $ES('dd.slide', $('content')).each(function(item){
      var toggler = $E('a.slide', item.getPrevious());


      var cSlider = new Fx.Slide(item, {duration: 500});
      cSlider.hide();

      toggler.addEvent('click', function(e){
         var e = new Event(e);
		
         cSlider.toggle();
         e.stop();
      });
   });

	$$('a.video').each(function(item){
		item.setOpacity(0.7);
		item.addEvent('click', function(e){
			var e = new Event(e);
			loadVideo(item.id);
			e.stop();
		});
	});
	
	$$('a.videoThumb').each(function(item){
		item.setOpacity(0.6);
		item.addEvent('click', function(e){
			var e = new Event(e);
			loadVideo(item.id);
			e.stop();
		});
	});
	
	if($("next"))
	{
		var lowerLimit = 0;

		$("next").addEvent("click", function(e)
		{
		   			
			lowerLimit = Number(lowerLimit) + 8;
			var e = new Event(e);
			
			var url = "/list";
			
					  new Ajax(url, {
							  method: 'get',
							  update: $('latestPr'),
							  data: "lowerLimit=" + lowerLimit,
							  evalScripts: true
					  }).request();
			
			e.stop();
		});
	}

	if($("prev"))
	{
		$("prev").addEvent("click", function(e)
		{
			if(lowerLimit != false)	lowerLimit = Number(lowerLimit) - 8;
			
			var e = new Event(e);
			var url = "/list";
			new Ajax(url, {
					method: 'get',
					update: $('latestPr'),
					data: "lowerLimit=" + lowerLimit,
					evalScripts: true
			}).request();
			
			
			e.stop();
		});
	}


});
