﻿// -------------------------------------------------------------------------------------------
// The Image preloader
// -------------------------------------------------------------------------------------------
(function ($) {
    $.fn.kriesi_image_preloader = function (options) {
        var defaults =
		{
		    repeatedCheck: 500,
		    fadeInSpeed: 1000,
		    delay: 600,
		    callback: ''
		};

        var 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 || ($.browser.msie && $.browser.version=="9.0") ) {
				                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);



// -------------------------------------------------------------------------------------------
// The Fade Slider
// -------------------------------------------------------------------------------------------

(function ($) {
    $.fn.kriesi_fade_slider = function (options) {
        var defaults =
		{
		    slides: '>div', 			// wich element inside the container should serve as slide
		    animationSpeed: 900, 	// animation duration
		    autorotation: true, 		// autorotation true or false?
		    autorotationSpeed: 3, 	// duration between autorotation switch in Seconds
		    appendControlls: '',
		    backgroundOpacity: 0.8		// opacity for background
		};

        var 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: 50 });
                    }
                    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=" ' + 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);


/**
* jqFancyTransitions - jQuery plugin
* @version: 1.0 (2009/12/04)
* @requires jQuery v1.2.2 or later 
* @author Ivan Lazarevic
* Examples and documentation at: http://www.workshop.rs/projects/jqfancytransitions
 
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
**/

(function ($) {
    var opts = new Array; var level = new Array; var img = new Array; var titles = new Array; var order = new Array; var imgInc = new Array; var inc = new Array; var stripInt = new Array; var imgInt = new Array; $.fn.jqFancyTransitions = $.fn.jqFancyTransitions = function (options) {
        init = function (el) {
            opts[el.id] = $.extend({}, $.fn.jqFancyTransitions.defaults, options); img[el.id] = new Array(); titles[el.id] = new Array(); order[el.id] = new Array(); imgInc[el.id] = 0; inc[el.id] = 0; params = opts[el.id]; if (params.effect == 'zipper') { params.direction = 'alternate'; params.position = 'alternate'; }
            if (params.effect == 'wave') { params.direction = 'alternate'; params.position = 'top'; }
            if (params.effect == 'curtain') { params.direction = 'alternate'; params.position = 'curtain'; }
            stripWidth = parseInt(params.width / params.strips); gap = params.width - stripWidth * params.strips; stripLeft = 0; $.each($('#' + el.id + ' img'), function (i, item) { img[el.id][i] = $(item).attr('src'); titles[el.id][i] = $(item).attr('alt') ? $(item).attr('alt') : ''; $(item).hide(); }); $('#' + el.id).css({ 'background-image': 'url(' + img[el.id][0] + ')', 'width': params.width, 'height': params.height, 'position': 'relative', 'background-position': 'top left' }); $('#' + el.id).append("<div class='ft-title' id='ft-title-" + el.id + "' style='position: absolute; bottom:0; left: 0; z-index: 1000; color: #fff; background-color: #000; '>" + titles[el.id][0] + "</div>"); if (titles[el.id][imgInc[el.id]])
                $('#ft-title-' + el.id).css('opacity', opts[el.id].titleOpacity); else
                $('#ft-title-' + el.id).css('opacity', 0); odd = 1; for (j = 1; j < params.strips + 1; j++) {
                if (gap > 0) { tstripWidth = stripWidth + 1; gap--; } else { tstripWidth = stripWidth; }
                $('#' + el.id).append("<div class='ft-" + el.id + "' id='ft-" + el.id + j + "' style='width:" + tstripWidth + "px; height:" + params.height + "px; float: left; position: absolute;'></div>"); $("#ft-" + el.id + j).css({ 'background-position': -stripLeft + 'px top', 'left': stripLeft }); stripLeft += tstripWidth; if (params.position == 'bottom')
                    $("#ft-" + el.id + j).css('bottom', 0); if (j % 2 == 0 && params.position == 'alternate')
                    $("#ft-" + el.id + j).css('bottom', 0); if (params.direction == 'fountain' || params.direction == 'fountainAlternate') { order[el.id][j - 1] = parseInt(params.strips / 2) - (parseInt(j / 2) * odd); order[el.id][params.strips - 1] = params.strips; odd *= -1; } else { order[el.id][j - 1] = j; } 
            }
            $('.ft-' + el.id).mouseover(function () { opts[el.id].pause = true; }); $('.ft-' + el.id).mouseout(function () { opts[el.id].pause = false; }); $('#ft-title-' + el.id).mouseover(function () { opts[el.id].pause = true; }); $('#ft-title-' + el.id).mouseout(function () { opts[el.id].pause = false; }); clearInterval(imgInt[el.id]); imgInt[el.id] = setInterval(function () { $.transition(el) }, params.delay + params.stripDelay * params.strips);
        }; $.transition = function (el) {
            if (opts[el.id].pause == true) return; stripInt[el.id] = setInterval(function () { $.strips(order[el.id][inc[el.id]], el) }, opts[el.id].stripDelay); $('#' + el.id).css({ 'background-image': 'url(' + img[el.id][imgInc[el.id]] + ')' }); imgInc[el.id]++; if (imgInc[el.id] == img[el.id].length) { imgInc[el.id] = 0; }
            if (titles[el.id][imgInc[el.id]] != '') { $('#ft-title-' + el.id).animate({ opacity: 0 }, opts[el.id].titleSpeed, function () { $(this).html(titles[el.id][imgInc[el.id]]).animate({ opacity: opts[el.id].titleOpacity }, opts[el.id].titleSpeed); }); } else { $('#ft-title-' + el.id).animate({ opacity: 0 }, opts[el.id].titleSpeed); }
            inc[el.id] = 0; if (opts[el.id].direction == 'random')
                $.fisherYates(order[el.id]); if ((opts[el.id].direction == 'right' && order[el.id][0] == 1) || opts[el.id].direction == 'alternate' || opts[el.id].direction == 'fountainAlternate')
                order[el.id].reverse();
        }; $.strips = function (itemId, el) {
            temp = opts[el.id].strips; if (inc[el.id] == temp) { clearInterval(stripInt[el.id]); return; }
            if (opts[el.id].position == 'curtain') { currWidth = $('#ft-' + el.id + itemId).width(); $('#ft-' + el.id + itemId).css({ width: 0, opacity: 0, 'background-image': 'url(' + img[el.id][imgInc[el.id]] + ')' }); $('#ft-' + el.id + itemId).animate({ width: currWidth, opacity: 1 }, 1000); } else { $('#ft-' + el.id + itemId).css({ height: 0, opacity: 0, 'background-image': 'url(' + img[el.id][imgInc[el.id]] + ')' }); $('#ft-' + el.id + itemId).animate({ height: opts[el.id].height, opacity: 1 }, 1000); }
            inc[el.id]++;
        }; $.fisherYates = function (arr) { var i = arr.length; if (i == 0) return false; while (--i) { var j = Math.floor(Math.random() * (i + 1)); var tempi = arr[i]; var tempj = arr[j]; arr[i] = tempj; arr[j] = tempi; } }
        this.each(function () { init(this); });
    }; $.fn.jqFancyTransitions.defaults = { width: 500, height: 332, strips: 20, delay: 5000, stripDelay: 50, titleOpacity: 0.7, titleSpeed: 1000, position: 'alternate', direction: 'fountainAlternate', effect: '' };
})(jQuery);



