(function($){
	/* hoverIntent by Brian Cherne */
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
	
})(jQuery);


/* =========================================================

// jquery.innerfade.js

// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

 *
 *  <ul id="news"> 
 *      <li>content 1</li>
 *      <li>content 2</li>
 *      <li>content 3</li>
 *  </ul>
 *  
 *  $('#news').innerfade({ 
 *	  animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'), 
 *	  speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'), 
 *	  timeout: Time between the fades in milliseconds (Default: '2000'), 
 *	  type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'), 
 * 		containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
 *	  runningclass: CSS-Class which the container get’s applied (Default: 'innerfade'),
 *	  children: optional children selector (Default: null)
 *  }); 
 *

// ========================================================= */


(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
        	'animationtype':    'fade',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          2000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
            		var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do { 
												current = Math.floor ( Math.random ( ) * ( elements.length ) );
										} while (last == current );             
										$.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
						} else if ( settings.type == 'random_start' ) {
								settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									$.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								$(elements[current]).show();
						}	else {
							alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
						}
				}
    };

    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
							removeFilter($(this)[0]);
						});
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}


var fQuery = jQuery.noConflict();
fQuery(document).ready(function(){
	swapValue = [];
	fQuery(".txt").each(function(i){
	   swapValue[i] = fQuery(this).val();
   		fQuery(this).focus(function(){
      	if (fQuery(this).val() == swapValue[i]) {
         	fQuery(this).val("");
      	}
    fQuery(this).addClass("focus");
    }).blur(function(){
     	if (fQuery.trim(fQuery(this).val()) == "") {
       		fQuery(this).val(swapValue[i]);
	 		fQuery(this).removeClass("focus");
      	}
 	});
    });
    
	// InnerFade News
	fQuery('#ticker').innerfade({ type: 'random',	speed: 1000, timeout: 3000 }); 
	
	// InnerFade Twitter
	fQuery('#twitter_update_list').innerfade({ type: 'random',	speed: 1000, timeout: 9000 }); 
	
	// Accordion
	if ( fQuery("#accordion").length > 0 )
		fQuery('#accordion').accordion({ autoHeight: false })
	
	// InnerFade Testimonials
	// InnerFade Twitter
	if ( fQuery("#testimonials").find('.wrapper').length > 0 ) {
		fQuery("#testimonials").innerfade({ type: 'random', containerheight: 190,	speed: 1000, timeout: 9000 });
	}
	
	// This function is making the info messages to slide up when the X is clicked //
	fQuery(".info").click(function() {
		fQuery(this).slideUp("fast");		
	});
	
	// IFrame Dialog
	fQuery('.iframe-dialog,').click(function(e) {       
      e.preventDefault();
      var $this = fQuery(this);
      var config = (this.rel.length) ? eval('(' + fQuery(this).attr("rel") +	')') : {};
      var params = (config.params) ? config.params : {};
      var title = fQuery(this).attr("title") || "LottoTeam.com";
      var w = parseInt(config.width) || 460;
	  var h = parseInt(config.height) || 400;
	  //var d = fQuery('<div class="ui-dialog"><img src="img/layout/loader.gif" alt="Load..." /></div>').appendTo("body");

      fQuery('<iframe id="externalSite" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" style="style="filter: Chroma(color=#ffffff)" class="externalSite" src="' + this.href + '" />').dialog({
      	title: title,
        autoOpen: true,
        width: w,
        height: h,
        modal: true,
        resizable: false,
        autoResize: false,
        zIndex: 1000000,
        overlay: {
            opacity: 0.5
        }
        }).width(w).height(h);                      
      });

	// Ajax Dialog
	fQuery(".form-dialog").click(function(e){
		e.preventDefault();
		var $this = fQuery(this);
		var config = (this.rel.length) ? eval('(' + fQuery(this).attr("rel") +	')') : {};
		var params = (config.params) ? config.params : {};
		var w = parseInt(config.width) || 615;
		var h = parseInt(config.height) || 400;
		var title = fQuery(this).attr("title") || "LottoTeam.com";
		var dialog = fQuery('<div id="dialog"></div>');
		var urlData = fQuery(this).attr("href");
		var send = false;

		dialog.load(urlData, params )
			.dialog({
				bgiframe: true,
				modal:true,
				width:w,
				height:h,
				title:title,
				//zIndex: 1000000,
				autoOpen: false,
				show: 'blind',
				close:function(ev,ui){
					fQuery(this).remove();
					return false;
				},
				buttons: {
		    		'Absenden': function() {
					  var str = fQuery("#form-dialog").serialize();
					  //alert(str);
		    	      fQuery.ajax({
		    	    	  type: "POST",
		    	    	  url: fQuery('#form-dialog').attr('action'),
		    	    	  data: str,
		    	    	  success: function(data){
		    	    	  	fQuery('#dialog').html(data);
		    	          },
		    	          error: function(data){
			    	    	alert('Fehler');
			    	      }
		    	      });
		    		},
		    		Abbrechen: function() {
		    			fQuery(this).dialog('close');
		    		}
		    	}

			}).dialog("open");
	});

	
	// Ajax Dialog
	fQuery(".ajax-dialog").click(function(e){
		e.preventDefault();
		var $this = fQuery(this);
		var config = (this.rel.length) ? eval('(' + fQuery(this).attr("rel") +	')') : {};
		var params = (config.params) ? config.params : {};
		var w = parseInt(config.width) || 615;
		var h = parseInt(config.height) || 400;
		var title = fQuery(this).attr("title") || "LottoTeam.com";
		var dialog = fQuery('<div id="dialog"></div>');
		var urlData = fQuery(this).attr("href");
	
		dialog.load(urlData, params )
			.dialog({
				bgiframe: true,
				modal:true,
				width:w,
				title:title,
				//zIndex: 10000001,
				autoOpen: false,
				//show: 'blind',
				close:function(ev,ui){
					fQuery(this).remove();
					return false;
				}

			}).dialog("open");
	});
	
	
	/**
	 * RollOver Images with Fade
	 *
	 *
	 */
	 

	fQuery('.op50 img').animate({ opacity: 0.5 }, 500);

	fQuery('.op50').hoverIntent(
	     function() {
	         fQuery(this).find('img').animate({ opacity: 1.5}, 400);
	     },
	     function() {
	         fQuery(this).find('img').animate({ opacity: 0.5 }, 600);  
	     }
	);
	   
	
	// Tooltip
	fQuery("a.tooltip").tooltip({
		bodyHandler: function() {
			return fQuery(fQuery(this).attr("href")).html();
		},
		showURL: false
	});
	fQuery("a.tooltip").click(function(e){
		return false;
	});
	
	// Fancybox
	fQuery('a.zoom').fancybox({
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#FFF',
		'frameWidth' 		: 640,
		'frameHeight'		: 480
	});
});
