
Login={worlds:null,fetchedFor:'',init:function(){$('#loginform').bind('submit',function(){Login.showWorlds();return false;});$('#loginform .login_fields').bind('keyup',function(evt){if(13==evt.keyCode){$('#loginform').submit();}});},fetchWorlds:function(showWorldsAfterFetch){var data={};data.name=$.trim($("#name").val());data.password=$.trim($("#password").val());data.passwordhash=$.trim($("#passwordhash").val());if(data.name===Login.fetchedFor){return false;}
Ajax.post('/start/index?action=ajax_played_worlds',null,data,function(return_data){Login.worlds=return_data;Login.fetchedFor=data.name;if(typeof(showWorldsAfterFetch)!=='undefined'){Login.showWorlds();}},{},null,false,false);return true;},showWorlds:function(facebook_login){if(Login.worlds===null){Login.fetchWorlds(true);return;}
var div=$('#worlds').length?$('#worlds'):$('<div id="worlds"><div><ul></ul></div></div>');var ul=div.find('ul').empty();var worlds_not_playing=0;$(Login.worlds).each(function(){var world=this;if(world.playing_on){var li=$('<li><a></a></li>');li.find('a').text(world.name).click(function(){$('#world').val(world.id);$('#loginform').unbind().submit();});ul.append(li);}else{worlds_not_playing++;}});if(worlds_not_playing>0){var li=$('<li><a></a></li>');li.find('a').text('other worlds').click(function(){$('#world').val('');$('#loginform').unbind().submit();});ul.append(li);}
var logout_button=$('<li><a class="logout_button" href="#"></a></li>');logout_button.find('a').text('Logout').click(function(){Login.logoutMasterAccount();return false;});ul.append(logout_button);if(facebook_login==true){$('#facebook_login').val('1');}
$('#loginform').append(div);$('#loginform .loginform-inner').hide();if(navigator.userAgent.toLowerCase().indexOf('msie')>-1){div.show();}else{div.hide().slideDown('fast');}
return;},fetchWorldsForFacebookUser:function(){if(Login.worlds){return;}
Ajax.post('/start/index?action=ajax_played_worlds_for_facebook_user',null,{},function(data){if(data=='no_account'||data=='no_login'){return;}
Login.worlds=data;Login.showWorlds(true);},{},null,false,false);},removeAutologinCookie:function(){$.cookie('autologin','');Login.logoutMasterAccount();return false;},logoutMasterAccount:function(){$('#worlds').hide();$('#remembered').remove();$('#loginform .loginform-inner').show();$('#login_form_inner').show();$('#password').val("");}};var Screenshots={init:function(){Screenshots.target_elm=$('#screenshots-target');Screenshots.target_elm.bind('click',Screenshots.onClickTarget);$('#screenshots').find('a img').bind('click',Screenshots.onClickThumb);$(document).bind('keydown',Screenshots.onKeyDown);return false;},onClickThumb:function(evt){var thumb_elm=$(evt.target),src=thumb_elm.attr('src').replace('_thumb','');Screenshots.show(src);return false;},onClickTarget:function(evt){Screenshots.target_elm.fadeOut('fast');return false;},onKeyDown:function(evt){try{if(27==evt.keyCode){Screenshots.target_elm.fadeOut('fast');}}catch(e){}},show:function(src){var img_elm=$(document.createElement('img'));img_elm.attr('src',src);Screenshots.target_elm.empty();Screenshots.target_elm.append(img_elm);Screenshots.target_elm.fadeIn('fast');return false;}};var Register={init:function(){$('#name').bind('blur',{element:'#name'},Register.preCheckFor);$('#password_confirmation').bind('blur',Register.checkPasswordConfirmation);$('#email').bind('blur',{element:'#email'},Register.preCheckFor);},checkPasswordConfirmation:function(){var password=$('#password').val();var password_confirmation=$('#password_confirmation').val();var status=$('#password_confirmation_status');if(password!=password_confirmation){status.html('The two entered passwords don\'t match!').show();}else{status.hide();}},preCheckFor:function(event){var action='';var element=event.data.element;switch(element){case'#name':action='check_player_name_availability';break;case'#email':action='check_email_availability';break;}
var value=$(this).val();if(action!=''&&value!=''){$.getJSON('start/index',{'action':action,'value':value},function(data){var status=$(element+'_status');if(data.result=='false'){status.html(data.message).show();}else{status.hide();}});}},register:function(){$.post('start/index?action=register',$('#register_form').serializeArray(),function(data){console.log(data);},'json');}};var LandingPage=function(options){if(options.replace_flash&&(f=document.getElementById('flash-zeus'))){var c=document.getElementById('content');if(f.data){f.data=f.data.replace('zeus','hera');}
c.appendChild(f);f.id='flash-hera';$('#gamebar_content').css({backgroundImage:'none'});}
if(options.no_icons){$('#icons').remove();}};var FlashPlayer={elm:{},fp:null,prev_volume:100,muted:false,fade_timeout:null,onInit:function(){(this.fp=document.getElementById('flashplayer')).SetVariable('method:setUrl','http://static.grepolis.com/images/start/flash/grepo_final_de.flv');this.fp.SetVariable('method:loadMovieOnTop','http://static.grepolis.com/images/start/flashplayer_overlay_play.png|1||');this.elm.play=$('#fp_controls a.pause');this.elm.volume=$('#fp_controls a.volume');this.elm.vol_control=$('#fp_volume_control');this.elm.vol_inp=$('#fp_volume');this.elm.inp=$('#fp_time');this.elm.timeline=$('#fp_timeline');this.elm.slider=new Slider({elementInput:this.elm.inp,elementSlider:this.elm.timeline});this.elm.vol_slider=new Slider({elementInput:this.elm.vol_inp,elementSlider:this.elm.vol_control});this.elm.vol_slider.setValue(this.elm.vol_slider.getMax());this.elm.handle=this.elm.timeline.find('.ui-slider-handle');this.elm.vol_control.bind('change',function(){FlashPlayer.setVolume(FlashPlayer.elm.vol_inp.val());})
this.elm.timeline.bind('change',function(){var new_pos=FlashPlayer.duration/100*FlashPlayer.elm.inp.val();FlashPlayer.fp.SetVariable('method:setPosition',new_pos);});},onClick:function(){this.togglePlay();},onKeyUp:function(){},onFinished:function(){},onUpdate:function(){this.setHandlePosition({animate:true});},setHandlePosition:function(options){var new_pc=~~(FlashPlayer.position/FlashPlayer.duration*10000)/100;var css={left:new_pc+'%'};if(options&&options.animate&&this.elm.handle){this.elm.handle.stop(true,true).animate(css,{duration:500,easing:'linear'});}else{this.elm.handle.css(css);}},togglePlay:function(){this.fp=this.fp||document.getElementById('flashplayer');this.fp.SetVariable('method:unloadMovieOnTop','1');var method=this.isPlaying==='true'?'pause':'play';this.elm.play.attr('class',method);if(this.isPlaying==='true'){this.fp.SetVariable('method:loadMovieOnTop','http://static.grepolis.com/images/start/flashplayer_overlay_pause.png|1||');}
this.fp.SetVariable('method:'+method,'');this.setHandlePosition();},showVolumeControl:function(){window.clearTimeout(this.hide_timeout);this.hide_timeout=window.setTimeout(function(){var elm=FlashPlayer.elm,pos=elm.volume.position();pos.top+=12,pos.left+=22;elm.vol_control.css(pos).stop(true,true).fadeIn();elm.vol_control.unbind('mouseenter').bind('mouseenter',function(){FlashPlayer.elm.volume.unbind('mouseleave.nodrag');window.clearTimeout(window.vc_to);});elm.vol_control.unbind('mouseleave').bind('mouseleave',function(){FlashPlayer.elm.vol_control.fadeOut();});elm.volume.unbind('mouseleave.nodrag').bind('mouseleave.nodrag',function(){window.vc_to=window.setTimeout(function(){FlashPlayer.elm.vol_control.fadeOut();},750);});},300);return false;},setVolume:function(vol){this.fp.SetVariable('method:setVolume',vol);},mute:function(){this.elm.vol_slider.setValue(this.muted?this.prev_volume:0);this.elm.volume.toggleClass('muted');this.muted=!this.muted;}};