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

// jquery.innerfade.js

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

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



(function($) {

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

    $.innerfade = function(container, options) {
	
		//animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'),
		//speed: Fadingspeed 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')
        var settings = {
        	'animationtype':    'slide',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          2000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null
        };
        var ifchanger = 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") {
            this.ifchanger = 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 ) );
				this.ifchanger = 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 ) );
								this.ifchanger = 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\'');
						}
				}
    };

    var sidecounter = 0;
    $.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]);
						});
						
						
						
	//start customisation
			// right here, slide the arrow, change the menu
		    var left_space = (current*75) + 20; // 225+20=245
			var page_break_on = $("#page_break_on").val();
			var nr_images = $("#nr_images").val();
			var thumbpanelheight = $("#thumb_panel_height").val();
//alert("left_space:"+left_space);
//95 170 245 320
			if(current==0) {
			    var title_id = nr_images;
			} else {
			    var title_id = current;
			}
/* thumbnails */
			n_title_id = current+1
			title_id = '#the'+title_id.toString()+'title';
			n_title_id = '#the'+n_title_id.toString()+'title';

			//jQuery(title_id).children('a').children('img').css("border","solid 2px white");
			//jQuery(n_title_id).children('a').children('img').css("border","solid 2px yellow");
			jQuery(title_id).removeClass("selected");
			jQuery(n_title_id).addClass("selected");
         
			//jQuery(n_title_id).children('a').animate({ "width":"350px" }, 300);

			if(current!=0 ){

				var margin_factor = -thumbpanelheight*(current); 
				//alert(current);
				if(current==nr_images){
					margin_factor = 0;
				}
				//alert("margin-left:"+margin_factor+"px")
				jQuery(".thumbpanel").css("margin-left", margin_factor+"px");
//-126 -252 -504
			}
			
//end customisation
		
        } 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\'');
        this.ifchanger = setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

/////////////////// end function


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


	



//========stuff to keep


jQuery(document).ready(function() {
    // Gray, Comment this out to stop banner rotation on main
	var page_break_on = $("#page_break_on").val();
	var nr_images = $("#nr_images").val();
	var thumbpanelheight = parseInt($("#thumb_panel_height").val());
	//var thumbpanelheight = 10;
	if(jQuery('ul#point-main').attr('id')) {
		jQuery('ul#point-main').innerfade({
			animationtype:    'fade',
			speed: 'normal', //250,
			timeout: 5000,
			type: 'sequence'
		});
	}
    // Stop commenting out here


	jQuery('.afeaturetitle').children('a').attr('href', 'javascript:void(0);')
	jQuery('.afeaturetitle').children('a').click(function() {
		clearTimeout(jQuery.innerfade.ifchanger);
		for(i=1;i<nr_images;i++) {
			jQuery('#the'+i+'feature').css("display", "none");
			jQuery('#the'+i+'title').removeClass("selected");
		}
		jQuery(this).parent('li').addClass("selected");
				
		jQuery('#the'+(jQuery(this).attr('rel'))+'feature').css("display", "block");
		
	    clearTimeout(jQuery.innerfade.ifchanger);
	
	});
	
	jQuery('.dress-nr').children('a').attr('href', 'javascript:void(0);')
	jQuery('.dress-nr').children('a').click(function() {
	clearTimeout(jQuery.innerfade.ifchanger);
	
	movepic(jQuery(this).attr('class')) ;


	});
	
	
	
	if ($.browser.mozilla) {
	    $(document).keypress (checkKey);
	} else {
	    $(document).keydown (checkKey);
	}
	
	function checkKey(e){
	     switch (e.keyCode) {
	        case 37:
	            direction = 'l';
				movepic(direction) ;
	            break;
	        case 39:
	            direction = 'r';
				movepic(direction) ;
	            break;
 
	            }      
	}
	
	
	
	function movepic(direction) 		{

			var curr_top_margin = parseInt($(".thumbpanel").css("margin-left").replace("px",""));
			//var direction = jQuery(this).attr('class');
			var panelCount = jQuery(".thumbpanel li").size();
			//var thumbpanelheight = parseInt(thumbpanelheight);
			var lastpage = thumbpanelheight * (panelCount-1);
			//alert(lastpage);

			if(direction=='l'){
				if(curr_top_margin==0) {
					margin_factor = -lastpage ; //0 => 0
				} else {
					margin_factor = curr_top_margin + thumbpanelheight; // -thumbpanelheight => 0; -320 => -thumbpanelheight
				}
			} else
			{
				if(curr_top_margin==-lastpage) {
					margin_factor = 0;
				} else {
					margin_factor = curr_top_margin - thumbpanelheight;
				}

			}	
			jQuery(".thumbpanel").css("margin-left",  margin_factor+"px");
			clearTimeout(jQuery.innerfade.ifchanger);
		};


	
});

