document.documentElement.className += 'js_active';

jQuery.noConflict();
jQuery(document).ready(function(){

    my_lightbox("a[rel^='prettyPhoto'], a[rel^='lightbox']");
    k_menu();
    k_pixelperfect();
    initFancyBox();

    jQuery('.sw').click(function(){
        switchStylestyle(this.getAttribute("title"));
        return false;
    });
    
    var c = readCookie('style');
    if (c) switchStylestyle(c);
    
    jQuery("#featured").not('.fadeslider, .newsslider').kricordion({
        slides: '.featured',
        animationSpeed: 1600,
        autorotation: true,
        autorotationSpeed:10,
        event: 'mouseover',
        imageShadow:true,
        backgroundOpacity:.7,
        imageShadowStrength:0.5
    });
	
    jQuery('.fadeslider').kriesi_fade_slider({
        slides: '.featured',
        animationSpeed: 900,
        autorotation: true,
        autorotationSpeed:5,
        appendControlls: '#feature_wrap'
    });

    jQuery('.newsslider').kriesi_news_slider({
        slides: '.featured',
        animationSpeed: 900,
        autorotation: true,
        autorotationSpeed:5
    });

    jQuery('.ajax_form').kriesi_ajax_form();
    jQuery('.news_form').kriesi_ajax_form();
    jQuery('#main').kriesi_image_preloader({delay:100,callback:removeloader});
    jQuery('input:text').kriesi_empty_input();
    
    // qr-code
    jQuery('a.ext-link').qr({
        size: 160
    });
    // technics slideshow
    k_next_slide(".preview_images a",".featured_item",".show-next");
    k_fader(".preview_images a",".featured_item");
    k_newsticker(".ticker span",10000);
    k_pointer();

    iTools_TextSize();

    // playMP3();

    jQuery('#top-link').topLink({
        min: 400,
        fadeSpeed: 500
    });

    //smoothscroll
    jQuery('#top-link').click(function(e) {
        e.preventDefault();
        jQuery.scrollTo(0,300);
    });


});

function removeloader(){
	jQuery('#main .preloading_background').removeClass('preloading_background');
	jQuery('.fadeaged .featured').css('backgroundImage','none');
}

jQuery(window).bind("load", function() {
    jQuery("div#my-folio-of-works").slideViewerPro({
        thumbs: 9,
        thumbsPercentReduction: 9,
        galBorderWidth: 0,
        galBorderColor: "aqua",
        thumbsTopMargin: 10,
        thumbsRightMargin: 10,
        thumbsBorderWidth: 2,
        thumbsActiveBorderColor: "#666",
        thumbsBorderColor:"transparent",
        thumbsActiveBorderOpacity: 0.8,
        thumbsBorderOpacity: 0,
        buttonsTextColor: "#707070",
        typoFullOpacity:0.8,
        autoslide: true,
        easeTime:1200,
        asTimer:6000,
        typo: true

    });
});

jQuery.fn.topLink = function(settings) {
    settings = jQuery.extend({
        min: 1,
        fadeSpeed: 200,
        ieOffset: 50
    }, settings);
    return this.each(function() {
        var el = jQuery(this);
        el.css('display','none');
        jQuery(window).scroll(function() {
            if(!jQuery.support.hrefNormalized) {
                el.css({
                    'position': 'absolute',
                    'top': jQuery(window).scrollTop() + jQuery(window).height() - settings.ieOffset
                });
            }
            if(jQuery(window).scrollTop() >= settings.min)
            {
                el.fadeIn(settings.fadeSpeed);
            }
            else
            {
                el.fadeOut(settings.fadeSpeed);
            }
        });
    });
};

function playMP3(){
    jQuery("#jquery_jplayer_1").jPlayer({
        ready: function() {

            jQuery(this).jPlayer("volume", 0.5);
            jQuery(this).jPlayer("setMedia", {
                mp3: "http://www.jplayer.org/audio/mp3/Miaow-07-Bubble.mp3"
            }).jPlayer("play");

            var click = document.ontouchstart === undefined ? 'click' : 'touchstart';
            var kickoff = function () {
                jQuery("#jquery_jplayer_1").jPlayer("play");
                document.documentElement.removeEventListener(click, kickoff, true);
            };

            document.documentElement.addEventListener(click, kickoff, true);

        },
        ended: function() {
            jQuery(this).jPlayer("volume", 0.5);
            jQuery(this).jPlayer("play");
        },
        swfPath: "assets/js"
    });

}

function switchStylestyle(styleName){
    jQuery('link[.sw][title]').each(function(i){
        this.disabled = true;
        if (this.getAttribute('title') == styleName)
            this.disabled = false;
    });
    createCookie('style', styleName, 365);
}

function createCookie(name,value,days){
    var date, expires;
    if (days){
        date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++){
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name){
    createCookie(name,"",-1);
}

function initFancyBox(){
    jQuery("a.fbox").fancybox({
        titleShow     : false,
        transitionIn	: 'elastic',
        transitionOut	: 'elastic',
        speedin         : 700,
        speedout        : 700,
        easingIn        : 'easeOutBack',
        easingOut       : 'easeInBack',
        overlayOpacity: 0.5
    });
}

function linkTo_UnCryptMailto(s, shift)	{
    location.href=UnCryptMailto(s, shift);
}

function UnCryptMailto(s, shift) {
    var n=0;
    var r="";
    for(var i=0;i<s.length;i++) {
        n=s.charCodeAt(i);
        if (n>=8364) {
            n = 128;
        }
        r += String.fromCharCode(n-(shift));
    }
    return r;
}

/**
 * get the gtm data for the client
 * @param {} target
 */
function getGTMData(target){
    var info = document.getElementById(target),
    lat = geoip_latitude(),
    lon = geoip_longitude(),
    city = geoip_city()
    out = null;
    if(geoip_region){
        out = ''+
        '<ul>'+
        '<li>Latitude: ' + lat + '</li>'+
        '<li>Longitude: ' + lon + '</li>'+
        '<li>City: ' + city + '</li>'+
        '<li>Region: ' + geoip_region() + '</li>'+
        '<li>Region Name: ' + geoip_region_name() + '</li>'+
        '<li>Postal Code: ' + geoip_postal_code() + '</li>'+
        '<li>Country Code: ' + geoip_country_code() + '</li>'+
        '<li>Country Name: ' + geoip_country_name() + '</li>'+
        '</ul>';
        if(info) info.innerHTML = out;
    }
}

function iTools_TextSize(){
    //ID, class and tag element that font size is adjustable in this array
    //Put in html or body if you want the font of the entire page adjustable
    var section = new Array('span','.section2');
    section = section.join(',');

    // Reset Font Size
    var originalFontSize = jQuery(section).css('font-size');
    jQuery(".resetFont").click(function(){
        jQuery(section).css('font-size', originalFontSize);
    });

    // Increase Font Size
    jQuery(".increaseFont").click(function(){
        var currentFontSize = jQuery(section).css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*1.2;
        jQuery(section).css('font-size', newFontSize);
        return false;
    });

    // Decrease Font Size
    jQuery(".decreaseFont").click(function(){
        var currentFontSize = jQuery(section).css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum*0.8;
        jQuery(section).css('font-size', newFontSize);
        return false;
    });
}

/* slider 2 */
function k_next_slide($items_to_click, $items_to_fade,$next){
    $items = jQuery($items_to_fade);
    $click_these_items = jQuery($items_to_click);
    var x = 0;
    $items.each(function(i)	{
        jQuery(this).find($next).click(function(){
            i+1 < $click_these_items.length ? x = i + 1 : x = 0;
            $click_these_items.filter(":eq("+x+")").trigger('click');
            return false;
        });
    });
}

function k_fader($items_to_click, $items_to_fade){
    var $item = jQuery($items_to_fade);
    jQuery($items_to_click).each(function(i){
        jQuery(this).click(function(){
            $new_item = $item.filter(":eq("+i+")");
            if( $new_item.css("display") == "none" ){
                $item.filter(":visible").fadeOut(400, function(){
                    $new_item.fadeIn(400);
                });
            }
            return false;
        });
    });
}

function k_pointer(){
    var $wrapper = jQuery(".preview_images");
    var $slider = jQuery('<div class="pointer"></div>').appendTo($wrapper);
    var $slider_half = $slider.width()/2;
    jQuery(".preview_images a").each(function(i){
        jQuery(this).click(function(){
            jQuery(".current_prev").removeClass('current_prev');
            jQuery(this).addClass('current_prev');
            $image_pos = jQuery(this).position();
            $newposition = $image_pos.left + jQuery(this).width()/2 - $slider_half;
            $slider.animate({
                "left":$newposition
            },600,"easeOutBack");
        });

    });
}

function k_newsticker($items_to_fade, $display_time){
    tickerchange = setInterval(k_start_ticker, $display_time);
    var $tickeritem = jQuery($items_to_fade);
    var i = 1;
    function k_start_ticker(){
        $tickeritem.filter(":eq("+i+")").trigger('fade');
        i+1 < $tickeritem.length ? i++ : i = 0;
    }
    $tickeritem.each(function(i) {
        jQuery(this).bind("fade",function() {
            $new_ticker_item = $tickeritem.filter(":eq("+i+")");
            if( $new_ticker_item.css("display") == "none" ) {
                $tickeritem.filter(":visible").fadeOut(400, function(){
                    $new_ticker_item.fadeIn(400);
                });
            }
        });
    });
}

(function($){
    $.fn.kriesi_empty_input = function(options){
        return this.each(function() {
            var currentField = $(this);
            currentField.methods = {
                startingValue:  currentField.val(),
                resetValue: function(){
                    var currentValue = currentField.val();
                    if(currentField.methods.startingValue == currentValue) currentField.val('');
                },
                restoreValue: function(){
                    var currentValue = currentField.val();
                    if(currentValue == '') currentField.val(currentField.methods.startingValue);
                }
            };
            currentField.bind('focus',currentField.methods.resetValue);
            currentField.bind('blur',currentField.methods.restoreValue);
        });
    }
})(jQuery);	


(function($) {
	$.fn.kriesi_image_preloader = function(variables, callback)  {
		var defaults =  {
			fadeInSpeed: 600,
			maxLoops: 10,
			callback: '',
			delay:500
		},
		options = $.extend(defaults, variables);
			
		return this.each(function() {
			var container 	= $(this),
				images		= $('img', this).css({opacity:0, visibility:'visible', display:'block'}),
				parent = images.parent(),
				imageCount = images.length,
				interval = '',
				allImages = images ;
			var methods = {
				checkImage: function() {
					images.each(function(i) {
						if(this.complete == true) images = images.not(this);
					});
					if(images.length && options.maxLoops >= 0){
						options.maxLoops--;
						setTimeout(methods.checkImage, 500);
					}else{
						methods.showImages();
					}
				},
				showImages: function(){
					allImages.each(function(i){
						var currentImage = $(this);
						setTimeout(function(){
							currentImage.animate({opacity:1}, options.fadeInSpeed, function(){
								if(allImages.length == i+1) methods.callback(i);
							});
						},options.delay*(i+1));
					});
				},
				callback: function(){
					if (variables instanceof Function) { callback = variables; }
					if (callback  instanceof Function) { callback.call(this);  }
					if(options.callback != '') (options.callback)();
				}
			};
			methods.checkImage();
		});
	};
})(jQuery);

(function($){
    $.fn.kriesi_image_preloader_old = function(options){
        var defaults = {
			repeatedCheck: 100,
			fadeInSpeed: 600,
			maxLoops: 10,
			delay:500,
			callback: ''
        };
        options = $.extend(defaults, options);
        return this.each(function(){
            var imageContainer = jQuery(this),
            images = imageContainer.find('img').css({
                opacity:0,
                visibility:'hidden'
            }),
            imagesToLoad = images.length;
            imageContainer.operations = {
                preload: function() {
                    var stopPreloading = true;
                    images.each(function(i, event){
                        var image = $(this);
                        if(event.complete == true){
                            imageContainer.operations.showImage(image);
                        }else{
                            image.bind('error load',{
                                currentImage: image
                            }, imageContainer.operations.showImage);
                        }
                    });
                    return this;
                },
                showImage: function(image){
                    imagesToLoad --;
                    if(image.data.currentImage != undefined) {
                        image = image.data.currentImage;
                    }
                    if (options.delay <= 0) image.css('visibility','visible').animate({
                        opacity:1
                    }, options.fadeInSpeed);
                    if(imagesToLoad == 0){
                        if(options.delay > 0){
                            images.each(function(i, event){
                                var image = $(this);
                                setTimeout(function(){
                                    image.css('visibility','visible').animate({
                                        opacity:1
                                    }, options.fadeInSpeed);
                                },
                                options.delay*(i+1));
                            });
                            if(options.callback != ''){
                                setTimeout(options.callback, options.delay*images.length);
                            }
                        } else if(options.callback != ''){
                            (options.callback)();
                        }
                    }
                }
            };
            imageContainer.operations.preload();
        });
    }
})(jQuery);

(function($){
    $.fn.kriesi_fade_slider= function(options){
        var defaults ={
            slides: '>div',
            animationSpeed: 900,
            autorotation: true,
            autorotationSpeed:3,
            appendControlls: '',
            backgroundOpacity:0.8
        };		
        options = $.extend(defaults, options);
        return this.each(function(){
            var slideWrapper = $(this),
            slides = slideWrapper.find(options.slides).css({
                display:'none',
                zIndex:0
            }),
            slideCount 	= slides.length,
            currentSlideNumber = 0,
            interval,
            current_class = 'active_item',
            controlls = '',
            skipSwitch = true;
            slides.find('.feature_excerpt').css('opacity',options.backgroundOpacity);
            slideWrapper.methods = {
                init: function(){
                    slides.filter(':eq(0)').css({
                        zIndex:2,
                        display:'block'
                    });
                    if(slideCount <= 1){
                        slideWrapper.kriesi_image_preloader({ delay:200 });
                    } else {
                        slideWrapper.kriesi_image_preloader({callback:slideWrapper.methods.preloadingDone,delay:200});
                        if (options.appendControlls){
                            controlls = $('<div></div>').addClass('slidecontrolls').css({
                                position:'absolute'
                            }).appendTo(options.appendControlls);
                            slides.each(function(i){
                                var controller = $('<span class="ie6fix '+current_class+'"></span>').appendTo(controlls);
                                controller.bind('click', {
                                    currentSlideNumber: i
                                }, slideWrapper.methods.switchSlide);
                                current_class = "";
                            });
                        }
                    }
                },
                preloadingDone: function(){
                    skipSwitch = false;
                    if(options.autorotation){
                        slideWrapper.methods.autorotate();
                    }
                },					
                switchSlide: function(passed){
                    var noAction = false;	
                    if(passed != undefined && !skipSwitch){
                        if(currentSlideNumber != passed.data.currentSlideNumber){
                            currentSlideNumber = passed.data.currentSlideNumber;
                        } else {
                            noAction = true;
                        }
                    }		
                    if(passed != undefined){
                        clearInterval(interval);
                    }	
                    if(!skipSwitch && noAction == false){
                        skipSwitch = true;
                        var currentSlide = slides.filter(':visible'),
                        nextSlide = slides.filter(':eq('+currentSlideNumber+')');
                        if(options.appendControlls){
                            controlls.find('.active_item').removeClass('active_item');
                            controlls.find('span:eq('+currentSlideNumber+')').addClass('active_item');
                        }								
                        currentSlide.css({
                            zIndex:4
                        });
                        nextSlide.css({
                            zIndex:2,
                            display:'block'
                        });	
                        currentSlide.fadeOut(options.animationSpeed, function(){
                            currentSlide.css({
                                zIndex:0,
                                display:"none"
                            });
                            skipSwitch = false;
                        });
                    }
                },
                autorotate: function(){
                    interval = setInterval(function(){
                        currentSlideNumber ++;
                        if(currentSlideNumber == slideCount) currentSlideNumber = 0;							
                        slideWrapper.methods.switchSlide();
                    },
                    (parseInt(options.autorotationSpeed) * 1000));
                }
            };
            slideWrapper.methods.init();
        });
    }
})(jQuery);

(function($){
    $.fn.kriesi_news_slider= function(options){
        var defaults ={
            slides: '>div',
            animationSpeed: 900,
            autorotation: true,
            autorotationSpeed:3,
            easing: 'easeOutQuint',
            backgroundOpacity:0.8
        };		
        options = $.extend(defaults, options);		
        return this.each(function(){
            var slideWrapper = $(this),
            slides = slideWrapper.find(options.slides).css({
                display:'none',
                zIndex:0
            }),
            slideCount 	= slides.length,
            accelerator = 0,
            scrollInterval = '',
            mousePos = '',
            moving = false,
            controllWindowHeight = 0,
            controllWindowPart = 0,
            itemWindowHeight = 0,
            current_class = 'active_item',
            skipSwitch = true,
            currentSlideNumber = 0,
            newsSelect ='',
            newsItems = '';				
            slides.find('.feature_excerpt').css('opacity',options.backgroundOpacity);				
            slideWrapper.methods = {
                init: function(){
                    newsSelect = $('<div></div>').addClass('newsselect').appendTo(slideWrapper);
                    newsItems = $('<div></div>').addClass('newsItems').appendTo(newsSelect);
                    fadeout = $('<div></div>').addClass('fadeout').addClass('ie6fix').appendTo(slideWrapper);						
                    slides.filter(':eq(0)').css({
                        zIndex:2,
                        display:'block'
                    });						
                    slides.each(function(i){
                        var slide = $(this),
                        url = slide.find('a').attr('href'),
                        controll = $('<a class="single_item '+current_class+'"></a>').appendTo(newsItems).attr('href',url);
                        current_class ='';
                        slide.find('.feature_excerpt .sliderheading, .feature_excerpt .sliderdate').clone().appendTo(controll);
                        controll.bind('click', {
                            currentSlideNumber: i
                        }, slideWrapper.methods.switchSlide);
                    });	
                    controllWindowHeight = newsSelect.height();
                    controllWindowPart = controllWindowHeight/3;
                    itemWindowHeight = newsItems.height();
                    if(slideCount > 1){
                        slideWrapper.kriesi_image_preloader({delay:200});
                        slideWrapper.methods.preloadingDone();
                    }
                },
                preloadingDone: function(){
                    skipSwitch = false;
                    var offset = newsSelect.offset();
                    newsSelect.mousemove(function(e){
                        mousePos = e.pageY - offset.top;
                        if(!moving){
                            scrollInterval = setInterval(function() {
                                slideWrapper.methods.scrollItem(mousePos);
                            }, 25);
                            moving = true;
                        }
                    });										
                    newsSelect.bind('mouseleave', function(){
                        clearInterval(scrollInterval);
                        moving = false;
                        accelerator = 0;
                    });
                },			
                scrollItem: function(){
                    var movement = 0,
                    percent = controllWindowPart / 100,
                    modifier = 10,
                    currentTop = parseInt(newsItems.css('top'));
                    accelerator = accelerator <= 2 ? accelerator + 0.5 : accelerator;
                    if(mousePos < controllWindowPart){
                        movement = ((controllWindowPart - mousePos) / percent) * accelerator;
                        newPos = currentTop + (movement/modifier);
                        if(currentTop < 0){
                            if (newPos > 0) newPos = 0;
                            newsItems.css({
                                top:newPos + "px"
                            });
                        }
                    } else if(mousePos > controllWindowPart * 2) {
                        movement = ((mousePos - controllWindowPart * 2) / percent) * accelerator;
                        newPos = currentTop + (movement/modifier * -1);
                        if((currentTop * -1) < itemWindowHeight - controllWindowHeight){
                            if (newPos * -1 > itemWindowHeight - controllWindowHeight) newPos = controllWindowHeight - itemWindowHeight;								
                            newsItems.css({
                                top:newPos + "px"
                            });
                        }
                    } else {
                        accelerator = 0;
                    }
                },
                switchSlide: function(passed){
                    var noAction = false;
                    if(passed != undefined && !skipSwitch){
                        if(currentSlideNumber != passed.data.currentSlideNumber){
                            currentSlideNumber = passed.data.currentSlideNumber;
                        } else {
                            noAction = true;
                        }
                    }		
                    if(passed != undefined){
                    // clearInterval(interval);
                    }			
                    if(!skipSwitch && noAction == false){
                        skipSwitch = true;
                        var currentSlide = slides.filter(':visible'),
                        nextSlide = slides.filter(':eq('+currentSlideNumber+')');
                        newsSelect.find('.active_item').removeClass('active_item');
                        newsSelect.find('a:eq('+currentSlideNumber+')').addClass('active_item');
                        currentSlide.css({
                            zIndex:4
                        });
                        nextSlide.css({
                            zIndex:2,
                            display:'block'
                        });	
                        currentSlide.fadeOut(options.animationSpeed, function(){
                            currentSlide.css({
                                zIndex:0,
                                display:"none"
                            });
                            skipSwitch = false;
                        });
                    }
                    return false;
                },
                autorotate: function(){
                //autorotation not yet supportet
                }
            };		
            slideWrapper.methods.init();
        });
    }
})(jQuery);

(function($){
    $.fn.kricordion = function(options){
        var defaults = {
            slides: '>div',
            animationSpeed: 900,
            autorotation: true,
            autorotationSpeed:3,
            easing: 'easeOutQuint',
            event: 'mouseover',
            imageShadow:true,
            imageShadowStrength:0.5,
            fontOpacity: 1,
            backgroundOpacity:0.9
        };
        var options = $.extend(defaults, options);
        return this.each(function(){            
            var slideWrapper 	= $(this),
            slides		= slideWrapper.find(options.slides).css('display','block'),
            slide_count 	= slides.length,
            slide_width		= slideWrapper.width() / slide_count
            expand_slide 	= slides.width(),
            minimized_slide	= (slideWrapper.width() - expand_slide) / (slide_count - 1),
            overlay_modifier    = 200 *(1- options.imageShadowStrength),
            excerptWrapper      = slideWrapper.find('.feature_excerpt'),
            interval            = '',
            sideOffsetLeft      = 7,
            current_slide = 0;            
            excerptWrapper.wrap('<span class="feature_excerpt"></span>').removeClass('feature_excerpt').addClass('position_excerpt');
            excerptWrapper = slideWrapper.find('.feature_excerpt').css('opacity',options.backgroundOpacity);            
            excerptWrapper.equalHeights().find('.position_excerpt').css({
                display:'block',
                opacity:0,
                position:'absolute'
            });
            var excerptWrapperHeight = excerptWrapper.height();            
            slides.each(function(i){
                var this_slide = $(this),
                this_slide_a = this_slide.find('a'),
                real_excerpt = this_slide.find('.position_excerpt'),
                real_excerpt_height = real_excerpt.height(),
                slide_heading =this_slide.find('.sliderheading'),
                cloned_heading =   slide_heading.clone().appendTo(this_slide_a)
                .addClass('heading_clone').css({
                    opacity:options.fontOpacity,
                    width:slide_width-30
                }),
                clone_height = cloned_heading.height();
                this_slide.css('backgroundPosition',parseInt(slide_width/2-8) + 'px ' + parseInt((this_slide.height()- real_excerpt_height)/2 -8) + 'px');					
                cloned_heading.css({
                    bottom: (excerptWrapperHeight-clone_height)/2 +9
                });
                real_excerpt.css({
                    bottom: (excerptWrapperHeight-real_excerpt_height)/2 +9
                });
                this_slide.data(
                    'data',
                    {
                        this_slides_position: i * slide_width,
                        pos_active_higher: i * minimized_slide,
                        pos_active_lower: ((i-1) * minimized_slide) + expand_slide
                    });
                this_slide.css({
                    zIndex:i+1,
                    left: i * slide_width,
                    width:slide_width + overlay_modifier
                });
                if(options.imageShadow){
                    this_slide.find('>a').prepend('<span class="fadeout ie6fix"></span>');
                }			
            });
            
			//jQuery('#featured').kriesi_image_preloader({callback:add_functionality});
			jQuery('#featured').kriesi_image_preloader({callback:add_functionality});
            
			function add_functionality(){
                if(options.autorotation){
                    interval = setInterval(function() {
                        autorotation();
                    }, (parseInt(options.autorotationSpeed) * 1000));
                }
                slides.each(function(i){
                    var this_slide = $(this),
                    real_excerpt = this_slide.find('.position_excerpt'),
                    cloned_heading = this_slide.find('.heading_clone');
                    this_slide.bind(options.event, function(event, continue_autoslide){                        
                        if(!continue_autoslide){
                            clearInterval(interval)
                        }
                        var objData = this_slide.data( 'data' );                        
                        real_excerpt.stop().animate({
                            opacity:options.fontOpacity
                        },options.animationSpeed, options.easing);
                        cloned_heading.stop().animate({
                            opacity:0
                        },options.animationSpeed, options.easing);						
                        this_slide.stop().animate({
                            width: expand_slide + (overlay_modifier * 1.2),
                            left: objData.pos_active_higher
                        },
                        options.animationSpeed, options.easing);
                        slides.each(function(j){
                            if (i !== j){
                                var this_slide = $(this),
                                real_excerpt = this_slide.find('.position_excerpt'),
                                cloned_heading = this_slide.find('.heading_clone'),
                                objData = this_slide.data( 'data' ),
                                new_pos = objData.pos_active_higher;
                                if(i < j) {
                                    new_pos = objData.pos_active_lower;
                                }
                                this_slide.stop().animate({
                                    left: new_pos,
                                    width:minimized_slide + overlay_modifier
                                },options.animationSpeed, options.easing);
                                real_excerpt.stop().animate({
                                    opacity:0
                                },options.animationSpeed, options.easing);
                                cloned_heading.stop().animate({
                                    opacity:options.fontOpacity
                                },options.animationSpeed, options.easing);
                            }
                        });		
                    });
                });
                slideWrapper.bind('mouseleave', function(){
                    slides.each(function(i){
                        var this_slide = $(this),
                        real_excerpt = this_slide.find('.position_excerpt'),
                        cloned_heading = this_slide.find('.heading_clone'),
                        objData = this_slide.data( 'data' ),
                        new_pos = objData.this_slides_position;
                        this_slide.stop().animate({
                            left: new_pos,
                            width:slide_width + overlay_modifier
                        },options.animationSpeed, options.easing);
                        real_excerpt.stop().animate({
                            opacity:0
                        },options.animationSpeed, options.easing);
                        cloned_heading.stop().animate({
                            opacity:options.fontOpacity
                        },options.animationSpeed, options.easing);
                    });
                });
            }
            function autorotation(){
                if(slide_count  == current_slide){
                    slideWrapper.trigger('mouseleave');
                    current_slide = 0;
                }else{
                    slides.filter(':eq('+current_slide+')').trigger(options.event,[true]);
                    current_slide ++;
                }
            }
        });
    };
})(jQuery);

function k_menu(){    	
    jQuery(".nav a, .catnav a").removeAttr('title');
    jQuery(" .nav ul, .catnav ul ").css({
        display: "none"
    });
    if(jQuery(".catnav>li").length >= 7){
        jQuery(".catnav>li:last").addClass('noborder');
    }
    var mainitem = jQuery(".catnav>li>a");
    mainitem.each(function(){
        if(jQuery(this).height() < 34){
            jQuery(this).css({
                height:"34px"
            });
        }
    });
    mainitem.equalHeights();
    jQuery(".nav li, .catnav li").each(function(){
        var $sublist = jQuery(this).find('ul:first');
        jQuery(this).hover(function(){
            $sublist.stop().css({
                overflow:"hidden",
                height:"auto",
                display:"none"
            }).slideDown(400, function(){
                jQuery(this).css({
                    overflow:"visible",
                    height:"auto"
                });
            });
        },
        function(){
            $sublist.stop().slideUp(400, function(){
                jQuery(this).css({
                    overflow:"hidden",
                    display:"none"
                });
            });
        });
    });
}

jQuery.fn.equalHeights = function() {
    return this.height(Math.max.apply(null,
        this.map(function() {
            return jQuery(this).height()
        }).get()
        ));
};


function k_pixelperfect(){	    
    if((jQuery.browser.msie && jQuery.browser.version < 7 ) || jQuery.browser.opera){
        jQuery('#headextras #searchsubmit').css({
            top:"10px"
        });
    }
    jQuery('.sidebar').equalHeights();
}


function my_lightbox($elements){	
    var usedCSS = 1;
    jQuery('link').each(function(){
        styleURL = jQuery(this).attr('href');
        CSSnumber = styleURL.match(/style(\d).css/);
        if(CSSnumber && CSSnumber.length > 0){
            usedCSS = CSSnumber[1];
        }
    });
    var theme_selected = 'light_rounded';
    if (usedCSS == 2 || usedCSS == 4){
        theme_selected = 'dark_rounded';
    }
    jQuery($elements).prettyPhoto({
        "theme": theme_selected /* light_rounded / dark_rounded / light_square / dark_square */
    });
    jQuery($elements).each(function(){
        var $image = jQuery(this).contents("img");
        $newclass = 'lightbox_video';
        if(jQuery(this).attr('href').match(/(jpg|gif|jpeg|png|tif)/)) $newclass = 'lightbox_image';
        if ($image.length > 0){
            if(jQuery.browser.msie &&  jQuery.browser.version < 7) jQuery(this).addClass('ie6_lightbox');
            var $bg = jQuery("<span class='"+$newclass+" ie6fix'></span>").appendTo(jQuery(this));
            jQuery(this).bind('mouseenter', function(){
                $height = $image.height();
                $width = $image.width();
                $pos =  $image.position();
                $bg.css({
                    height:$height,
                    width:$width,
                    top:$pos.top,
                    left:$pos.left
                });
            });
        }
    });
    jQuery($elements).contents("img").hover(function(){
        jQuery(this).stop().animate({
            opacity:0.5
        },400);
    },
    function(){
        jQuery(this).stop().animate({
            opacity:1
        },400);
    });
}

(function($){
    $.fn.kriesi_ajax_form = function(options){
        var defaults ={
            sendPath: 'send.php',
            responseContainer: '.ajaxresponse'
        };
        options = $.extend(defaults, options);		
        return this.each(function(){
            var form = $(this),
            send =
            {
                formElements: form.find('textarea, select, input:text, input[type=hidden]'),
                validationError:false,
                button : form.find('input:submit'),
                datastring : ''
            };
            send.button.bind('click', checkElements);
            function send_ajax_form(){
                send.button.fadeOut(300);				
                $.ajax({
                    type: "POST",
                    url: options.sendPath,
                    data:send.datastring,
                    success: function(response){
                        var message =  $("<div'></div>").addClass(options.responseContainer)
                        .css('display','none')
                        .insertBefore(form)
                        .html(response);								
                        form.slideUp(400, function(){
                            message.slideDown(400), send.formElements.val('');
                        });	
                    }
                });	
            }	
            function checkElements(){                
                send.validationError = false;
                send.datastring = 'ajax=true';				
                send.formElements.each(function(i){
                    var currentElement = $(this),
                    surroundingElement = currentElement.parent(),
                    value = currentElement.val(),
                    name = currentElement.attr('name'),
                    classes = currentElement.attr('class'),
                    nomatch = true;
                    send.datastring  += "&" + name + "=" + value;
                    if(classes.match(/is_empty/)){
                        if(value == ''){
                            surroundingElement.attr("class","").addClass("error");
                            send.validationError = true;
                        }else{
                            surroundingElement.attr("class","").addClass("valid");
                        }
                        nomatch = false;
                    }		
                    if(classes.match(/is_email/)){
                        if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)){
                            surroundingElement.attr("class","").addClass("error");
                            send.validationError = true;
                        } else {
                            surroundingElement.attr("class","").addClass("valid");
                        }
                        nomatch = false;
                    }		
                    if(nomatch && value != ''){
                        surroundingElement.attr("class","").addClass("valid");
                    }
                });
                if(send.validationError == false){
                    send_ajax_form();
                }
                return false;
            }
        });
    }
})(jQuery);

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c*(t/=d)*t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c *(t/=d)*(t-2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t + b;
        return -c/2 * ((--t)*(t-2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c*(t/=d)*t*t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c*((t=t/d-1)*t*t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t + b;
        return c/2*((t-=2)*t*t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c*(t/=d)*t*t*t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
        return -c/2 * ((t-=2)*t*t*t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c*(t/=d)*t*t*t*t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c*((t=t/d-1)*t*t*t*t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
        return c/2*((t-=2)*t*t*t*t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t/d * (Math.PI/2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t==0) return b;
        if (t==d) return b+c;
        if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
        return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
        return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
    },
    easeInElastic: 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-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
    },
    easeOutElastic: 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;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s=1.70158;
        var p=0;
        var a=c;
        if (t==0) return b;
        if ((t/=d/2)==2) return b+c;
        if (!p) p=d*(.3*1.5);
        if (a < Math.abs(c)) {
            a=c;
            var s=p/4;
        }
        else var s = p/(2*Math.PI) * Math.asin (c/a);
        if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
        return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*(t/=d)*t*((s+1)*t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
        return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t/=d) < (1/2.75)) {
            return c*(7.5625*t*t) + b;
        } else if (t < (2/2.75)) {
            return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
        } else if (t < (2.5/2.75)) {
            return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
        } else {
            return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
    }
});
