var EmotionImages_SlideShow;

$(document).ready(function() {
/*
			if(!(navigator.userAgent.match(/iPhone/i)) && !(navigator.userAgent.match(/iPod/i)) && !(navigator.userAgent.match(/iPad/i)))
			{
 $('.SubTeaserElement div,.TeaserElement,.ZMSTeaserElement .text').each(function(k,v) {
		e=$(v);
		eimg= e.children("img");

		if(eimg.length>0) {
				e.hover(function() {
					grayscale.reset( $(this).children("img") );
				}, function() {
					grayscale( $(this).children("img") );
				});
				grayscale(eimg);
			}
	});
		}
*/
	if($('#EmotionImages')) {
		startreturn = startSlideShow();
	}

	$('#Channel ul.main li.parent').each(function(i){
		$(this).mouseenter(function() {
			$(this).addClass('over');
			if(!$.browser.msie) $(this).children("ul").css({opacity: 0.0}).animate({opacity: 1.0}, 500);
		});
		$(this).mouseleave(function() {
			if(!$.browser.msie) $(this).children("ul").animate({opacity: 0.0}, 200);
			$(this).removeClass('over');
		});
	});
	
	$('#Channel ul.main li.menu3show').each(function(i){
		$(this).mouseenter(function() {
			elid=$(this).attr('rel');
			if(!$('#MenuInformation'+elid).is('div')) {
				html = '<table cellpadding="0" width="544" cellspacing="0"><tr><td valign="top" width="169"><h1>'+menu3show[elid].title+'</h1><p>'+menu3show[elid].desc;
				if(menu3show[elid].url) html+='<br/><a href="'+menu3show[elid].url+'">more</a>'; 
				html+='</p></td><td valign="top" width="375">';
				if(menu3show[elid].img) html+='<img src="'+menu3show[elid].img+'" alt="'+menu3show[elid].title+'"/>';
				if(menu3show[elid].childs && menu3show[elid].childs.length>0){
					html+='<ul class="child4">';
					$.each(menu3show[elid].childs, function(key, value) { 
						html+='<li><a href="'+value.url+'">'+value.title+'</a></li>';
					});
					html+='</ul>';
				}
				html+='</td></tr></table>';
				$('<div class="MenuInformation" id="MenuInformation'+elid+'"><div class="clerasil">'+html+'</div></div>').appendTo($(this));
			}
			p_top = $(this).offset().top - 135;
			$('#MenuInformation'+elid).css({top: (p_top*-1) +"px"}).css({opacity: 0.0}).animate({opacity: 1.0}, 500).show();
			// $('#MenuInformation').bind('mouseleave',function(){ $('#MenuInformation').remove(); });
		});
		
		$(this).mouseleave(function() {
			$(this).children('div.MenuInformation').animate({opacity: 0.0}, 200).hide();
		});
	});

	$('.SubTeaserElement h2.title a').each(function(i){
		$(this).click(function(event){
			event.preventDefault();
			$(this).parent().parent().toggleClass('open');
			nexttext = $(this).parent().next('div');
			nexttext.slideToggle("fast");
		});
	});

	if($('.tabController')){

		$('.tabHolder').height($('.tabHolder div:first').height());
		
		$('.tabController li a').each(function(i){
			$(this).click(function(event){
				event.preventDefault();
				$('.tabController li.active').each(function(i){ $(this).removeClass('active'); });
				$(this).parent().addClass('active');
	
				$('.tabHolder div.active').each(function(i){ 
					$(this).animate({opacity: 0}, 200,function(){ 
						$(this).css({display:'none'});
						$(this).removeClass('active');
					});
				});
				
				$('#'+$(this).attr('rel')).css({display: 'block'}).animate({opacity: 1.0}, 200,function (){ $(this).addClass('active');
					$('.tabHolder').height($(this).height());
				});
			
				
			});
		});
	}
	
	$('.EmotionImagesController li').each(function(i){
        $(this).click(function(event){
           // $(this).css({'opacity':1});
            event.preventDefault();
            stepToSlide(i);
		});		
	});

	$('.ZMSTeaserElement h2.title').each(function(i){
        $(this).click(function(event){
            event.preventDefault();
			$(this).toggleClass('open');
            nexttext = $(this).next('div.text');
            nexttext.slideToggle("fast");
        });
    });
    	
});

function startSlideShow(){
	EmotionImages_SlideShow = setInterval( "slideSwitch()", 5000 );
	return false;
}

function stopSlideShow(){
	if(EmotionImages_SlideShow)  clearInterval(EmotionImages_SlideShow);
	return false;
}

function stepToSlide(step){

	stopSlideShow();

	var $active = $('#EmotionImages ul li.active');	
	var $next = $($('#EmotionImages ul li')[step]);
	
	$active.addClass('last-active');

    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
    });
}

function slideSwitch(){
	var $active = $('#EmotionImages ul li.active');
    if ( $active.length == 0 ) $active = $('#EmotionImages ul li:last');
	
	var $next =  $active.next().length ? $active.next() : $('#EmotionImages ul li:first');
	
	$active.addClass('last-active');

    $next.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
    });
}

if (top != self) {
       top.location=self.location;
}

function open_function(url,width,height,options) { 
	self.msgWindow = open(url, "Window", "width=" + width + ",height=" + height + ",screenX=" + (screen.width-width)/2 + ",screenY=" + (screen.height-height)/2 + ",dependent=yes" + ",left=" + (screen.width-width)/2 + ",top=" + (screen.height-height)/2 + options );
	if (self.msgWindow) { 
		self.msgWindow.focus();
		if (self.msgWindow.opener == null) self.msgWindow.opener = self;
	}
}

function get_url (url, k0 ,v0 ,k1 ,v1 ,k2 ,v2 ,k3 ,v3 ,k4 ,v4 ) { 
	if (k0 && v0) url += "?" + k0 + "=" + escape(v0); if (k1 && v1) url += "&" + k1 + "=" + escape(v1); 
	if (k2 && v2) url += "&" + k2 + "=" + escape(v2); if (k3 && v3) url += "&" + k3 + "=" + escape(v3);
	if (k4 && v4) url += "&" + k4 + "=" + escape(v4); 
	return url;
}

