var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);var day="";function checkBirthDate()
{start=1;year=$('birthdayYear')[$('birthdayYear').selectedIndex].value;if(year>1965&&year<=2002)
{$('birthdayMonth').enable();month=$('birthdayMonth')[$('birthdayMonth').selectedIndex].value;if(month>0&&month<=12)
{$('birthdayDay').enable();if(month==2)
{if(year%4==0)
{end=29;}
else
{end=28;}}
else
{end=monthDays[month-1];}
$('birthdayDay').innerHTML="";newEntry=new Option(day,"",false,true);$('birthdayDay').options[$('birthdayDay').length]=newEntry;for(i=start;i<=end;i++)
{newEntry=new Option(i,i,false,true);$('birthdayDay').options[$('birthdayDay').length]=newEntry;}
$('birthdayDay').selectedIndex=0;}
else
{$('birthdayDay').selectedIndex=0;$('birthdayDay').disable();}}
else
{$('birthdayMonth').selectedIndex=0;$('birthdayMonth').disable();$('birthdayDay').selectedIndex=0;$('birthdayDay').disable();}}
function setBirthDate(year,month,day)
{for(i=0;i<$('birthdayYear').length;i++)
{if($('birthdayYear')[i].value==year)
{$('birthdayYear').selectedIndex=i;break;}}
for(i=0;i<$('birthdayMonth').length;i++)
{if($('birthdayMonth')[i].value==month)
{$('birthdayMonth').selectedIndex=i;break;}}
checkBirthDate();$('birthdayDay').selectedIndex=day;}
function showLoading()
{Effect.Appear('loading',{duration:0.2,queue:{scope:'loading',position:'front'}});}
function hideLoading()
{Effect.Fade('loading',{duration:0.2,queue:{scope:'loading',position:'end'}});}
function openOnTopMessage()
{$('onTopMsgText').innerHTML=$('loader').innerHTML;$('onTopMsgTitle').innerHTML='Loading';if(!$('fader').visible())
{Effect.BlindDown($('fader'),{duration:0.2,queue:'front'});}
Effect.Appear($('onTopMsg'),{duration:0.5,queue:'end'});$('tmp').innerHTML=$('onTopMsg').innerHTML;changeOverlaySize($('tmp').getWidth(),$('tmp').getHeight(),(maxWidth-$('tmp').getWidth())/2,(maxHeight-$('tmp').getHeight())/2,0);}
function changeOverlaySize(width,height,left,top,duration)
{if(width>maxWidth)
{height=height*maxWidth/width;width=maxWidth;}
if(height>maxHeight)
{width=width*maxHeight/height;height=maxHeight;}
left=(maxWidth-width)/2;top=(maxHeight-height)/2;new Effect.Morph($('onTopMsg'),{style:'width:'+(width+20)+'px;'+'height:'+(height+56)+'px; '+'left:'+(left-10+paddingH/2)+'px; '+'top:'+(top-28+paddingV/2)+'px;',duration:duration,queue:'front'});}
var currMsg;var currTitle;function showOnTopMessage(msg,title)
{$('tmp').innerHTML=msg;changeOverlaySize($('tmp').getWidth(),$('tmp').getHeight(),(maxWidth-$('tmp').getWidth())/2,(maxHeight-$('tmp').getHeight())/2,0.35);currTitle=title;currMsg=msg;window.setTimeout(refreshOnTopTexts,350);}
function sleep(ms){var zeit=(new Date()).getTime();var stoppZeit=zeit+ms;while((new Date()).getTime()<stoppZeit){};}
function refreshOnTopTexts()
{$('onTopMsgText').hide();$('onTopMsgTitle').hide();$('onTopMsgText').innerHTML=currMsg;if(currTitle!=null)
{$('onTopMsgTitle').innerHTML=currTitle;}
new Effect.Parallel([new Effect.Appear('onTopMsgText'),new Effect.Appear('onTopMsgTitle')],{duration:0.5});}
function hideOnTopMsg()
{Effect.BlindUp($('fader'),{duration:0.2});Effect.Fade($('onTopMsg'),{duration:0.5});}
function getConfirm(param)
{openOnTopMessage();new Ajax.Updater('tmp','/ajax/get.php',{parameters:param,method:'post',evalScripts:true,onComplete:function(transport)
{showOnTopMessage(transport.responseText,null);hideLoading();}});return false;}
function changebImages(){if(document.images){if(changebImages.arguments[1]&&changebImages.arguments[1]=='out'){$(changebImages.arguments[0]+'_left').className="left";$(changebImages.arguments[0]+'_right').className="right";$(changebImages.arguments[0]+'_mid').className="mid";}else{$(changebImages.arguments[0]+'_left').className="left over_left";$(changebImages.arguments[0]+'_right').className="right over_right";$(changebImages.arguments[0]+'_mid').className="mid over_mid";}}}
function showPicture()
{if(bigPicture.width>maxWidth)
{bigPicture.height=bigPicture.height*maxWidth/bigPicture.width;bigPicture.width=maxWidth;}
if(bigPicture.height>maxHeight)
{bigPicture.width=bigPicture.width*maxHeight/bigPicture.height;bigPicture.height=maxHeight;}
txt='<div style="width:'+bigPicture.width+'px; height:'+bigPicture.height+'px;">'+'<img src="'+bigPicture.src+'" alt="'+bigPictureTitle+'" title="'+bigPictureTitle+'" width="'+bigPicture.width+'" height="'+bigPicture.height+'" />'+'</div>';$('tmp').innerHTML=txt;sleep(250);showOnTopMessage(txt,bigPictureTitle);}
function getPicture(picture)
{bigPicture=new Image();for(i=0;i<picture.childNodes.length;i++)
{if(picture.childNodes[i].nodeValue==null&&picture.childNodes[i].hasAttribute("title"))
{bigPictureTitle=picture.childNodes[i].getAttribute("title");continue;}}
var source=picture.getAttribute("href");if(picture.getAttribute('rel')=='overlay')
{openOnTopMessage();pictureLoaded=false;bigPicture.src=source;bigPicture.onload=function()
{showPicture();};}
return false;}
var bigPicture;var bigPictureTitle;var pictureLoaded=false;var maxWidth;var maxHeight;var paddingH=200;var paddingV=200;function parseLinks()
{if(BrowserCheck()==0)
{maxWidth=window.innerWidth-paddingH;maxHeight=window.innerHeight-paddingV;}
else if(BrowserCheck()==1)
{maxWidth=document.body.offsetWidth-paddingH;maxHeight=document.body.offsetHeight-paddingV;}
var piclinks=$$('a');for(i=0;i<piclinks.length;i++)
{if(piclinks[i].getAttribute('rel')=='overlay')
{piclinks[i].onclick=function()
{return getPicture(this)}}
else{}}}
function BrowserCheck()
{var nav=navigator.appName
if(nav=="Netscape")
{return 0;}
else if(nav=="Microsoft Internet Explorer"||nav=="msie")
{return 1;}
else
{return 2;}}
var mapElement;function showMap(src,title)
{openOnTopMessage();mapElement='<iframe src="'+src+'" width="'+maxWidth+'" height="'+maxHeight+'" id="maps_frame"></iframe>';$('tmp').innerHTML=mapElement;sleep(1000);showOnTopMessage(mapElement,title);}
function showLyrics(songId)
{openOnTopMessage();new Ajax.Updater('tmp','/ajax/getLyrics.php',{parameters:{song_id:songId},method:'post',evalScripts:true,onComplete:function(transport)
{msg=transport.responseText.evalJSON();showOnTopMessage(msg.text,msg.title);hideLoading();}});return false;}
function getMessage(messageID,boxName)
{showLoading();new Ajax.Updater('messages','/ajax/readMessages.php?box='+boxName+'&action=read&messageID='+messageID,{onComplete:function(transport)
{hideLoading();}});return false;}
function moveMessage(messageID,toBox,boxName)
{showLoading();new Ajax.Updater('messages','/ajax/readMessages.php?box='+boxName+'&action=move&toBox='+toBox+'&messageID='+messageID,{onComplete:function(transport)
{hideLoading();}});return false;}
function deleteMessage(messageID,boxName)
{showLoading()();new Ajax.Updater('messages','/ajax/readMessages.php?box='+boxName+'&action=delete&messageID='+messageID,{onComplete:function(transport)
{hideLoading();}});return false;}
function changeFolder(boxName)
{showLoading();new Ajax.Updater('messages','/ajax/readMessages.php?box='+boxName,{onComplete:function(transport)
{hideLoading();}});return false;}
function sendMessage(formData)
{openOnTopMessage();new Ajax.Updater('tmp','/ajax/sendMessage.php',{parameters:formData,evalScripts:true,onComplete:function(transport)
{showOnTopMessage(transport.responseText,null);hideLoading();}});return false;}
function getModells(language)
{showLoading();while($('modells_box').hasChildNodes()){$('modells_box').removeChild($('modells_box').lastChild);}
manufacturerId=$('manufacturers').options[$('manufacturers').selectedIndex].value;new Ajax.Request('/ajax/getModellsByManufacturer.php',{parameters:{manufacturer_id:manufacturerId},onSuccess:function(transport)
{var mobiles=transport.responseText.evalJSON();if((mobiles).length>0)
{container=document.createElement("div");innerContainer=document.createElement("div");var currMobile;mobiles.each(function(currMobile)
{box=document.createElement("div");contentBox=document.createElement("div");link=document.createElement("a");link.href=currMobile.id+"/";deviceImg=document.createElement("img");statusImg=document.createElement("img");pictureBox=document.createElement("div");nameDiv=document.createElement("div");pictureBox.className="clearfix";box.className="clearfix mobileBox";contentBox.className="content";deviceImg.src=currMobile.deviceImage;deviceImg.className="deviceImage";nameDiv.innerHTML=currMobile.name;nameDiv.className="name";statusImg.src=currMobile.statusImage;statusImg.className="statusImage";pictureBox.appendChild(deviceImg);pictureBox.appendChild(statusImg);link.appendChild(pictureBox);link.appendChild(nameDiv);contentBox.appendChild(link);box.appendChild(contentBox)
innerContainer.appendChild(box);container.appendChild(innerContainer);});container.className="box";$('modells_box').appendChild(container);$('modells_box').appear();}
hideLoading();}});}
function $o(v,o){return((typeof(o)=='object'?o:document).getElementById(v));}
function $S(o){return((typeof(o)=='object'?o:$o(o)).style);}
function agent(v){return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0));}
function abPos(o){var o=(typeof(o)=='object'?o:$o(o)),z={X:0,Y:0};while(o!=null){z.X+=o.offsetLeft;z.Y+=o.offsetTop;o=o.offsetParent;};return(z);}
function XY(e,v){var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY};return(v?o[v]:o);}
star={};star.voted=false;star.mouse=function(e,o)
{if(star.stop||isNaN(star.stop))
{star.stop=0;document.onmousemove=function(e)
{var n=star.num;var p=abPos($o('star'+n)),x=XY(e),oX=x.X-p.X,oY=x.Y-p.Y;star.num=o.id.substr(4);if(oX<1||oX>84||oY<0||oY>19)
{star.stop=1;star.revert();}
else
{starWidth=84/5;$S('starCur'+n).width=oX+'px';$S('starUser'+n).color='#FFFFFF';$o('starUser'+n).innerHTML=Math.round(oX/84*100)+'%';}};}};star.update=function(e,o){var n=star.num;v=parseInt($o('starUser'+n).innerHTML);n=o.id.substr(4);$o('starCur'+n).title=v;Effect.BlindDown($('fader'),{duration:0.2,queue:'front'});openOnTopMessage();new Ajax.Updater('tmp','/ajax/rate.php',{parameters:{vote:v,id:n,type:$('type'+n).value},evalScripts:true,method:'POST',onComplete:function(transport)
{showOnTopMessage(transport.responseText,"title");hideLoading();}});};star.revert=function()
{var n=star.num;v=parseInt($o('starCur'+n).title);$S('starCur'+n).width=Math.round(v*84/100)+'px';$o('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');$o('starUser'+n).style.color='#999999';};star.num=0;function clearSearch(element)
{element.value="";}
function resetSearch(element)
{if($('search_results').visible())
{new Effect.BlindUp('search_results',{queue:'end',duration:0.3});}
if((trim(element.value)).length==0)
{element.value=$('default').value;}}
var previousResponse="";var previousRequest=null;function searchFriends(element)
{if(previousRequest!=null)
{previousRequest.transport.abort();}
previousRequest=new Ajax.Updater('search_results','/ajax/searchInFriends.php',{parameters:{input:element.value},method:'post',onComplete:function(transport)
{if(transport.responseText!="")
{if(transport.responseText!=previousResponse)
{$('search_results').clonePosition(element,{setWidth:false,setHeight:false});new Effect.Move($('search_results'),{y:19,mode:'relative',duration:0});if(!$('search_results').visible())
new Effect.BlindDown('search_results',{queue:'end',duration:0.3});}
previousResponse=transport.responseText;}}});}
function trim(str)
{return str.replace(/^\s+/,'').replace(/\s+$/,'');}
var defaultDuration=0.15;function setActiveDistrict(districtId)
{if(districtId==null)
{unHighlightDistrict(lastDistrictId);}
else
{highlightDistrict(districtId);updateInfoBlock(districtId);lastDistrictId=districtId;}}
function highlightDistrict(districtId)
{new Effect.Appear('gh_city_district_'+districtId,{duration:defaultDuration/2,queue:{position:'front',scope:'hlDistrict'}});}
var effect;var axConnection;function unHighlightDistrict(districtId)
{new Effect.Fade('gh_city_district_'+districtId,{duration:defaultDuration/2,queue:{position:'end',scope:'hlDistrict'}});if(effect!=null)
{effect.cancel();}
effect=new Effect.Parallel([new Effect.Fade('districtDescriptionBlock',{sync:true}),new Effect.Fade('districtInhabitsBlock',{sync:true})],{duration:defaultDuration});if(axConnection!=null)
{axConnection.transport.abort();}}
var clans=new Array(0,1,4,3,6,2,0,5,0);function updateInfoBlock(districtId)
{if(axConnection!=null)
{axConnection.transport.abort();}
request=new Ajax.Request('/ajax/getDistrictInfo.php',{parameters:{district_id:districtId,clan_id:clans[districtId]},method:'post',onCreate:function(request){axConnection=request;},onComplete:function(transport){var district=transport.responseText.evalJSON();$('districtTitle').innerHTML=district.name;$('districtDescr').innerHTML=district.description;$('districtImage').src=district.img;out="";if(district.clanImg!="")
{$('districtInhabitsTitle').innerHTML=district.clanName;$('districtInhabitsTxt').innerHTML=district.inhabitans;$('districtInhabitsImg').src=district.clanImg;if(effect!=null)
{effect.cancel();}
effect=new Effect.Parallel([new Effect.Appear('districtDescriptionBlock',{sync:true}),new Effect.Appear('districtInhabitsBlock',{sync:true})],{duration:defaultDuration});}
else
{if(effect!=null)
{effect.cancel();}
new Effect.Appear('districtDescriptionBlock',{duration:defaultDuration});}}});}
var tourSlides=0;var currentSlide=0;var transitionDuration=0.5;function startTour()
{$('tour_'+currentSlide).appear({duration:transitionDuration});refreshTourButtons();}
function tourNextSlide()
{if(currentSlide+1<tourSlides)
{$('tour_'+currentSlide).fade({duration:transitionDuration});++currentSlide;$('tour_'+currentSlide).appear({duration:transitionDuration});refreshTourButtons();}}
function tourPrevSlide()
{if(currentSlide>0)
{$('tour_'+currentSlide).fade({duration:transitionDuration});--currentSlide;$('tour_'+currentSlide).appear({duration:transitionDuration});refreshTourButtons();}}
function refreshTourButtons()
{if(currentSlide==0)
{if($('tourPrev').visible())
{$('tourPrev').fade({duration:transitionDuration});}}
else
{if(!$('tourPrev').visible())
{$('tourPrev').appear({duration:transitionDuration});}}
if(currentSlide+1==tourSlides)
{if($('tourNext').visible())
{$('tourNext').fade({duration:transitionDuration});}
if(!$('tourEnd').visible())
{$('tourEnd').appear({duration:transitionDuration});}}
else
{if(!$('tourNext').visible())
{$('tourNext').appear({duration:transitionDuration});}
if($('tourEnd').visible())
{$('tourEnd').fade({duration:transitionDuration});}}}
function endTour(url)
{window.location.href=url;}
var plusImage;var minusImage;function toggleVisibility(element)
{if($(element).visible())
{Effect.SlideUp(element,{duration:0.3});display="none";$(element+"_img").src=plusImage;}
else
{Effect.SlideDown(element,{duration:0.3});display="block";$(element+"_img").src=minusImage;}
var a=new Date();a=new Date(a.getTime()+60*60*24*30);document.cookie=element+'='+display+'; expires='+a.toGMTString()+';';}
function addSmilie(smilie)
{tinyMCE.execCommand('mceInsertContent',false,smilie);}
actionIds=new Array();var cnt=13;delay=1000;notUpdated=0;function initActionTicker()
{reloadActionTickerData();}
lastUpdate=null;function reloadActionTickerData()
{if(lastUpdate!=null)
{url='/ajax/getLatestActions.php?cnt='+cnt+'&date='+lastUpdate;}
else
{url='/ajax/getLatestActions.php?cnt='+cnt;}
new Ajax.Request(url,{onSuccess:function(transport)
{try
{tickerData=transport.responseText.evalJSON();refreshActionTickerData(tickerData);}
catch(e){}}});}
function refreshActionTickerData(tickerData)
{insertData=new Array();dropData=new Array();updates=0;dropCounter=0;tickerData.each(function(tickerRow)
{if(!actionIds.in_array(tickerRow.action_id))
{insertData.push(tickerRow);if(actionIds.length>=cnt)
{actionIds.unshift(tickerRow.action_id);++dropCounter;}
else
{actionIds.push(tickerRow.action_id);}
if(lastUpdate<tickerRow.action_dt)
{lastUpdate=tickerRow.action_dt;}
++updates;}});for(i=0;i<dropCounter;i++)
{dropData.push(actionIds.pop());}
if(updates==0)
{++notUpdated;}
else
{notUpdated=0;}
dropActionTickerRows(dropData);insertActionTickerRows(insertData);window.setTimeout(reloadActionTickerData,1500+delay*notUpdated);}
function dropActionTickerRows(dropIds)
{Effect.multiple(dropIds,Effect.DropOut);}
function insertActionTickerRows(insertData)
{divArray=new Array();insertData.reverse();insertData.each(function(insertRow)
{divContainer=document.createElement("div");divContainer.id=insertRow.action_id;$(divContainer).setStyle({margin:"5px 0px"});innerDiv=document.createElement("div");$(innerDiv).setStyle({borderBottom:"1px solid #555555"});innerDiv.innerHTML='<img src="'+insertRow.action_image+'">'+insertRow.action_text;divContainer.appendChild(innerDiv);divContainer.style.display="none";Element.insert($('latestStats'),{'top':divContainer});divArray.unshift(insertRow.action_id);new Effect.Parallel([new Effect.SlideDown(divContainer),new Effect.Highlight(divContainer,{startcolor:'#808080',endcolor:'#505050'})],{duration:1});});}
battleIds=new Array();function initTicker()
{reloadTickerData();}
function reloadTickerData()
{new Ajax.Request('/ajax/getLatestGameResults.php',{onSuccess:function(transport)
{try
{tickerData=transport.responseText.evalJSON();}
catch(e)
{}
refreshTickerData(tickerData);}})}
Array.prototype.in_array=function(needle){for(var i=0;i<this.length;i++){if(needle===this[i])
return true}
return false;}
function refreshTickerData(tickerData)
{insertData=new Array();dropData=new Array();tickerData.each(function(tickerRow)
{if(!battleIds.in_array(tickerRow.battle_id))
{insertData.push(tickerRow);if(battleIds.length>=7)
{battleIds.unshift(tickerRow.battle_id);dropData.push(battleIds.pop());}
else
{battleIds.push(tickerRow.battle_id);}}});dropTickerRows(dropData);insertTickerRows(insertData);window.setTimeout(reloadTickerData,3000);}
function dropTickerRows(dropIds)
{dropIds.each(function(dropId)
{new Effect.SlideUp(dropId,{duration:1});});}
function insertTickerRows(insertData)
{insertData.reverse();insertData.each(function(insertRow)
{STATIC_SERVER="http://static.gedda-headz.com/";divContainer=document.createElement("div");divContainer.id=insertRow.battle_id;innerDiv=document.createElement("div");innerDiv.innerHTML='<table class="ticker" cellpadding="0" cellspacing="0"><tr>'+'<td width="35" rowspan="2"><img src="'+STATIC_SERVER+'img/heads/tiny/'+insertRow.winner_head+'.png" /></td>'+'<td width="70"><a href="/de/Account/Profile/'+insertRow.winner_user+'/">'+insertRow.winner_user+'</a></td>'+'<td width="60" class="center" style="font-size:12pt;">&rarr;</td>'+'<td width="70" style="text-align:right"><a href="/de/Account/Profile/'+insertRow.loser_user+'/">'+insertRow.loser_user+'</a></td>'+'<td width="35" rowspan="2" style="text-align:right"><img src="'+STATIC_SERVER+'img/heads/tiny/'+insertRow.loser_head+'.png" /></td>'+'</tr>'+'<tr>'+'<td>LVL '+insertRow.winner_head_level+'</td>'+'<td class="center" style="font-size:6pt;">'+insertRow.game+'</td>'+'<td style="text-align:right">LVL '+insertRow.loser_head_level+'</td>'+'</tr>'+'<tr><td colspan="5" style="border-bottom: 1px solid #555555; height:1px;"></td></tr></table>';divContainer.appendChild(innerDiv);divContainer.style.display="none";Element.insert($('latestStats'),{'top':divContainer});new Effect.Parallel([new Effect.SlideDown(divContainer),new Effect.Highlight(divContainer,{startcolor:'#808080',endcolor:'#505050'})],{duration:1});});}
function showTickerLoading()
{Effect.Appear('loadTicker',{duration:0.2,to:0.7});}
function hideTickerLoading()
{Effect.Fade('loadTicker',{duration:0.2});}
var isCurrentlyShown=0;var closeTimeout=500;var openTimeout=750;var effectDuration=0.2;var closetimer=new Object();var opentimer=new Object();var openAnimation;var closeAnimation;var openItem;var closeItems=new Object();function showSubmenu(menuItem)
{{cancelCloseSubmenuTimeout(menuItem);if(!Element.visible($(menuItem)))
{closeSubmenu();openItem=menuItem;opentimer[menuItem]=window.setTimeout(openSubmenu,openTimeout);}}}
function openSubmenu()
{if(!Element.visible($(openItem)))
{openAnimation=Effect.BlindDown(openItem,{duration:effectDuration,queue:{position:'end',scope:openItem,limit:1},afterFinish:function(){isCurrentlyShown=openItem;openAnimation=null;openItem=0;}});}}
function hideSubmenu(menuName)
{closeItems[menuName]=true;closetimer[menuName]=window.setTimeout(closeSubmenu,closeTimeout);}
function closeSubmenu()
{for(closeItem in closeItems)
{if($(closeItem).visible())
{isCurrentlyShown=null;closeAnimation=Effect.BlindUp(closeItem,{duration:effectDuration,queue:{position:'end',scope:closeItem,limit:2},afterFinish:function(){closeAnimation=null;closeItems[closeItem]=false;}});}}}
function cancelOpenSubmenuTimeout(menuItem)
{if(opentimer[menuItem])
{window.clearTimeout(opentimer[menuItem]);opentimer[menuItem]=null;}}
function cancelCloseSubmenuTimeout(menuItem)
{if(closetimer[menuItem])
{closeItems[menuItem]=false;window.clearTimeout(closetimer[menuItem]);closetimer[menuItem]=null;}}
function startPromoBoxUpdate(){window.setTimeout(updatePromoBox,10*1000);}
var bannerId=0;function updatePromoBox(){new Ajax.Request('/ajax/getPromoBanner.php',{parameters:{currentId:bannerId},method:'post',evalScripts:true,onComplete:function(transport)
{data=transport.responseText.evalJSON();new Effect.Fade('promoBox',{duration:0.2,to:0.01,afterFinish:function(){$('promoBox').style.backgroundImage="url("+data.img+")";$('promoBoxLink').href=data.url;$('promoBoxLink').target=data.tar;bannerId=data.id;new Effect.Appear('promoBox',{duration:0.2,afterFinish:function(){startPromoBoxUpdate();}});}});}});};var ProtoFlow=Class.create({initialize:function(elem,opt){opt=opt||{};this.options={startIndex:2,interval:60,slider:true,flex:110,captions:false,autoplay:false,autoplayInterval:5,useReflection:false,enableOnClickScroll:false,enableKeyboard:true,enableMouse:true};Object.extend(this.options,opt);this.useCaptions=this.options.captions;this.elem=$(elem);if(!this.elem)
return;this.elem.setStyle({overflow:"hidden",position:"relative"});this.imageStack=this.elem.select('img');if(this.options.captions!=false){this.captions=this.imageStack.pluck("alt");this.captionsCount=this.captions.size();}
if(this.options.useReflection){this.imageStack.each(function(elem){Reflection.add(elem,{height:1/4,opacity:2/3});}.bind(this));this.stack=this.elem.childElements();}
else{this.stack=this.imageStack;}
this.stackCount=(this.stack).size();if(this.useCaptions){this.captionHolder=new Element('div');this.captionHolder.className="captionHolder";this.captionHolder.setStyle({width:"100%",textAlign:"center",position:'absolute',left:"0px",top:(Element.getHeight(this.elem)-80)+"px"});this.elem.appendChild(this.captionHolder);}
this.currPos=this.options.startIndex-1;this.currIndex=this.currPos;if(this.options.slider){this.sliderContainer=new Element('div');this.sliderContainer.setStyle({width:'200px',height:'10px',position:'absolute',top:(Element.getHeight(this.elem)-30)+"px",left:(Element.getWidth(this.elem)/2-(137/2))+"px",zIndex:99999999});this.sliderTrack=new Element('div');this.sliderTrack.className="sliderTrack";this.sliderHandle=new Element('div');this.sliderHandle.className="sliderHandle";this.sliderTrack.appendChild(this.sliderHandle);this.sliderContainer.appendChild(this.sliderTrack);this.elem.appendChild(this.sliderContainer);this.slider=new Control.Slider(this.sliderHandle,this.sliderTrack,{range:$R(0,this.getStackCount()-1),sliderValue:this.getCurrentPos(),onSlide:this.handleSlider.bind(this),onChange:this.handleSlider.bind(this)});}
this.timer=0;this.stack.each(function(elem){elem.identify();if(this.options.enableOnClickScroll)
elem.observe('click',this.handleClick.bind(this));}.bind(this));if(this.options.enableOnClickScroll)
{this.disableLinks();}
this.goTo(this.currPos);this.autoplayer=null;if(this.options.autoplay){this.autoplayer=new PeriodicalExecuter(this.autoPlay.bind(this),this.options.autoplayInterval);}
if(this.options.enableKeyboard){document.observe('keyup',(function(e){var code=e.keyCode;if(37==code)this.previous();if(39==code)this.next();}).bind(this));}
if(this.options.enableMouse){var eventType=Prototype.Browser.Gecko?"DOMMouseScroll":"mousewheel";Event.observe(this.elem,eventType,(function(e){this.enableMouse(e);}).bind(this),false);if(this.useCaptions){Event.observe(this.captionHolder,eventType,(function(e){this.enableMouse(e);}).bind(this),false);}}
Event.observe(window,'resize',this.handleWindowResize.bind(this));},disableLinks:function(){this.elem.select("a").each(function(a){a.observe('click',function(e){e.preventDefault();});});},autoPlay:function(){if((this.currIndex+2)>this.stackCount){this.currIndex=0;}
this.currIndex=this.currIndex+1
this.goTo(this.currIndex);},handleWindowResize:function(event){},handleWheel:function(event){v=Event.wheel(event);this.goTo(this.currIndex+v);this.slider.setValue(this.currIndex+v);},handleSliderChange:function(index){this.goTo(index);},handleSlider:function(index){if(index)
this.goTo(index);},handleClick:function(e){var elem=Event.element(e);var v=elem.getAttribute("index");if(!v&&this.options.useReflection){elem=elem.up('a');v=elem.getAttribute("index");}
this.currIndex=v;this.goTo(v);this.updateSlider(v);},getCurrentPos:function(){return this.currPos;},goTo:function(index){this.slideTo(index*this.options.flex*-1);if(this.useCaptions){this.captionHolder.innerHTML=this.captions[Math.round(index)];}},updateSlider:function(index){if(this.options.slider)
this.slider.setValue(index);},step:function(){if(this.target<this.currPos-1||this.target>this.currPos+1){this.moveTo(this.currPos+(this.target-this.currPos)/5);window.setTimeout(this.step.bind(this),this.options.interval);this.timer=1;}
else{this.timer=0;}},slideTo:function(x){this.target=x;if(this.timer==0){window.setTimeout(this.step.bind(this),this.options.interval);this.timer=1;}},moveTo:function(currentPos){var x=currentPos;this.currPos=currentPos;var width=Element.getWidth(this.elem);var height=Element.getHeight(this.elem);var top=this.elem.offsetTop;var zIndex=this.stackCount;var flex=this.options.flex;this.stack.each(function(elem,index){Element.absolutize(elem);elem.setAttribute("index",index);var wsize=300;var hsize=300;if(this.options.useReflection){wsize=elem.select('img')[0].width;hsize=elem.select('img')[0].height;}else{wsize=elem.width;hsize=elem.height;}
if(this.options.useReflection){elem.down(1).setAttribute('index',index);}
var sign=1;if(x<0)
sign=-1;var mvt=Math.abs(x/flex/this.stackCount);if(mvt>0.2){mvt=Math.min(1,Math.pow(mvt,0.1));}else if(mvt>0.01){mvt=mvt*4;}
var nx=(width-wsize)/2+sign*(width-wsize-20)*mvt/2;var ny=(20+height-hsize)/2-(height-hsize-10)*mvt/2;halfWidth=width/2;diff=halfWidth-Math.abs(nx);op=1-(Math.abs(diff/halfWidth)/2);elem.setStyle({left:nx+'px',top:ny+'px',textAlign:"center"});elem.style.zIndex=zIndex;if(x<-(flex/2))
zIndex++;else
zIndex--;x+=this.options.flex;}.bind(this));},getStackCount:function(){return this.stackCount;},decreaseIndex:function(e){if(this.currIndex>0)
this.currIndex--;},increaseIndex:function(e){if(this.currIndex<this.getStackCount()-1)
this.currIndex++;},previous:function(e){this.decreaseIndex();this.toCurrentIndex();},next:function(e){this.increaseIndex();this.toCurrentIndex();},enableMouse:function(e){Event.wheel(e)<0?this.next():this.previous();Event.stop(e);},toCurrentIndex:function(e){this.goTo(this.currIndex);this.updateSlider(this.currIndex);}});Object.extend(Event,{wheel:function(event){var delta=0;if(!event)event=window.event;if(event.wheelDelta){delta=event.wheelDelta/120;if(window.opera)delta=-delta;}
else if(event.detail){delta=-event.detail/3;}
return Math.round(delta);}});if(!document.myGetElementsByClassName){document.myGetElementsByClassName=function(className){var children=document.getElementsByTagName('*')||document.all;var elements=new Array();for(var i=0;i<children.length;i++){var child=children[i];var classNames=child.className.split(' ');for(var j=0;j<classNames.length;j++){if(classNames[j]==className){elements.push(child);break;}}}
return elements;}}
var Reflection={defaultHeight:0.5,defaultOpacity:0.5,add:function(image,options){Reflection.remove(image);doptions={"height":Reflection.defaultHeight,"opacity":Reflection.defaultOpacity}
if(options){for(var i in doptions){if(!options[i]){options[i]=doptions[i];}}}else{options=doptions;}
try{var d=document.createElement('div');var p=image;var classes=p.className.split(' ');var newClasses='';for(j=0;j<classes.length;j++){if(classes[j]!="reflect"){if(newClasses){newClasses+=' '}
newClasses+=classes[j];}}
var reflectionHeight=Math.floor(p.height*options['height']);var divHeight=Math.floor(p.height*(1+options['height']));var reflectionWidth=p.width;if(document.all&&!window.opera){if(p.parentElement.tagName=='A'){var d=document.createElement('a');d.href=p.parentElement.href;}
d.className=newClasses;p.className='reflected';d.style.cssText=p.style.cssText;p.style.cssText='vertical-align: bottom';var reflection=document.createElement('img');reflection.src=p.src;reflection.style.width=reflectionWidth+'px';reflection.style.display='block';reflection.style.height=p.height+"px";reflection.style.marginBottom="-"+(p.height-reflectionHeight)+'px';reflection.style.filter='flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(options['opacity']*100)+', style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')';d.style.width=reflectionWidth+'px';d.style.height=divHeight+'px';p.parentNode.replaceChild(d,p);d.appendChild(p);d.appendChild(reflection);}else{var canvas=document.createElement('canvas');if(canvas.getContext){d.className=newClasses;p.className='reflected';d.style.cssText=p.style.cssText;p.style.cssText='vertical-align: bottom';var context=canvas.getContext("2d");canvas.style.height=reflectionHeight+'px';canvas.style.width=reflectionWidth+'px';canvas.height=reflectionHeight;canvas.width=reflectionWidth;d.style.width=reflectionWidth+'px';d.style.height=divHeight+'px';p.parentNode.replaceChild(d,p);d.appendChild(p);d.appendChild(canvas);context.save();context.translate(0,image.height-1);context.scale(1,-1);context.drawImage(image,0,0,reflectionWidth,image.height);context.restore();context.globalCompositeOperation="destination-out";var gradient=context.createLinearGradient(0,0,0,reflectionHeight);gradient.addColorStop(1,"rgba(255, 255, 255, 1.0)");gradient.addColorStop(0,"rgba(255, 255, 255, "+(1-options['opacity'])+")");context.fillStyle=gradient;context.rect(0,0,reflectionWidth,reflectionHeight*2);context.fill();}}}catch(e){}},remove:function(image){if(image.className=="reflected"){image.className=image.parentNode.className;image.parentNode.parentNode.replaceChild(image,image.parentNode);}}}
function addReflections(){var rimages=document.myGetElementsByClassName('reflect');for(i=0;i<rimages.length;i++){var rheight=null;var ropacity=null;var classes=rimages[i].className.split(' ');for(j=0;j<classes.length;j++){if(classes[j].indexOf("rheight")==0){var rheight=classes[j].substring(7)/100;}else if(classes[j].indexOf("ropacity")==0){var ropacity=classes[j].substring(8)/100;}}
Reflection.add(rimages[i],{height:rheight,opacity:ropacity});}}
var previousOnload=window.onload;window.onload=function(){if(previousOnload)previousOnload();addReflections();}
