function Preview()
{
  jQuery("#preview").attr("value", "1");
}

function Save()
{
  // publish
  jQuery('#hire_published, #project_published, #news_published, #paper_published').attr("value", "1"); 
}

function saveAsUnpublished()
{
  // TODO 
  jQuery('#hire_published, #project_published, #news_published, #paper_published').attr("value", "0");
}

// For flash to write anchor to remember the current flash
function writeAnchor(anchor)
{
	window.location.hash = anchor;
}

(function($)
{  
  $(function(){
    $("a[rel*=new_window]").click(
      function()
      {
        window.open($(this).attr('href'), "mainPop");
        return false;
      }
    );
  
    // flash remember
    hash = window.location.hash;
    if(hash)
    {
      hash = hash.substring(1);
      $("#contentFrame").attr('src', hash);
      
      // update flash param string
      url = hash.split('/');
      main = url[1];
      sub  = url[2];
      
      if(sub == "catalog")
      {
        //alert(url[3]);
        sub = url[3];
      }
      // update flash vars
      $("#flash-vars").attr('value', "main=" + main + "&" + "sub=" + sub);
      $("#myFlash embed").attr('flashvars', "main=" + main + "&" + "sub=" + sub);
    }  
  
    // admin input
    $('input:text').css('width', '200px');
    $('input:password').css('width', '200px');
  
  	if($.fn.datepicker)
	{
		// date picker
		$('.has_datepicker').datepicker();
	}
    
    // delete link
    $("#delete_link").click(function(){
      $("#delete_form").submit();
    });
    //
    $("#select_all").click(function(){
      // TODO Reeze: if($(this).
    });
    
    // initialize notice motion
    $("#notice").fadeIn('slow');

    
    // pop tip
    $("#methods span").hover(
      function()
      {
        $(this).children(".pop_tip").css("text-decoration", "none");
        $(this).children(".pop_tip").fadeIn();
      },
      
      function()
      {
        $(this).children(".pop_tip").fadeOut();
      }
    );

    $("#tpl_selector").change(
      function()
      {
        window.location = jQuery("#tpl_selector option:selected").attr('value');
      }
    );
    
    // admin checkbox select all
    $("#select_all").change(
      function()
      {
        if($(this).attr('checked') == false)
        {
          $('input:checkbox').attr('checked', false);
        }
        else
        {
          $('input:checkbox').attr('checked', true);
        }
      }
    );
    
    $("#publish_btn").click(function(){Save();});
    $("#preview_btn").click(function(){Preview();});
    $("#save_draft_btn").click(function(){saveAsUnpublished();});
    
  });
})(jQuery);

