function setup(){

    $('.title').each(function () {
        $(this).unbind("focus").focus(function () {
            if( this.value == "Enter Title Here" ) {
                this.value = "";
            }
        }).unbind("blur").blur(function() {
            if( !this.value.length ) {
                this.value = "Enter Title Here";
            }
        });
    });

	//Setup Detail onHover 
    $("div.manager ul li").unbind("hover").hover(function(){ 
			$("div.picinfo",this).show();
			$(this).addClass("blue");
        }, 
         function() { 
			$("div.picinfo",this).hide();
			$(this).removeClass("blue");
         } 
    );
    
    //Setup picinfo onHover 
    $("div.picinfo").unbind("hover").hover(function(){ 
			$(this).fadeTo("fast", 1);
        }, 
         function() { 
			$(this).fadeTo("fast", 0.5);
         } 
    );
    
    //reset all picinfos - fade opacity
    $("div.picinfo").each(function(){
		$(this).fadeTo("fast", 0.5);
    });

    // Edit Image Details
	$("a.edit").unbind("click").click(function(){
		$(this).parent().parent().parent().children("div.picedit").show();
	});
	
	// Delete Image
	$("a.del").each(
		function( intIndex ){
		$(this).unbind("click");
		$(this).bind (
			"click",
			function(){
			if (confirm ("Are you sure you want to delete this image?")) {
				//delfile
				$(this).parent().parent().parent().addClass("red");
                $('#hidden').load("proc.htm?cmd=deli&id="+($(this).parent().children("form").children("input.did").val()));
                $(this).parent().parent().parent().fadeOut("slow");
                $(this).parent().parent().parent().remove();
			}
			return false;
		});
	});

	
	// Cancel Save
	$("input.cancel").unbind("click").click(function(){
		$(this).parent().parent().parent().parent().children("div.picedit").hide();
		$(this).parent().parent().parent().parent().children(".saving").html("<div><font color=red>Save Cancelled</font></div>");
		$(this).parent().parent().parent().parent().children(".saving").fadeOut("slow",function(){
			$(this).parent().parent().parent().parent().children(".saving").remove();
		});
	});
    
    
    //Update Pic Info -- Form Submit
	$(".picupdate").unbind("submit").submit(function() {
		//Show Saving Box
		$("div#saving-hide").children(".saving").clone().appendTo($(this).parent().parent());
		
		//Post Save
		var tmpid = $("input.id",this).val();
		var tmptitle = $("input.title",this).val();
		var tmpcategory = $("select",this).val();
        //var tmpcategoryC = $("select",this).children("[@selected]").text();
		var dataString = 'cmd=savei&id='+ tmpid + '&title=' + escape(tmptitle) + '&category=' + tmpcategory;
        $("#hidden").load("proc.htm?"+dataString);
   
        //Update Div.picInfo
       // $(this).parent().parent().children(".picinfo").children("span.title").html($(tmptitle).val());
        //$(this).parent().parent().children(".picinfo").children("span.category").html($(tmpcategory).val());
        $(this).parent().parent().children(".picinfo").children("span.title").html($("input.title",this).val());
        $(this).parent().parent().children(".picinfo").children("span.category").html($("select",this).val());

        //Hide the edit div
        $(this).parent().parent().children(".picedit").hide();

        //Remove Saving Box
        $(this).parent().parent().children(".saving").addClass("green");
        $(this).parent().parent().children(".saving").html("<div><img src='images/check.png' align='absmiddle' /><font color=green><b>SUCCESS</b></font></div>");
        $(this).parent().parent().children(".saving").fadeOut("slow",function(){
            $(this).parent().parent().children(".saving").remove();
        });

		return false;
	});
		
	}
	

function addPic(id, filename, title, category) {
    if (title.length == 0) { 
        tmptitle = "Enter Title Here";
    } else {
        tmptitle = title;
    }
    $("#photolist li:last").clone().prependTo($("#photolist"));
    $("#photolist li:first div.picedit form input.id").attr("value",id);
    $("#photolist li:first div.picinfo form input.did").attr("value",id);

    $("#photolist li:first div.picedit form input.title").attr("value",tmptitle);
    //$("#photolist li:first div.picinfo form select").selectOptions(category);
    
    $("#photolist li:first div.picinfo span.title").html(tmptitle);
    $("#photolist li:first div.picinfo span.category").html(category);
    $("#photolist li:first img").attr("src", "photos/"+filename+".jpg?width=300&height=200&cropratio=1:1&image=/photos/"+filename);
    $("#photolist li:first").fadeIn("slow");
    //alert("test");
}

function CleanupSuccess(obj) {
	//Update Div.picInfo
	$(obj[0]).children(".picinfo").children("span.title").html($("input.title",obj[0]).val());
	$(obj[0]).children(".picinfo").children("span.category").html($("select",obj[0]).val());
	
	//Hide the edit div
	$(obj[0]).children(".picedit").hide();
	
	//Remove Saving Box
	$(obj[0]).children(".saving").addClass("green");
	$(obj[0]).children(".saving").html("<div><img src='images/check.png' align='absmiddle' /><font color=green><b>SUCCESS</b></font></div>");
	$(obj[0]).children(".saving").fadeOut("slow",function(){
		$(obj[0]).children(".saving").remove();
	});
}


