// JavaScript Document
var $ttnews_uid;
$(document).ready(function() {
	//alert($.browser.version);
	if($.browser.mozilla && $.browser.version=='1.9.0.19') {
		$('.h1, #nav1 ul li, #nav2 ul li, #info-date, #info-location, #lang ul li, #subnav ul li, #bands ul li li, .lineup h3, .right-box h5, .news-start-item h3, .news-list h2').css({
			'font-family':"'TraumzeitWebCompressedBold','Arial Narrow', 'Impact', Arial",
			'letter-spacing':'-1px'
		});
		$('li.lineup-item h4, .news-list-item h2').css({
			'letter-spacing':'-1px'
		});
	}
	
	var flashvars = {};
	var params = {
		menu: "false",
		scale: "noScale",
		wmode: "transparent",
		salign:"tl"
	};
	swfobject.embedSWF("fileadmin/relaunch2011/swf/slideshow.swf", "slideshow-container", "560", "331", "9.0.0", "fileadmin/relaunch2011/swf/expressInstall.swf", flashvars, params);
	
	$('#right-community ul img').hover(function(e) {
		e.preventDefault();
		$alt = $(this).attr('alt');
		$(this).attr('alt','');
		$(this).attr('title','');
		$('#right-community p').html($alt);
	}, function(e) {
		e.preventDefault();
		$(this).attr('alt',$alt);
		$(this).attr('title',$alt);
		$('#right-community p').html('');
	});
	
	$('#bands ul').css({
		'display':'block'
	});
	$i = 0;
	$('#bands ul li.li-1').each(function() {
		$i = 0;
		$(this).find('ul li').each(function() {
			if($i==0) {
				$(this).addClass('li-band-first');
			}
			$i++;
		});
	});
	$i = 0;
	$('#bands ul li.li-1').each(function() {
		if($i==0) {
			$(this).addClass('li-band-1-first');
		}
		$i++;
	});
	//:first-child
	$bandCurrent = 0;
	$jj = 0;
	$t = window.setInterval(bandSlide, 10000);
	
	$lineupAni = false;
	$('.lineup-trigger').bind('click',function(e) {
		e.preventDefault();
		if($lineupAni == true) {
			return;
		}
		$(this).css({
			'outline':'none'
		});
		$lineupAni = true;
		$idString = $(this).attr("id");
		$trigger = $(this);
		$id = $idString.replace('lineup-item-id-', '');
		$href = $(this).attr("href");
		$noThing = false;
		$('.lineup-content').each(function() {
			$tempID = $(this).parents('li.lineup-item').find('.lineup-trigger').attr("id");
			//alert($tempID+"!="+$idString);
			if($tempID!=$idString) {
			} else {
				$noThing = true;
			}
			$(this).clearQueue();
			if($.browser.msie) {
				$(this).slideUp('fast',function() {
					$(this).remove();
				});
			} else {
				$(this).find('.lineup-content-inner').clearQueue().fadeTo('fast',0, function() {
					$(this).parents('.lineup-content').slideUp('fast',function() {
						$(this).remove();
					});
				});
			}
		});
		if($noThing==false) {
			$.get($href, {
				//'id':$id,
				'type':'55'
			}, function(data, textStatus, jqXHR) {
				if(data.length>0) {
					$trigger.parents('h4').after('<div class="lineup-content" style="display:none;"><div class="lineup-content-inner"><div class="lineup-close" id="lineup-close-1"><a href="#">Schließen</a></div>'+data+'<div class="lineup-close" id="lineup-close-2"><a href="#">Schließen</a></div></div></div>');
					if($.browser.msie) {
						$trigger.parents('li.lineup-item').find('.lineup-content').slideDown('slow');
					} else {
						$trigger.parents('li.lineup-item').find('.lineup-content-inner').fadeTo('fast',0,function() {
							$(this).parents('.lineup-content').slideDown('slow', function() {
								$(this).find('.lineup-content-inner').fadeTo('slow',1, function() {
									$(this).removeAttr('filter');
									$(this).css('opacity','');
								});
							});
						});
					}
					$trigger.parents('li.lineup-item').find('.lineup-close a').click(function(e) {
						e.preventDefault();
						$(this).parents('li.lineup-item').find('.lineup-trigger').click();
					});
				}
				$lineupAni = false; 
			});
		} else {
			$lineupAni = false; 
		}
	});
	$('#newsletter-name').focus(function() {
		if($(this).val()=="Vorname") {
			$(this).val('');
		}
	});
	$('#newsletter-name').focusout(function() {
		if($(this).val()=="") {
			$(this).val('Vorname');
		}
	});
	$('#newsletter-lastname').focus(function() {
		if($(this).val()=="Nachname") {
			$(this).val('');
		}
	});
	$('#newsletter-lastname').focusout(function() {
		if($(this).val()=="") {
			$(this).val('Nachname');
		}
	});
	$('#newsletter-email').focus(function() {
		if($(this).val()=="E-Mail") {
			$(this).val('');
		}
	});
	$('#newsletter-email').focusout(function() {
		if($(this).val()=="") {
			$(this).val('E-Mail');
		}
	});
	$('#right-newsletter form').bind('submit', function() {
		if($(this).find('#newsletter-email').val()=="E-Mail") {
			$(this).find('#newsletter-email').val('');
		}
		if($(this).find('#newsletter-name').val()=="Vorname") {
			$(this).find('#newsletter-name').val('');
		}
		if($(this).find('#newsletter-lastname').val()=="Nachname") {
			$(this).find('#newsletter-lastname').val('');
		}
	})
	initNewsList();
	initDownloads();
	initStartNews();
	initRaster();
});
function initStartNews() {
	$('.news-start-item a').click(function(e) {
		e.preventDefault();
		$id = $(this).attr("id");
		$trigger = $(this);
		$id = $id.replace('start-news-title-', '');
		$id = $id.replace('start-news-more-', '');
		$href = $(this).attr("href");
		$divider = $href.indexOf("?")===-1 ? "?" : "&";
		$href = $href + $divider + "tx_ttnews[js]=1";
		location.href = $href;
	});
}
function bandSlide() {
	//$bandCurrent = 0;
	var anzahl = $('#bands ul.ul-1 li.li-1').length;
	var next = $bandCurrent+1;
	next = next>=anzahl ? 0 : next;
	$now = $('#bands ul li.li-1')[$bandCurrent];
	$next = $('#bands ul li.li-1')[next];
	$($now).css({
		'position':'absolute',
		'left':0,
		'top':0
	});
	$($next).css({
		'position':'absolute',
		'display':'block',
		'left':816,
		'top':0
	});
	$($next).animate({
		'left':0
	},'slow');
	$($now).animate({
		'left':Math.max(816,$($now).width())*-1
	},'slow');
	$bandCurrent = next;
	$jj++;
	if($jj>=3) {
		//clearInterval($t);
	}
}

function initNewsList() {
		var $newsListAni = false;
		$('.news-list-trigger').bind('click',function(e) {
			e.preventDefault();
			if($newsListAni == true) {
				return;
			}
			$(this).css({
				'outline':'none'
			});
			$newsListAni = true;
			$idString = $(this).attr("id");
			$trigger = $(this);
			$id = $idString.replace('news-trigger-title_', '');
			$id = $id.replace('news-trigger-image_', '');
			$id = $id.replace('news-trigger-more_', '');
			$idA = $id.split("_");
			$pidString = $idA[0];
			$uidString = $idA[1];
			$pid = $pidString.replace('pid-', '');
			$uid = $uidString.replace('uid-', '');
			$noThing = false;
			$('.news-list-item-detail').each(function() {
				$tempID = $(this).parents('.news-list-item').find('.news-list-trigger').attr("id");
				$tempID = $tempID.replace('news-trigger-title_', '');
				$tempID = $tempID.replace('news-trigger-image_', '');
				//alert($tempID+"!="+$idString);
				if($tempID!=$id) {
				} else {
					$noThing = true;
				}
				$(this).clearQueue();
				$(this).parents('.news-list-item').find('.news-list-item-img').fadeIn('fast');
				$(this).parents('.news-list-item').find('.news-list-item-preview').fadeIn('fast');
				
				$(this).parents('.news-list-item').find('#news-list-item-close-1').fadeTo('fast',0, function() {
					$(this).remove();
				});
				$(this).slideUp('fast',function() {
					//$(this).parents('.news-list-item').find('.news-list-item-preview').slideDown('slow');
					$(this).remove();
				});
			});
			
			if($noThing==false) {
				
				//$langID = $.getUrlVar('L');
				$__href = $(this).attr("href");
				$.get($__href, {
					//'id':$pid,
					//'tx_ttnews[tt_news]':$uid,
					'type':'55'
				}, function(data, textStatus, jqXHR) {
					if(data.length>0) {
						$trigger.parents('.news-list-item').find('.news-list-item-content').prepend('<div class="news-list-item-close" id="news-list-item-close-1" style="display:none;"><a href="#">Schließen</a></div>');
						//$trigger.parents('.news-list-item').find('.news-list-item-preview').after('<div class="news-list-item-detail" style="display:none;"><div class="news-list-item-detail-inner"><div class="news-list-item-close" id="news-list-item-close-1"><a href="#">Schließen</a></div>'+data+'<div class="news-list-item-close" id="news-list-item-close-2"><a href="#">Schließen</a></div></div></div>');
						$trigger.parents('.news-list-item').find('.news-list-item-preview').after('<div class="news-list-item-detail" style="display:none;"><div class="news-list-item-detail-inner">'+data+'<div class="news-list-item-close" id="news-list-item-close-2"><a href="#">Schließen</a></div></div></div>');
						
								$span = $(this).find('.rgmediaimages-player');
								$object = $($span).find('object');
								$embed = $($span).find('embed');
								$maxH = Math.max($($object).height(),$($embed).height());
								if($maxH>0) {
									$($span).css({
										'display':'block',
										'overflow':'hidden',
										'height':($maxH)+"px"
									});
								}
								//$($span).html($.trim($($span).html()))
								
								$img = $(this).find('.news-single-img img');
								$($img).css({
									'margin-bottom':'6px'
								});
								$imgH = $($img).height();
								$a = $($img).parents('a');
								$($a).css({
									'display':'block',
									'overflow':'hidden',
									'height':($imgH+6)+"px"
								});
								$caption = $(this).parents('.news-list-item-detail').find('p.news-single-imgcaption');
								$ch = $($caption).html();
								if($ch!=null) {
									if($ch.length<=1) {
										$($caption).css('display','none');
									}
								}
						
						if($.browser.msie) {
							//$trigger.parents('.news-list-item').find('.news-list-item-preview').slideUp('slow', function() {
								$trigger.parents('.news-list-item').find('.news-list-item-detail').slideDown('slow');
								$trigger.parents('.news-list-item').find('.news-list-item-preview').fadeOut('slow');
								$trigger.parents('.news-list-item').find('.news-list-item-img').fadeOut('slow');
								$trigger.parents('.news-list-item').find('#news-list-item-close-1').fadeTo('slow',1);
							//});
						} else {
							//$trigger.parents('.news-list-item').find('.news-list-item-preview').slideUp('slow');
							$trigger.parents('.news-list-item').find('.news-list-item-img').fadeOut('slow');
							$trigger.parents('.news-list-item').find('.news-list-item-preview').fadeOut('slow');
							$trigger.parents('.news-list-item').find('.news-list-item-detail-inner').fadeTo(0.1,0,function() {
							});
							$trigger.parents('.news-list-item').find('.news-list-item-detail').slideDown('slow', function() {
								$(this).parents('.news-list-item').find('#news-list-item-close-1').fadeTo('slow',1);
								$(this).find('.news-list-item-detail-inner').fadeTo('slow',1, function() {
									$(this).removeAttr('filter');
									$(this).css('opacity','');
								});
							});
						}
						$trigger.parents('.news-list-item').find('.news-list-item-close a').click(function(e) {
							e.preventDefault();
							$ft = $(this).parents('.news-list-item').find('.news-list-trigger')[0];
							$($ft).click();
						});
					}
					$newsListAni = false; 
				});
			} else {
				$newsListAni = false; 
			}
		});
		$newsID = $.getUrlVar('tx_ttnews[tt_news]');
		if($ttnews_uid!=null) {
			$newsID = $ttnews_uid!=null && $ttnews_uid!="" ? $ttnews_uid : $newsID;
		}
		if($newsID>0) {
			$('.news-list-item').each(function() {
				$triggerInit = $(this).find('.news-list-trigger')[0];
				$id = $($triggerInit).attr("id");
				$id = $id.replace('news-trigger-title_', '');
				$id = $id.replace('news-trigger-image_', '');
				$idA = $id.split("_");
				$pidString = $idA[0];
				$uidString = $idA[1];
				$pid = $pidString.replace('pid-', '');
				$uid = $uidString.replace('uid-', '');
				if($uid==$newsID) {
					$($triggerInit).click();
				}
			});
		}
}
function initDownloads() {
	$downloadAni = false;
	$('.twdownloads-item a').click(function(e) {
		e.preventDefault();
		if($downloadAni == true) {
			return;
		}
		$(this).css({
			'outline':'none'
		});
		$downloadAni = true;
		$idString = $(this).attr("id");
		$trigger = $(this);
		$id = $idString.replace('twdownloads-id-', '');
		$id = $id.replace('twdownloads-id2-', '');
		$noThing = false;
		closeDownload($id, $(this));
	});
}
function closeDownload(id, trigger) {
		if($('.twdownloads-detail').length==0) {
			loadDownload(id, trigger);
			return;
		}
		$('.twdownloads-detail').each(function() {
			$(this).clearQueue();
			if($.browser.msie) {
				$(this).slideUp('fast',function() {
					$(this).remove();
					if(id!="") {
						loadDownload(id, trigger);
					}
				});
			} else {
				$(this).find('.twdownloads-detail-inner').clearQueue().fadeTo('fast',0, function() {
					$(this).parents('.twdownloads-detail').slideUp('fast',function() {
						$(this).remove();
						if(id!="") {
							loadDownload(id, trigger);
						}
					});
				});
			}
		});
}
function loadDownload(id, trigger) {
		
			$.get('index.php', {
				'eID':'twdownloads_detail',
				'download':id
			}, function(data, textStatus, jqXHR) {
				$downloadAni = false; 
				if(data.length>0) {
					$(trigger).parents('.twdownloads-row').after('<div class="twdownloads-detail" style="display:none;"><div class="twdownloads-detail-inner"><div class="twdownloads-detail-close"><a href="#">Schließen</a></div>'+data+'</div></div>');
					if($.browser.msie) {
						$('.twdownloads-detail').slideDown('slow');
					} else {
						$('.twdownloads-detail').find('.twdownloads-detail-inner').fadeTo('fast',0,function() {
							$(this).parents('.twdownloads-detail').slideDown('slow', function() {
								$(this).find('.twdownloads-detail-inner').fadeTo('slow',1, function() {
									$(this).removeAttr('filter');
									$(this).css('opacity','');
								});
							});
						});
					}
					$('.twdownloads-detail').find('.twdownloads-detail-close a').click(function(e) {
						e.preventDefault();
						closeDownload();
					});
				}
			});
}


function initRaster() {
	$('.twimages a').click(function(e) {
		e.preventDefault();
		$('.twimages-big').stop().clearQueue().remove();
		$('#all').append('<div class="twimages-big"><img src="" border="0" /></div>');
		$href = $(this).attr('href');
		$x = $(this).parents('.twimages').offset().left;
		$y = $(this).parents('.twimages').offset().top;
		$w = $(this).width();
		$h = $(this).height();
		$('.twimages-big').css({
			'left':$x,
			'top':$y
		});
		$('.twimages-big img').attr('src', $href).load(function(){
				
				$ww = $(this).parent().width();
				$hh = $(this).parent().height();
				$(this).css({
					'width':$w,
					'height':$h
				});
			//$(this).fadeIn('fast');
			$(this).animate({
					'width':$ww,
					'height':$hh
			},'fast');
			$(this).parent().fadeIn('fast');
			$(this).click(function() {
				$(this).parents('.twimages-big').fadeTo('fast',0, function() {
					$(this).remove();
				});
			});
		});
	});
}

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});
