/*
	PIUS HOSPITAL
	JavaScript Library
*/

// JQUERY PLUGIN FUNCTIONS
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200
	}, settings);
	return this.each(function() {
		//listen for scroll
		var el = jQuery(this);
		el.hide(); //in case the user forgot
		jQuery(window).scroll(function() {
			if(jQuery(window).scrollTop() >= settings.min)
			{
				el.fadeIn(settings.fadeSpeed);
			}
			else
			{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};

// JQUERY DOCUMENT READY
jQuery(document).ready(function(){
	// TOOL COMANDS
	jQuery("a#c-print").mouseover(function() { jQuery("#c-descr").html("Druckversion"); });
	jQuery("a#c-print").mouseout(function() { jQuery("#c-descr").html(""); });
	jQuery("a#c-sharemail").mouseover(function() { jQuery("#c-descr").html("Seite weiterempfehlen"); });
	jQuery("a#c-sharemail").mouseout(function() { jQuery("#c-descr").html(""); });
	jQuery("a#c-sharefacebook").mouseover(function() { jQuery("#c-descr").html("Seite teilen: Facebook"); });
	jQuery("a#c-sharefacebook").mouseout(function() { jQuery("#c-descr").html(""); });
	jQuery("a#c-sharetwitter").mouseover(function() { jQuery("#c-descr").html("Seite teilen: Twitter"); });
	jQuery("a#c-sharetwitter").mouseout(function() { jQuery("#c-descr").html(""); });
	jQuery("a#c-sharevz").mouseover(function() { jQuery("#c-descr").html("Seite teilen: VZ"); });
	jQuery("a#c-sharevz").mouseout(function() { jQuery("#c-descr").html(""); });
	jQuery("a#c-sharedelicious").mouseover(function() { jQuery("#c-descr").html("Seite bookmarken: Delicio.us"); });
	jQuery("a#c-sharedelicious").mouseout(function() { jQuery("#c-descr").html(""); });
	jQuery("a#c-sharemrwong").mouseover(function() { jQuery("#c-descr").html("Seite bookmarken: Mr. Wong"); });
	jQuery("a#c-sharemrwong").mouseout(function() { jQuery("#c-descr").html(""); });
	jQuery("a#c-sharegooglebm").mouseover(function() { jQuery("#c-descr").html("Seite bookmarken: Google"); });
	jQuery("a#c-sharegooglebm").mouseout(function() { jQuery("#c-descr").html(""); });

	// TOPLINK AUTO SHOW
	jQuery('#top-link').hide();
	jQuery('#top-link').topLink({
		// min: jQuery(window).height()-(jQuery(window).height()/2),
		min: 350,
		fadeSpeed: 600
	});

	// SCROLL TO TOP
    jQuery('a[href=#top]').click(function(e){
        jQuery('html, body').animate({scrollTop:0}, 'slow');
		return false;
    });
	
	// SCROLL TO ANCHOR
    jQuery('a[href^=#]').click(function(){
		var scrollposition = jQuery('a[name='+jQuery(this).attr('href').substring(1, jQuery(this).attr('href').length)+']').position().top;
		jQuery('html, body').animate({scrollTop:scrollposition}, 'fast');
        return false;
    });
    
    // FANCYBOX
	$("a.fb-image").fancybox({
		'titlePosition'		: 'inside',
		'overlayOpacity'	: 0.65,
		'overlayColor'		: '#000'
	});
	$("a.fb-gallery").fancybox({
		'titlePosition'		: 'inside',
		'overlayOpacity'	: 0.65,
		'overlayColor'		: '#000'
	});
	
	$("a.fb-video").fancybox({
		'width'				: 720,
		'height'			: 435,
		'padding'			: 10,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayOpacity'	: 0.65,
		'overlayColor'		: '#000'
	});
	$("a.fb-team").fancybox({
		'width'				: 640,
		'height'			: 480,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayOpacity'	: 0.65,
		'overlayColor'		: '#000'
	});
	$("a.fb-team2").fancybox({
		'width'				: 740,
		'height'			: 480,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayOpacity'	: 0.65,
		'overlayColor'		: '#000'
	});
	$("a.fb-babygallery").fancybox({
		'width'				: 700,
		'height'			: 550,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayOpacity'	: 0.65,
		'overlayColor'		: '#000'
	});
	$("a.fb-tellafriend").fancybox({
		'width'				: 550,
		'height'			: 460,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'overlayOpacity'	: 0.65,
		'overlayColor'		: '#000'
	});
});

// PULLDOWN ACTIONS
function pullDownScroll()
{
	var anchor = document.form1.ankerliste.value.substring(1, document.form1.ankerliste.value.length);
	var scrollposition = jQuery('a[name='+anchor+']').position().top;
	jQuery('html, body').animate({scrollTop:scrollposition}, 'fast');
}

function pullDownJump() {
	self.location.href = document.form1.ankerliste.value;
}

// POPUP WINDOW
function Popup(vBreite, vHoehe, vURL, vName) {
	var oeffnerFenster = "";
	var inhaltFenster = "";
	breite = screen.availWidth - 10;
	hoehe = screen.availHeight - 30;
	px = (breite / 2) - (vBreite / 2);
	py = (hoehe / 2) - (vHoehe / 2);
	fensterProps = "top=" + py + ",left=" + px + ",width=" + vBreite + ",height=" + vHoehe + ",dependant=yes,scrollbars=no,status=no,resizable=no";
	inhaltFenster = window.open(vURL, vName, fensterProps);
}

// DREAMWEAVER FUNCTIONS
function MM_swapImgRestore() {
	var i, x, a = document.MM_sr;
	for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) {
	var p, i, x;
	if (!d) d = document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if (! (x = d[n]) && d.all) x = d.all[n];
	for (i = 0; ! x && i < d.forms.length; i++) x = d.forms[i][n];
	for (i = 0; ! x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
	if (!x && d.getElementById) x = d.getElementById(n);
	return x;
}

function MM_swapImage() {
	var i, j = 0,
		x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for (i = 0; i < (a.length - 2); i += 3)
	if ((x = MM_findObj(a[i])) != null) {
		document.MM_sr[j++] = x;
		if (!x.oSrc) x.oSrc = x.src;
		x.src = a[i + 2];
	}
}

function MM_preloadImages() {
	var d = document;
	if (d.images) {
		if (!d.MM_p) d.MM_p = new Array();
		var i, j = d.MM_p.length,
			a = MM_preloadImages.arguments;
		for (i = 0; i < a.length; i++)
		if (a[i].indexOf("#") != 0) {
			d.MM_p[j] = new Image;
			d.MM_p[j++].src = a[i];
		}
	}
}
