jQuery(function( $ ){
//    $('a').remove().prependTo('body');

//    $("div#mainnav").css('display', 'none');

     var _width = $(window).width();
     var _height = $(window).height();
    
    // 21.08.2009 12:21:51 2do Max: Slider langsamer (Tel. Fuchs)
     //var _duration = 1000;        
//     var _duration = 8000;        
     var _duration = 4000;        
//        alert(_height)    ;
    
//     $('a.thickbox').attr('href', 'http://www.gefob.de' );
    var newheight = _height - 100;
    newheight = Math.min( 660 , newheight);
    $('a.thickbox').each(function(i){
        this.href = this.href  + newheight;
    });


//    $.scrollTo( { top:'-100px', left:0}, 0 );
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */

	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};

	
	/**
	 * Restart the scroll position to ( 0, 0 ) (Firefox doesn't reset it)
	 * could use $(target).scrollTo( 0, {axis:'xy'));
	 * but this needs to be quick(synchronous), to reset before $.localScroll.hash() begins
	 */
	$('body').scrollTo( { top:0, left:0}, 1 );
	$('#content').attr({scrollTop:0,scrollLeft:0});
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content', //could be a selector or a jQuery object too.
		axis:'x',//the default is 'y'
		queue:false,
//		easing:'elasout',
		duration: _duration,
		onBefore:function( ){
			$.scrollTo( { top:'-100px', left:0}, 1 );
		}
	});
	
//	var $last = $([]);//save the last link
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$.localScroll({
		target: '#content', //could be a selector or a jQuery object too.
		axis:'xy', //the default is 'y'
		queue:true,
		duration: _duration,
//		easing: 'elasout',
		hash: true,
		onBefore:function( ){
		},
		onAfter:function( ){
		}
	});

//    initMainNav();
    imagePreview();

    /* SubNav */
    $("li.subNavLi").click(function( evt) {
        $("li.subNavLi").removeClass( 'activeCat' );
        $(this).addClass( 'activeCat' );
    });

	
});

this.initMainNav = function(){	
    if (AC_FL_RunContent != 0) {
        var catid = $("#currcatid").attr('value');
	    var mainNav = TDO_FL_RunContent(
            'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0',
			"src", "main",
			"FlashVars", "currcatid="+catid+"&nav=1%7C%7C%7CHighlights%7C%7C%7Cindex.php%3Fcat%3Dc212_Highlights.html%23%23%23%23%232%7C%7C%7CProdukte%7C%7C%7Cindex.php%3Fcat%3Dc218_Produkte.html%23%23%23%23%233%7C%7C%7CFarben%7C%7C%7Cindex.php%3Fcat%3Dc215_Farben.html%23%23%23%23%234%7C%7C%7CPreisbereiche%7C%7C%7Cindex.php%3Fcat%3Dc217_Preisbereiche.html%23%23%23%23%235%7C%7C%7CMaterialien%7C%7C%7Cindex.php%3Fcat%3Dc216_Materialien.html%23%23%23%23%236%7C%7C%7CWohnbereich%7C%7C%7Cindex.php%3Fcat%3Dc220_Wohnbereich.html%23%23%23%23%237%7C%7C%7CStilrichtung%7C%7C%7Cindex.php%3Fcat%3Dc219_Stilrichtung.html",
			"width", "200",
			"height", "200",
			"align", "middle",
			"id", "main",
			"quality", "high",
			"bgcolor", "#869ca7",
			"bgcolor", "#GGGGGG",
			"wmode", "transparent",
			"name", "main",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	    );
	    $("div#mainnav").empty();
	    $("div#mainnav").append( mainNav );

    }
}

this.imagePreview = function(){	
	/* CONFIG */
	var	xOffset = 10;
    var	yOffset = 30;
    var _windoww = 290;		
    var _windowh = 310;		
    
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("img.thumb_img").hover(function(e){
        var _url = this.id;
        var _width = $(window).width();
        var _height = $(window).height();
        var _diffy = _height - e.clientY;
        var _diffx = _width - e.clientX;
        var _addy = _windowh - _diffy;
        var _addx = (_windoww + yOffset) - _diffx;
	    if (_addy < 0 ){ _addy = 0};
	    if (_addx > 0 ){ _addx = _windoww + yOffset+ yOffset};
	    if (_addx <= 0 ){ _addx = 0};
	    
	    _url=_url.replace(/\.jpg.*/g,'.jpg');
        _url=_url.replace(/\.\.\./g,'/');
		this.t = this.title;
		this.title = "";	
		/* var c = (this.t != "") ? "<br/>" + this.t : ""; */
		var c = (this.t != "") ? "<span class='previewText'>" + this.t + "</span>" : "";
		$("body").append("<p id='preview'><img src='"+ _url + "' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset - _addy) + "px")
			.css("left",(e.pageX + yOffset + _addx) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	

	$("img.thumb_img").mousemove(function(e){
        var _width = $(window).width();
        var _height = $(window).height();
        var _diffy = _height - e.clientY;
        var _diffx = _width - e.clientX;
        var _addy = _windowh - _diffy;
        var _addx = (_windoww + yOffset) - _diffx;
	    if (_addy < 0 ){ _addy = 0};
	    if (_addx > 0 ){ _addx = _windoww + yOffset+ yOffset};
	    if (_addx <= 0 ){ _addx = 0};
    
		$("#preview")
		.css("top",(e.pageY - xOffset - _addy) + "px")
		.css("left",(e.pageX + yOffset - _addx) + "px");
	});			
};

