jQuery(document).ready(function($) {
  $('a[rel*=facebox]').facebox({
    loading_image : '/img/loading.gif',
    close_image   : '/img/closelabel.gif'
  });
  $('input[rel*=facebox]').facebox({
    loading_image : '/img/loading.gif',
    close_image   : '/img/closelabel.gif'
  });

  //$('#content table[class=default]').tableHover({rowClass: 'ac-row-highlight'});
  $('a[class=toggle_search]').click(function() {   
      $('div[id=search]').toggle('slow');
  });
})
jQuery(document).ready(function() {   
    var projects = $('#user_projects div[class=project]').each(function() {
        var element_id = '#' + this.id + '_details';
        $(this).click(function() {
            $(element_id).slideToggle();
        });
        $(element_id).hide();
    });

    $("a.delete_project").click(function() {
        return confirm("Are you sure you want to delete this project?");
    });
});

$(document).ready(function() {	
    $('.date-pick').datePicker({startDate:'01/01/2008'}).val(new Date().asString()).trigger('change');
});

var tabberOptions = {
	'cookie':"pT",
	  'onLoad': function(argsObj) {
	    var t = argsObj.tabber;
	    var i;
	    if (t.id) {
	      t.cookie = t.id + t.cookie;
	    }
	    i = parseInt(getCookie(t.cookie));
	    if (isNaN(i)) { return; }
	    t.tabShow(i);
	  },
	  'onClick':function(argsObj) {
	    var c = argsObj.tabber.cookie;
	    var i = argsObj.index;
	    setCookie(c, i);
	  }
}
    
/*==================================================
  Cookie functions
  ==================================================*/
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function ajaxFileUpload() {
		$("#loadMessage").ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
		
		/*
			prepareing ajax file upload
			url: the url of script file handling the uploaded files
                        fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
			dataType: it support json, xml
			secureuri:use secure protocol
			success: call back function when the ajax complete
			error: callback function when the ajax failed	
        */
		$.ajaxFileUpload
		(
			{
				url:'/projects/artwork/', 
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status) {
					if(typeof(data.error) != 'undefined') {
						if(data.error != '') {
							alert(data.error);
						} else {
							alert(data.msg);
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

}

