var WEBDIR = '/';
jQuery.fn.popit = function(href) {
	return this.each(function(v,i){
		var popit = "active-popit-"+($('.dialog-container').length);

		var sc = getScrollXY();
		sc = sc[1];
		$('<div></div>').addClass('dialog-layer').css({height:$(document).height()+'px',width:$(document).width()+'px'}).appendTo($(document.body));

		var obj = $(this).appendTo( // SELECTED ELEMENT //
		$('<div></div>').css({position:'absolute',top : ((($(window).height()-600)/2)+sc), left : (($(window).width()-750)/2)})
		.addClass('dialog-container')
		.attr('id',popit)
		.appendTo($(document.body))
		);

		if(href!='' && typeof href != 'undefined')
		{
			obj.append('<div></div>').addClass('ajax-content').load(href,{},function(t){
				$('#'+popit).find('#dialog-loader').hide();
			});
			obj.parent()
			.prepend('<span id="dialog-loader"> / loading...</span>')
			.prepend(
			$(' <span> / </span> <a>reload</a>').css({cursor:'pointer'}).click(function(){
				$('#'+popit).find('#dialog-loader').show();
				$('#'+popit).find('.ajax-content').load(href,{},function(t){
					$('#'+popit).find('#dialog-loader').hide();
				});
			}))
		}
		obj.parent().prepend(
		$('<a>close</a>').css({cursor:'pointer'}).click(function(){
			$(this).text('bezig...')
			$('#'+popit).hide();
			$('#'+popit).remove();
			$('.dialog-layer').remove();

			if($('.dialog-container').length == 1)
			{
				//				$('object,embed').show();
			}
		})
		)
	});
};
openWindow = function(url,w,h,tb,stb,l,mb,sb,rs,x,y)
{
	var t=(document.layers)? ',screenX='+x+',screenY='+y: ',left='+x+',top='+y; //A LITTLE CROSS-BROWSER CODE FOR WINDOW POSITIONING
	tb=(tb)?'yes':'no'; stb=(stb)?'yes':'no'; l=(l)?'yes':'no'; mb=(mb)?'yes':'no'; sb=(sb)?'yes':'no'; rs=(rs)?'yes':'no';
	var x=window.open(url, 'newWin'+new Date().getTime(), 'scrollbars=yes,width='+w+',height='+h+',toolbar='+tb+',status='+stb+',menubar='+mb+',links='+l+',resizable=yes');
	x.focus();
}

$(document).ready(function(){

	if($('form').length > 0)
	{
		$('input,textarea,select').focus(function(){
			$(this).addClass('input-active');
			$(this).prev().addClass('input-active');
		})
		$('input,textarea,select').blur(function(){
			$(this).removeClass('input-active');
			$(this).prev().removeClass('input-active');
		})
	}

	//$('.crud,.crudbut,.tt').tooltip();

	$('#new_tag').keyup(function(){

		var inp = $(this);
		var id = inp.attr('id');
		$('#ac_'+id+'').empty().show();
		if($('#ac_'+id+'').length<1)
		{
			$('<ul id="ac_'+id+'"></ul>').css({position:'absolute'}).appendTo(inp.parent().parent());
		}
		$.post('/'+WEBDIR+'/items/search/',{tag : inp.val()},function(data){

			jQuery.each(data, function(i, val) {
				$('<li>'+val.name+'</li>').appendTo($('#ac_'+id)).click(function(){
					inp.val(val.name);

					$(this).parent().hide();
				})
			});

		},"json")
	})

})
function select_by_client(id)
{
	$('.inp-filter').each(function(i,v){
		if(($(this).attr('id') != id) && ($(this).attr('checked')==true) )
		{
			$(this).attr('checked',false);
		}else if($(this).attr('id') == id){
			if($(this).attr('checked')==true)
			{
				$(this).attr('checked',false);
			}else{
				$(this).attr('checked',true);
			}
		}
	})

	$('#projects-filter-form').submit();

}
function select_by_type(id,fromcb)
{
	$('.inp-filter').each(function(i,v){
		if(($(this).attr('id') != id) && ($(this).attr('checked')==true) && !$(this).hasClass('type-filter') )
		{
			$(this).attr('checked',false);
		}else if(($(this).attr('id') == id) && !fromcb){
			if($(this).attr('checked')==true)
			{
				$(this).attr('checked',false);
			}else{
				$(this).attr('checked',true);
			}
		}
	})

	$('#projects-filter-form').submit();
}
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}