/* JS */

// Transparenz-Filter bei PNG-Bilder für IE 5.5 und IE 6 anwenden
// Aufruf bei $(document).ready() oder mit JS-Code vor </body>:
// <script type="text/javascript">
// fixPng();
// </script>
function fixPng()
{
    if($.browser.msie == true && $.browser.version > 5.5 && $.browser.version < 7.0 && document.body.filters)
    {
        $('img').each(function(){
			if(this.src.match(/\.png$/) != null){
				$(this)
					.css({
						filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+$(this).attr('src')+'\', sizingMethod=\'image\')',
						width: $(this).width()+'px',
						height: $(this).height()+'px'
					})
					.attr('src',BPATH+'images/blank.gif');
			}
        });
	}
}


function ajaxDialog(file, params)
{
	var self = this;

	if(typeof file != 'string') return;
    else if(file == 'close'){ self.close(); return; }

	if(typeof params == 'number') params = {post_data: {g_id: params}};
	else if(typeof params != 'object') params = {};

	var defaults = {
		container: 'body',
		width: '300',
		callback: function(){},
		post_data: {}
	};
	var config = $.extend(defaults, params);

	this.show = function(){
	    self.close();
	    $(config.container).append('<div id="dialog_bg"></div><div id="dialog"><div id="dialog_load"></div></div>');
	    $('#dialog_bg').click(function(){ self.close(); });
	    //$('#dialog').draggable({ handle: '.title', containment: 'body' });
	    $('embed, object').css('visibility','hidden');

		if($.browser.msie == true && $.browser.version == '6.0'){
		    //document.body.style.overflow = 'auto';
			//var hhh = document.body.clientHeight - document.documentElement.clientHeight; // oder:
			var hhh = $('body').height() - $('html').height();
			$('#dialog_bg').height(hhh);
			$('#dialog_bg').css('position','absolute'); // wegen position:fixed
			$('#dialog').css('position','absolute'); // wegen position:fixed
			$('#dialog').css('margin-top',$('html').scrollTop()+'px');
		}

		// Zum Dialog scrollen wenn die Scrollposition sich weiter unterhalb befindet.
		// Für Safari und Chrome muss der body-Selector verwendet werden
// 		if($('html').scrollTop() > $(config.container).offset().top || $('body').scrollTop() > $(config.container).offset().top){
// 			$('html,body').animate({ scrollTop: $(config.container).offset().top }, 200);
// 		}
		
		self.load();
	}

	this.load = function(){
	    $.ajax({
			url: BPATH+'scripts/ajax.'+file+'.php',
			type: 'post',
			data: config.post_data,
			success: function(html){
				$('#dialog').html(html);
				$('#dialog').modFields();
				if($('#dialog').find('form').attr('action') == ''){
					$('#dialog form:first').submit(function(){
					    config.post_data = $(this).find('input, textarea, select');
					    self.load();
					    return false;
					});
				}
			    if(typeof config.callback == 'function') config.callback();
			}
		});
	}
	
	this.close = function(){
	    $('#dialog_bg, #dialog').remove();
	    $('embed, object').css('visibility','visible');
		if($.browser.msie == true && $.browser.version == '6.0'){
		    //document.body.style.overflow = 'visible';
		}
	}

	self.show();
}


$.fn.modFields = function(){
	$(this).find('input.field[title], textarea.field[title]').each(function(){
		if($(this).attr('title').length){
		    if($(this).val() == $(this).attr('title') || $(this).val() == ''){ $(this).addClass('disable'); $(this).val($(this).attr('title')); }
		    $(this).focus(function(){
		        if($(this).val() == $(this).attr('title')){ $(this).removeClass('disable'); $(this).val(''); }
			});
		    $(this).blur(function(){
		        if($(this).val() == $(this).attr('title') || $(this).val() == ''){ $(this).addClass('disable'); $(this).val($(this).attr('title')); }
			});
		}
	});
	
	$(this).find('input.field, textarea.field, select.field').each(function(){
	    $(this).focus(function(){
	        $(this).addClass('enable');
	    });
	    $(this).blur(function(){
	        $(this).removeClass('enable');
	    });
	    if($(this).is(":focus")) $(this).addClass('enable');
	});
};

function gAction(container, params)
{
	$.ajax({
		url: BPATH+'scripts/ajax.action.php',
		type: 'post',
		data: params,
		success: function(html){
			if(typeof container == 'object'){
				$(container).html(html);
				$(container).find('a[title].ttip').tipsy({gravity: 's', offset: 2});
			}
		}
	});
}

$(document).ready(function(){
    fixPng();
	if($.browser.msie == true && $.browser.version < 9)
	{
		$('div.corner-all').each(function(){
			$(this).before('<div class="corner"><div class="tl"></div><div class="tr"></div></div>');
			$(this).after('<div class="corner"><div class="bl"></div><div class="br"></div></div>');
		});
		$('div.corner-tl').each(function(){
			$(this).before('<div class="corner"><div class="tl"></div></div>');
		});
		$('div.corner-tr').each(function(){
			$(this).before('<div class="corner"><div class="tr"></div></div>');
		});
		$('div.corner-bl').each(function(){
			$(this).after('<div class="corner"><div class="bl"></div></div>');
		});
		$('div.corner-br').each(function(){
			$(this).after('<div class="corner"><div class="br"></div></div>');
		});
	}

	$('a[title].ttip').tipsy({gravity: 's', offset: 2});
	$('body').modFields();
});

$(window).load(function(){

});



