
var oServices;var openbox_my_services={'browse_all':false,'category_id':0,'load':function(params)
{if(first_services_js)
{oServices=first_services_js||{};first_services_js=null;openbox_my_services.filter_prepare();openbox_my_services.display();return;}
if(params&&typeof(params.category_id)!='undefined')
{openbox_my_services.category_id=params.category_id;}
openbox_my_services.show_loading();openbox_my_services.show_header();var query={browse:browse,category_id:openbox_my_services.category_id};var q=$j.box.formatQuery(query);var url=site_root+'index.php?rm=box_get_services';$j.getJSON(url,q,function(json)
{if(!json)return;oServices=json.services||{};openbox_my_services.display();});},'display':function(new_display_mode,param)
{var servicesElements=[];var i=0;if(oServices.toString())
{for(i in oServices)
{var service=new Service({actions:oServices[i].actions,description:oServices[i].description,logo_url:oServices[i].logo_url,favicon_url:oServices[i].favicon_url,name:oServices[i].name,service_id:oServices[i].service_id,service_url:oServices[i].service_url,site_url:oServices[i].site_url,user_has_service:oServices[i].user_has_service});servicesElements.push(service.render());}
$j('#service_list').empty().append(servicesElements);$j('#'+i).css('border','none');return;}
var empty_note=(browse=='all'||browse=='featured')?$j('#note_empty_not_added'):$j('#note_empty_added');empty_note.clone().css('display','block');$j('#service_list').empty().append(empty_note).addClass('empty_list');},'show_loading':function()
{$j('#service_list').empty();$j('#loading_div').clone().css('display','block').appendTo($j('#service_list'));},'show_header':function()
{if(browse=='all')
{$j('.title').text($t('All Public OpenBox Services','services_js_title_all_openbox'));openbox_my_services.browse_all=false;return;}
$j('.title').text($t('My OpenBox Services','services_js_title_my_openbox'));openbox_my_services.browse_all=true;},'toggle_action':function(p)
{var service_id=p.parentNode.parentNode.parentNode.parentNode.parentNode.id;var added_actions_count=0;var service=null;var action_added=false;for(var i in oServices[service_id].actions)
{var service2=oServices[service_id];if(service2.actions[i].service_action_id==p.value)
{service=new Service({actions:service2.actions,description:service2.description,logo_url:service2.logo_url.indexOf('/.jpg')>0?'/img/box_openbox_img1.gif':oServices[service_id].logo_url,favicon_url:service2.favicon_url,name:service2.name,service_id:service2.service_id,service_url:service2.service_url,user_has_service:service2.user_has_service});action_added=service2.actions[i].user_attached?true:false;}
if(service2.actions[i].user_attached)added_actions_count++;}
if(added_actions_count==1&&action_added)
{openbox_my_services.popup_remove_service_open(service_id);openbox_my_services.display();return false;}
var query={action_id:p.value,add:p.checked?1:null};var q=$j.box.formatQuery(query);var url=site_root+'index.php?rm=box_services_toggle_action';$j.getJSON(url,q,function(json)
{var show_service=false;for(var i in oServices[service_id].actions)
{var actions=oServices[service_id].actions[i];if(actions.service_action_id==p.value)actions.user_attached=p.checked;if(actions.user_attached)
{show_service=true;oServices[service_id].user_has_service=true;}}
if(!show_service)
{delete oServices[service_id];$j('#'+service_id).remove();}
openbox_my_services.display();});},current_service_id:null,'popup_add_service_open':function(service_id)
{if(!service_id)return false;openbox_my_services.current_service_id=service_id;simpleBodyBlocker.create();$('global_blocker').onclick=openbox_my_services.popup_wrapper_cancel;$j('#popup_box_wrapper_content').empty();$('popup_box_wrapper_content').appendChild($('popup_service_part').cloneNode(true));$('popup_box_wrapper_content').childNodes[0].childNodes[0].innerHTML=$t('You are about to add %1 to your Box account. By adding this OpenBox service, you are granting this service access to the files you use the service with.','js_services_js_popup_add_text',$j.text(oServices[service_id].name));$j('#popup_box_wrapper_title').html($t('Add %1 service','js_services_js_popup_add_title',$j.text(oServices[service_id].name)));$j('#popup_box_wrapper_title').css('background-image','url(\''+oServices[service_id].favicon_url+'\')');popup_wrapper_submit_callback=openbox_my_services.popup_add_service_submit;system.set_popup_position($('popup_box_wrapper'));$j('#popup_box_wrapper').css('display','block');},'popup_add_service_submit':function()
{openbox_my_services.popup_wrapper_cancel();var query={service_id:openbox_my_services.current_service_id};var q=$j.box.formatQuery(query);var url=site_root+'index.php?rm=box_add_service';var service=oServices[query.service_id];$j.getJSON(url,q,function(json)
{if(json.result!='success')return;service.user_has_service=true;for(var i=0;i<service.actions.length;i++)
{service.actions[i].user_attached=1;}
openbox_my_services.display();return false;});},'popup_remove_service_open':function(service_id)
{openbox_my_services.current_service_id=service_id;simpleBodyBlocker.create();$('global_blocker').onclick=openbox_my_services.popup_wrapper_cancel;$j('#popup_box_wrapper_content').empty();$('popup_box_wrapper_content').appendChild($('popup_service_part').cloneNode(true));$('popup_box_wrapper_content').childNodes[0].childNodes[0].innerHTML=$t('You are about to remove %1 from your Box account. By doing so, you will no longer be able to send files to this service.','js_services_js_popup_text',$j.text(oServices[service_id].name));$j('#popup_box_wrapper_title').html($t('Remove %1 service','js_services_js_popup_remove_title',$j.text(oServices[service_id].name)));$j('#popup_box_wrapper_title').css('background-image','url(\''+oServices[service_id].favicon_url+'\')');popup_wrapper_submit_callback=openbox_my_services.popup_remove_service_submit;system.set_popup_position($('popup_box_wrapper'));$j('#popup_box_wrapper').css('display','block');},'popup_remove_service_submit':function()
{openbox_my_services.popup_wrapper_cancel();var service_id=openbox_my_services.current_service_id;var query={service_id:service_id};var q=$j.box.formatQuery(query);var url=site_root+'index.php?rm=box_remove_service';$j.getJSON(url,q,function(json)
{if(json.result!='success')return;oServices[service_id].user_has_service=false;if(browse=='all')
{openbox_my_services.display();return;}
$j('#'+service_id).remove();delete oServices[service_id];var added_services_count=0;for(i in oServices)added_services_count++;if(added_services_count==0)oServices='';openbox_my_services.display();});},'popup_wrapper_submit':function()
{if(popup_wrapper_submit_callback)popup_wrapper_submit_callback();},'popup_wrapper_cancel':function()
{$j('#popup_box_wrapper').fadeOut("fast",openbox_my_services.popup_wrapper_cancel_callback);current_service_id=null;},'popup_wrapper_cancel_callback':function()
{$('popup_box_wrapper').style.display='none';$('popup_box_wrapper_content').style.marginTop='19px';simpleBodyBlocker.destroy();},'filter_timout_id':null,'filter_hide':function()
{clearTimeout(openbox_my_services.filter_timout_id);openbox_my_services.filter_timout_id=null;$j('#filter_categories_list').hide();},'filter_mouseout':function()
{if(!openbox_my_services.filter_timout_id)openbox_my_services.filter_timout_id=setTimeout(openbox_my_services.filter_hide,50);},'filter_mouseover':function()
{if(!openbox_my_services.filter_timout_id)return;clearTimeout(openbox_my_services.filter_timout_id);openbox_my_services.filter_timout_id=null;},'filter_prepare':function()
{var me=this;var list=$j('#filter_categories_list');$j('.filter_list_item').click(function()
{var c=$j(this);$j('#filter_categories_current').text(c.text());openbox_my_services.load({category_id:c.attr('cid')});list.hide();}).hover(function()
{$j(this).addClass('filter_list_item-hover');me.filter_mouseover();},function()
{$j(this).removeClass('filter_list_item-hover');me.filter_mouseout()});list.hover(me.filter_mouseover,me.filter_mouseout);$j('#filter_categories_current').click(function()
{var offset=$j(this).offset();list.css({top:offset.top+20,left:offset.left,display:'block'});}).mouseout(me.filter_mouseout);}};var Service=function(params)
{params=params||{};this.actions=params.actions||{};this.description=params.description||'';this.faviconUrl=params.favicon_url||'';this.logoUrl=params.logo_url||'/img/box_openbox_img1.gif';this.name=params.name||'';this.serviceId=params.service_id||'';this.serviceUrl=params.service_url||'';this.siteUrl=params.site_url||'';this.userHasService=params.user_has_service||false;};Service.prototype={actions:null,description:null,element:null,faviconUrl:null,name:null,serviceId:null,serviceUrl:null,userHasService:null,render:function()
{var service=$j('#tpl_service').clone().attr('id',this.serviceId);var is_application=!this.actions.length;var parts={image:service.find('.image'),name:service.find('.service_name'),description:service.find('.text'),addedNote:service.find('.note'),actionButtons:service.find('.actions'),serviceActions:service.find('.service_actions')};parts.image.find('a').attr('href',this.serviceUrl);parts.image.find('img').attr('src',this.logoUrl);parts.name.find('img').attr('src',this.faviconUrl);parts.name.find('a').attr('href',this.serviceUrl).slice(0,1).text(this.name);parts.description.text(this.description);var has_free_action=false;for(var i in this.actions)
{if(this.actions[i].free==1)
{has_free_action=true;}}
for(var i in this.actions)
{var serviceAction=$j('#service_action').clone().attr('id',this.actions[i].service_action_id);serviceAction.find('label').attr('value',this.actions[i].service_action_id);if(browse=='all'||browse=='featured')
{serviceAction.find('label').text(this.actions[i].name+':');}
else
{serviceAction.find('label input').attr({checked:this.actions[i].user_attached?'checked':false,defaultChecked:this.actions[i].user_attached?true:false,value:this.actions[i].service_action_id});serviceAction.find('label').append(this.actions[i].name+':');}
if(this.actions[i].free==1)
{}
else
{serviceAction.find('label').append('<span class="premium">premium</span>');if(has_free_action)
{serviceAction.find('label').parent().addClass('premium_only');if(free_user)
{serviceAction.find('label').prepend('<span class="upgrade">'+$t('This action is only available for business & premium accounts','openbox_action_available_for_premium_only')+'. <a href="/settings/billing">'+$t('Upgrade','js_openbox_upgrade')+'</a></span>').click(function(){window.location='/settings/billing';return false;});}}}
if(this.actions[i].description)
{serviceAction.find('> span').text(' '+this.actions[i].description);}
if(this.actions[i].status=='development')
{serviceAction.find('span').append('<span style="font-size:12px;font-weight:bold;color:#c00;"> '+$t('in development (action visible only because you are a developer)','services_js_item_development')+'</span></div>');}
serviceAction.css('display','block');parts.serviceActions.append(serviceAction);}
if(this.userHasService===true)
{parts.addedNote.text($t('You have this application','services_js_item_you_have'));parts.actionButtons.find('a span span').attr('class','btn_icon_remove').text($t('Remove Application','services_js_item_remove'));parts.actionButtons.find('a').bind('click',function(){openbox_my_services.popup_remove_service_open(this.parentNode.parentNode.id);return false;});}
else
{if(logged_in)
{parts.actionButtons.find('a').bind('click',function(){openbox_my_services.popup_add_service_open(this.parentNode.parentNode.id);return false;});}
if(!is_application)
{if(has_free_action)
{parts.actionButtons.find('a span span').attr('class','btn_icon_add').text($t('Add Application','js_services_js_item_add_service'));parts.addedNote.parent().removeClass('premium_only');}
else
{if(free_user)
{parts.actionButtons.find('a span span').attr('class','btn_icon_add').text($t('Upgrade','js_openbox_upgrade'));parts.actionButtons.find('a').unbind().attr('href','/settings/billing');}
else
{parts.actionButtons.find('a span span').attr('class','btn_icon_add').text($t('Add Application','js_services_js_item_add_service'));}
parts.addedNote.text($t('This service is only available for business & premium accounts','openbox_service_available_for_premium_only')).parent().addClass('premium_only');}}
else
{parts.actionButtons.find('a').unbind().attr('href',this.siteUrl);parts.actionButtons.find('a span span').attr('class','btn_icon_app').text($t('Get Application','services_js_item_get_application'));}}
service.css('display','block');delete parts;this.element=service.get(0);return this.element;}};