/*
 * Webvanta Setup for CMS Admin access
 * Copyright (c) 2009 Webvanta Inc
 */

// Depends on WebvantaBootstrap.js loading first
if (WebvantaVersions)
  wv_jQuery = WebvantaVersions.use('jquery','latest');
if (wv_jQuery) {
  wv_jQuery(document).ready(function(jQuery) {
    if (WebvantaAdmin.isAdmin()) {
      jQuery.ajaxSetup({cache: true});
      jQuery('<link rel="stylesheet" type="text/css" href="/javascripts/yui/2.7.0b/build/assets/skins/sam/skin.css" media="screen" />').prependTo('head');
      jQuery('<link rel="stylesheet" type="text/css" href="/stylesheets/admin/webvanta-editor-1.0.0.css" media="screen" />').appendTo('head');
      jQuery('<link rel="stylesheet" type="text/css" href="/stylesheets/admin/webvanta-code-editor-1.0.0.css" media="screen" />').appendTo('head');
      jQuery("<style>\n#webvanta-toolbar #wvtop { background: url('/images/admin/cp_bar_background.gif') repeat-x !important; margin: 0 !important; padding: 0 !important; position: fixed !important; width: 100% !important; z-index: 999999 !important; height: 39px !important; left: 0 !important; top: 0 !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop .wv-logo { float: left !important; padding: 3px 10px 0 20px !important; margin: 0 !important; border: none !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop .site_name { float: left !important; padding: 3px 0 0 10px !important; margin-top: 10px !important; border-left: 1px solid #333 !important; font-size: 12px !important; font-family: Arial,Helvetica,sans-serif !important; color: #000 !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop ul { padding: 0 10px !important; margin: 0 !important; position: relative !important; top: 5px !important; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; float: right !important; clear: none !important; } \n #webvanta-toolbar #wvtop ul a, #webvanta-toolbar #wvtop ul p { -moz-border-radius: 0px !important; -webkit-border-radius: 0px !important; opacity: 1.0 !important; } \n #webvanta-toolbar #wvtop ul .topbar_button_proxy a:link,#wvtop ul .topbar_button_proxy a:visited { text-decoration: none !important; width: 102px !important; height: 18px !important; padding: 5px 0 0 0 !important; margin: 0 !important; display: block; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop ul .topbar_button_proxy a:hover { text-decoration: none !important; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop ul .topbar_button a:link,#wvtop ul .topbar_button a:visited { text-decoration: none !important; color: #fff !important; background: #666 !important; width: 102px !important; height: 18px !important; padding: 5px 0 0 0 !important; margin: 0 !important; display: block; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop ul #clear_cache_btn.topbar_button a:link,#wvtop ul #clear_cache_btn.topbar_button a:visited { text-decoration: none !important; color: #fff !important; background: #622 !important; width: 102px !important; height: 18px !important; padding: 5px 0 0 0 !important; margin: 0 !important; display: block; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop ul .topbar_button a:hover, #webvanta-toolbar #wvtop ul #clear_cache_btn.topbar_button a:hover { text-decoration: none !important; color: #fff !important; background: #660 !important; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop li { float: left !important; display: block; list-style-type: none !important; font-size: 10px !important; font-weight: bold !important; margin: 0 10px 0 0 !important; padding: 0 !important; text-align: center !important; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop .topbar_link { margin: 0 10px 0 0 !important; text-align: center !important; text-decoration: none !important; padding: 5px 10px 0 0 !important; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop .topbar_link a { background-color: transparent !important; } \n #webvanta-toolbar #wvtop .topbar_link a:link,#wvtop .topbar_link a:visited { color: #000 !important; font-weight: normal !important; text-decoration: none !important; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-toolbar #wvtop .topbar_link a:hover,#wvtop .topbar_link a:active { text-decoration: underline !important; font-family: Arial,Helvetica,sans-serif !important; line-height: 12px !important; } \n #webvanta-msg .alert { color: red; font-family: arial,verdana,sans-serif; font-size: 14px; font-style: normal; font-weight: normal; margin: 0; padding: 0; } \n\n\n</style>").appendTo('head');
      jQuery("<div id='webvanta-msg' style='display:none'>").insertBefore("#webvanta-features");
      jQuery('<div id="webvanta-toolbar">').insertBefore('#webvanta-features').html("<div id='wvtop'><img src='/images/admin/webvanta_logo_admin.png' class='wv-logo' /><p class='site_name'></p><ul style='float:right'><li class='topbar_link'><a href='http://www.webvanta.com/help' target='_blank'>HELP &amp; TUTORIALS</a></li><li class='topbar_link'><a href='/logout'>SIGN OUT</a></li><li id='clear_cache_btn' class='topbar_button'><a href='#' onclick=\"jQuery.get('/admin/a/clear_page_cache', {}, function(d) {jQuery('#webvanta-msg').html(d).dialog('open');});return false;\">CLEAR</a></li><li id='edit_mode_proxy' class='topbar_button_proxy'><a href='#'></a></li><li id='edit_mode_enable' class='topbar_button' style='display:none;'><a href='#' onclick=\"YAHOO.webvanta.enableEditMode(); return false;\">ENABLE EDITING</a></li><li id='edit_mode_disable' class='topbar_button' style='display:none;'><a href='#' onclick=\"YAHOO.webvanta.disableEditMode(); return false;\">DISABLE EDITING</a></li><li class='topbar_button'><a href='/a'>CONTROL PANEL</a></li></ul></div>");
      jQuery('#webvanta-toolbar #wvtop .site_name').html(WebvantaAdmin.getUIRValue('company_name'));
      jQuery('#webvanta-wrapper').css({'position' : 'relative', 'top' : '39px'});
      jQuery('<script type="text/javascript" src="/javascripts/admin/webvanta-yui-1.0.0.js"></script>').appendTo('head');
      jQuery('<script type="text/javascript">if (typeof(jQuery) == "undefined") jQuery = WebvantaVersions.use("jquery","latest");</script>').appendTo('head');
      jQuery('<script type="text/javascript" src="/webvanta/js/jquery/1.3/jquery-ui-1.7.2.full.min.js"></script>').appendTo('head');
      jQuery('<script type="text/javascript" src="/javascripts/admin/codemirror-0.65.2009111501/js/codemirror.js"></script>').appendTo('head');
      jQuery('<script type="text/javascript" src="/javascripts/admin/codemirror-0.65.2009111501/js/util.js"></script>').appendTo('head');
      jQuery('<script type="text/javascript" src="/javascripts/admin/fckeditor-2.6.5/fckeditor.js"></script>').appendTo('head');
      jQuery('<script type="text/javascript" src="/javascripts/admin/webvanta-editor-1.0.0.js"></script>').appendTo('head');
      jQuery('<script type="text/javascript" src="/javascripts/admin/webvanta-rte-1.0.0.js"></script>').appendTo('head');
      jQuery('<script type="text/javascript">jQuery("#webvanta-msg").dialog({dialogClass:"webvanta-dialogs",bgiframe: true,resizable:false,autoOpen:false,width:400,height:200,modal:true,zIndex:999999,title:"Webvanta Message",overlay:{backgroundColor: "#000",opacity: 0.5},open:function(e,u){this.to=window.setTimeout(function(){jQuery(\"#webvanta-msg\").dialog(\"close\")},3000)},beforeclose:function(e,u){window.clearTimeout(this.to)},buttons:{"OK":function(){jQuery(this).dialog("close");}}});</script>').appendTo('head');      
    }
  });
}