﻿/*---------------------------------------Clear Input Text------------------------------
* jQuery Form Example Plugin 1.4.2
* Populate form inputs with example text that disappears on focus.
*
* e.g.
* $('input#name').example('Bob Smith');
* $('input[@title]').example(function() {
* return $(this).attr('title');
* });
* $('textarea#message').example('Type your message here', {
* className: 'example_text'
* });
*
* Copyright (c) Paul Mucur (http://mucur.name), 2007-2008.
* Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
* licenses.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
(function($) {
  
  $.fn.example = function(text, args) {
    
    /* Only calculate once whether a callback has been used. */
    var isCallback = $.isFunction(text);
    
    /* Merge the arguments and given example text into one options object. */
    var options = $.extend({}, args, {example: text});
    
    return this.each(function() {
      
      /* Reduce method calls by saving the current jQuery object. */
      var $this = $(this);
      
      /* Merge the plugin defaults with the given options and, if present,
* any metadata.
*/
      if ($.metadata) {
        var o = $.extend({}, $.fn.example.defaults, $this.metadata(), options);
      } else {
        var o = $.extend({}, $.fn.example.defaults, options);
      }
      
      /* The following event handlers only need to be bound once
* per class name. In order to do this, an array of used
* class names is stored and checked on each use of the plugin.
* If the class name is in the array then this whole section
* is skipped. If not, the events are bound and the class name
* added to the array.
*
* As of 1.3.2, the class names are stored as keys in the
* array, rather than as elements. This removes the need for
* $.inArray().
*/
      if (!$.fn.example.boundClassNames[o.className]) {
      
        /* Because Gecko-based browsers cache form values
* but ignore all other attributes such as class, all example
* values must be cleared on page unload to prevent them from
* being saved.
*/
        $(window).unload(function() {
          $('.' + o.className).val('');
        });
      
        /* Clear fields that are still examples before any form is submitted
* otherwise those examples will be sent along as well.
*
* Prior to 1.3, this would only be bound to forms that were
* parents of example fields but this meant that a page with
* multiple forms would not work correctly.
*/
        $('form').submit(function() {
        
          /* Clear only the fields inside this particular form. */
          $(this).find('.' + o.className).val('');
        });
      
        /* Add the class name to the array. */
        $.fn.example.boundClassNames[o.className] = true;
      }
    
      /* Internet Explorer will cache form values even if they are cleared
* on unload, so this will clear any value that matches the example
* text and hasn't been specified in the value attribute.
*
* If a callback is used, it is not possible or safe to predict
* what the example text is going to be so all non-default values
* are cleared. This means that caching is effectively disabled for
* that field.
*
* Many thanks to Klaus Hartl for helping resolve this issue.
*/
      if ($.browser.msie && !$this.attr('defaultValue') && (isCallback || $this.val() == o.example))
        $this.val('');
      
      /* Initially place the example text in the field if it is empty
* and doesn't have focus yet.
*/
      if ($this.val() == '' && this != document.activeElement) {
        $this.addClass(o.className);
        
        /* The text argument can now be a function; if this is the case,
* call it, passing the current element as `this`.
*/
        $this.val(isCallback ? o.example.call(this) : o.example);
      }
      
      /* Make the example text disappear when someone focuses.
*
* To determine whether the value of the field is an example or not,
* check for the example class name only; comparing the actual value
* seems wasteful and can stop people from using example values as real
* input.
*/
      $this.focus(function() {
        
        /* jQuery 1.1 has no hasClass(), so is() must be used instead. */
        if ($(this).is('.' + o.className)) {
          $(this).val('');
          $(this).removeClass(o.className);
        }
      });
 
      /* Detect a change event to the field and remove the example class. */
      $this.change(function() {
        if ($(this).is('.' + o.className)) {
          $(this).removeClass(o.className);
        }
      });
 
      /* Make the example text reappear if the input is blank on blurring. */
      $this.blur(function() {
        if ($(this).val() == '') {
          $(this).addClass(o.className);
          
          /* Re-evaluate the callback function every time the user
* blurs the field without entering anything. While this
* is not as efficient as caching the value, it allows for
* more dynamic applications of the plugin.
*/
          $(this).val(isCallback ? o.example.call(this) : o.example);
        }
      });
    });
  };
  
  /* Users can override the defaults for the plugin like so:
*
* $.fn.example.defaults.className = 'not_example';
*/
  $.fn.example.defaults = {
    className: 'example'
  };
  
  /* All the class names used are stored as keys in the following array. */
  $.fn.example.boundClassNames = [];
  
})(jQuery);

/*
* FancyBox - simple jQuery plugin for fancy image zooming
* Examples and documentation at: http://chadly.net/post/2009/01/29/Lightbox-for-YouTube-Videos.aspx
* Version: 1.0.0 (29/04/2008)
* Copyright (c) 2008 Janis Skarnelis
* Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
* Requires: jQuery v1.2.1 or later
*/
(function($) {
    var opts = {},
		imgPreloader = new Image, imgTypes = ['png', 'jpg', 'jpeg', 'gif'],
		loadingTimer, loadingFrame = 1;

    $.fn.fancybox = function(settings) {
        opts.settings = $.extend({}, $.fn.fancybox.defaults, settings);

        $.fn.fancybox.init();

        return this.each(function() {
            var $this = $(this);
            var o = $.metadata ? $.extend({}, opts.settings, $this.metadata()) : opts.settings;

            $this.unbind('click').click(function() {
                $.fn.fancybox.start(this, o); return false;
            });
        });
    };

    $.fn.fancybox.start = function(el, o) {
        if (opts.animating) return false;

        if (o.overlayShow) {
            $("#fancy_wrap").prepend('<div id="fancy_overlay"></div>');
            $("#fancy_overlay").css({ 'width': $(window).width(), 'height': $(document).height(), 'opacity': o.overlayOpacity });

            if ($.browser.msie) {
                $("#fancy_wrap").prepend('<iframe id="fancy_bigIframe" scrolling="no" frameborder="0"></iframe>');
                $("#fancy_bigIframe").css({ 'width': $(window).width(), 'height': $(document).height(), 'opacity': 0 });
            }

            $("#fancy_overlay").click($.fn.fancybox.close);
        }

        opts.itemArray = [];
        opts.itemNum = 0;

        if (jQuery.isFunction(o.itemLoadCallback)) {
            o.itemLoadCallback.apply(this, [opts]);

            var c = $(el).children("img:first").length ? $(el).children("img:first") : $(el);
            var tmp = { 'width': c.width(), 'height': c.height(), 'pos': $.fn.fancybox.getPosition(c) }

            for (var i = 0; i < opts.itemArray.length; i++) {
                opts.itemArray[i].o = $.extend({}, o, opts.itemArray[i].o);

                if (o.zoomSpeedIn > 0 || o.zoomSpeedOut > 0) {
                    opts.itemArray[i].orig = tmp;
                }
            }

        } else {
            if (!el.rel || el.rel == '') {
                var item = { url: el.href, title: el.title, o: o };

                if (o.zoomSpeedIn > 0 || o.zoomSpeedOut > 0) {
                    var c = $(el).children("img:first").length ? $(el).children("img:first") : $(el);
                    item.orig = { 'width': c.width(), 'height': c.height(), 'pos': $.fn.fancybox.getPosition(c) }
                }

                opts.itemArray.push(item);

            } else {
                var arr = $("a[rel=" + el.rel + "]").get();

                for (var i = 0; i < arr.length; i++) {
                    var tmp = $.metadata ? $.extend({}, o, $(arr[i]).metadata()) : o;
                    var item = { url: arr[i].href, title: arr[i].title, o: tmp };

                    if (o.zoomSpeedIn > 0 || o.zoomSpeedOut > 0) {
                        var c = $(arr[i]).children("img:first").length ? $(arr[i]).children("img:first") : $(el);

                        item.orig = { 'width': c.width(), 'height': c.height(), 'pos': $.fn.fancybox.getPosition(c) }
                    }

                    if (arr[i].href == el.href) opts.itemNum = i;

                    opts.itemArray.push(item);
                }
            }
        }

        $.fn.fancybox.changeItem(opts.itemNum);
    };

    $.fn.fancybox.changeItem = function(n) {
        $.fn.fancybox.showLoading();

        opts.itemNum = n;

        $("#fancy_nav").empty();
        $("#fancy_outer").stop();
        $("#fancy_title").hide();
        $(document).unbind("keydown");

        imgRegExp = imgTypes.join('|');
        imgRegExp = new RegExp('\.' + imgRegExp + '$', 'i');

        var url = opts.itemArray[n].url;

        if (url.match(/#/)) {
            var target = window.location.href.split('#')[0]; target = url.replace(target, '');

            $.fn.fancybox.showItem('<div id="fancy_div">' + $(target).html() + '</div>');

            $("#fancy_loading").hide();

        } else if (url.match(imgRegExp)) {
            $(imgPreloader).unbind('load').bind('load', function() {
                $("#fancy_loading").hide();

                opts.itemArray[n].o.frameWidth = imgPreloader.width;
                opts.itemArray[n].o.frameHeight = imgPreloader.height;

                $.fn.fancybox.showItem('<img id="fancy_img" src="' + imgPreloader.src + '" />');

            }).attr('src', url + '?rand=' + Math.floor(Math.random() * 999999999));

        } else if (url.match(/youtube\.com\/watch/i)) {
            var vidId = url.split('v=')[1].split('&')[0];
            var vidSrc = "http://www.youtube.com/v/" + vidId + "&hl=en&fs=1&autoplay=1&rel=0";
            var flashvars = {};
            var params = {};
            params.wmode = "transparent";
            params.allowFullScreen = "true";
            params.allowscriptaccess = "always";
            var attributes = {};

            $.fn.fancybox.showItem('<div id="fancy_video">No video available</div>');
            swfobject.embedSWF(vidSrc, "fancy_video", opts.itemArray[n].o.frameWidth, opts.itemArray[n].o.frameHeight, "9.0.0", false, flashvars, params, attributes);
            $("#fancy_loading").hide();

        } else {
            $.fn.fancybox.showItem('<iframe id="fancy_frame" onload="$.fn.fancybox.showIframe()" name="fancy_iframe' + Math.round(Math.random() * 1000) + '" frameborder="0" hspace="0" src="' + url + '"></iframe>');
        }
    };

    $.fn.fancybox.showIframe = function() {
        $("#fancy_loading").hide();
        $("#fancy_frame").show();
    };

    $.fn.fancybox.showItem = function(val) {
        $.fn.fancybox.preloadNeighborImages();

        var viewportPos = $.fn.fancybox.getViewport();
        var itemSize = $.fn.fancybox.getMaxSize(viewportPos[0] - 50, viewportPos[1] - 100, opts.itemArray[opts.itemNum].o.frameWidth, opts.itemArray[opts.itemNum].o.frameHeight);

        var itemLeft = viewportPos[2] + Math.round((viewportPos[0] - itemSize[0]) / 2) - 20;
        var itemTop = viewportPos[3] + Math.round((viewportPos[1] - itemSize[1]) / 2) - 40;

        var itemOpts = {
            'left': itemLeft,
            'top': itemTop,
            'width': itemSize[0] + 'px',
            'height': itemSize[1] + 'px'
        }

        if (opts.active) {
            $('#fancy_content').fadeOut("normal", function() {
                $("#fancy_content").empty();

                $("#fancy_outer").animate(itemOpts, "normal", function() {
                    $("#fancy_content").append($(val)).fadeIn("normal");
                    $.fn.fancybox.updateDetails();
                });
            });

        } else {
            opts.active = true;

            $("#fancy_content").empty();

            if ($("#fancy_content").is(":animated")) {
                console.info('animated!');
            }

            if (opts.itemArray[opts.itemNum].o.zoomSpeedIn > 0) {
                opts.animating = true;
                itemOpts.opacity = "show";

                $("#fancy_outer").css({
                    'top': opts.itemArray[opts.itemNum].orig.pos.top - 18,
                    'left': opts.itemArray[opts.itemNum].orig.pos.left - 18,
                    'height': opts.itemArray[opts.itemNum].orig.height,
                    'width': opts.itemArray[opts.itemNum].orig.width
                });

                $("#fancy_content").append($(val)).show();

                $("#fancy_outer").animate(itemOpts, opts.itemArray[opts.itemNum].o.zoomSpeedIn, function() {
                    opts.animating = false;
                    $.fn.fancybox.updateDetails();
                });

            } else {
                $("#fancy_content").append($(val)).show();
                $("#fancy_outer").css(itemOpts).show();
                $.fn.fancybox.updateDetails();
            }
        }
    };

    $.fn.fancybox.updateDetails = function() {
        $("#fancy_bg,#fancy_close").show();

        if (opts.itemArray[opts.itemNum].title !== undefined && opts.itemArray[opts.itemNum].title !== '') {
            $('#fancy_title div').html(opts.itemArray[opts.itemNum].title);
            $('#fancy_title').show();
        }

        if (opts.itemArray[opts.itemNum].o.hideOnContentClick) {
            $("#fancy_content").click($.fn.fancybox.close);
        } else {
            $("#fancy_content").unbind('click');
        }

        if (opts.itemNum != 0) {
            $("#fancy_nav").append('<a id="fancy_left" href="javascript:;"></a>');

            $('#fancy_left').click(function() {
                $.fn.fancybox.changeItem(opts.itemNum - 1); return false;
            });
        }

        if (opts.itemNum != (opts.itemArray.length - 1)) {
            $("#fancy_nav").append('<a id="fancy_right" href="javascript:;"></a>');

            $('#fancy_right').click(function() {
                $.fn.fancybox.changeItem(opts.itemNum + 1); return false;
            });
        }

        $(document).keydown(function(event) {
            if (event.keyCode == 27) {
                $.fn.fancybox.close();

            } else if (event.keyCode == 37 && opts.itemNum != 0) {
                $.fn.fancybox.changeItem(opts.itemNum - 1);

            } else if (event.keyCode == 39 && opts.itemNum != (opts.itemArray.length - 1)) {
                $.fn.fancybox.changeItem(opts.itemNum + 1);
            }
        });
    };

    $.fn.fancybox.preloadNeighborImages = function() {
        if ((opts.itemArray.length - 1) > opts.itemNum) {
            preloadNextImage = new Image();
            preloadNextImage.src = opts.itemArray[opts.itemNum + 1].url;
        }

        if (opts.itemNum > 0) {
            preloadPrevImage = new Image();
            preloadPrevImage.src = opts.itemArray[opts.itemNum - 1].url;
        }
    };

    $.fn.fancybox.close = function() {
        if (opts.animating) return false;

        $(imgPreloader).unbind('load');
        $(document).unbind("keydown");

        $("#fancy_loading,#fancy_title,#fancy_close,#fancy_bg").hide();

        $("#fancy_nav").empty();

        opts.active = false;

        if (opts.itemArray[opts.itemNum].o.zoomSpeedOut > 0) {
            var itemOpts = {
                'top': opts.itemArray[opts.itemNum].orig.pos.top - 18,
                'left': opts.itemArray[opts.itemNum].orig.pos.left - 18,
                'height': opts.itemArray[opts.itemNum].orig.height,
                'width': opts.itemArray[opts.itemNum].orig.width,
                'opacity': 'hide'
            };

            opts.animating = true;

            $("#fancy_outer").animate(itemOpts, opts.itemArray[opts.itemNum].o.zoomSpeedOut, function() {
                $("#fancy_content").hide().empty();
                $("#fancy_overlay,#fancy_bigIframe").remove();
                opts.animating = false;
            });

        } else {
            $("#fancy_outer").hide();
            $("#fancy_content").hide().empty();
            $("#fancy_overlay,#fancy_bigIframe").fadeOut("fast").remove();
        }
    };

    $.fn.fancybox.showLoading = function() {
        clearInterval(loadingTimer);

        var pos = $.fn.fancybox.getViewport();

        $("#fancy_loading").css({ 'left': ((pos[0] - 40) / 2 + pos[2]), 'top': ((pos[1] - 40) / 2 + pos[3]) }).show();
        $("#fancy_loading").bind('click', $.fn.fancybox.close);

        loadingTimer = setInterval($.fn.fancybox.animateLoading, 66);
    };

    $.fn.fancybox.animateLoading = function(el, o) {
        if (!$("#fancy_loading").is(':visible')) {
            clearInterval(loadingTimer);
            return;
        }

        $("#fancy_loading > div").css('top', (loadingFrame * -40) + 'px');

        loadingFrame = (loadingFrame + 1) % 12;
    };

    $.fn.fancybox.init = function() {
        if (!$('#fancy_wrap').length) {
            $('<div id="fancy_wrap"><div id="fancy_loading"><div></div></div><div id="fancy_outer"><div id="fancy_inner"><div id="fancy_nav"></div><div id="fancy_close"></div><div id="fancy_content"></div><div id="fancy_title"></div></div></div></div>').appendTo("body");
            $('<div id="fancy_bg"><div class="fancy_bg fancy_bg_n"></div><div class="fancy_bg fancy_bg_ne"></div><div class="fancy_bg fancy_bg_e"></div><div class="fancy_bg fancy_bg_se"></div><div class="fancy_bg fancy_bg_s"></div><div class="fancy_bg fancy_bg_sw"></div><div class="fancy_bg fancy_bg_w"></div><div class="fancy_bg fancy_bg_nw"></div></div>').prependTo("#fancy_inner");

            $('<table cellspacing="0" cellpadding="0" border="0"><tr><td id="fancy_title_left"></td><td id="fancy_title_main"><div></div></td><td id="fancy_title_right"></td></tr></table>').appendTo('#fancy_title');
        }

        if ($.browser.msie) {
            $("#fancy_inner").prepend('<iframe id="fancy_freeIframe" scrolling="no" frameborder="0"></iframe>');
        }

        if (jQuery.fn.pngFix) $(document).pngFix();

        $("#fancy_close").click($.fn.fancybox.close);
    };

    $.fn.fancybox.getPosition = function(el) {
        var pos = el.offset();

        pos.top += $.fn.fancybox.num(el, 'paddingTop');
        pos.top += $.fn.fancybox.num(el, 'borderTopWidth');

        pos.left += $.fn.fancybox.num(el, 'paddingLeft');
        pos.left += $.fn.fancybox.num(el, 'borderLeftWidth');

        return pos;
    };

    $.fn.fancybox.num = function(el, prop) {
        return parseInt($.curCSS(el.jquery ? el[0] : el, prop, true)) || 0;
    };

    $.fn.fancybox.getPageScroll = function() {
        var xScroll, yScroll;

        if (self.pageYOffset) {
            yScroll = self.pageYOffset;
            xScroll = self.pageXOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        } else if (document.body) {
            yScroll = document.body.scrollTop;
            xScroll = document.body.scrollLeft;
        }

        return [xScroll, yScroll];
    };

    $.fn.fancybox.getViewport = function() {
        var scroll = $.fn.fancybox.getPageScroll();

        return [$(window).width(), $(window).height(), scroll[0], scroll[1]];
    };

    $.fn.fancybox.getMaxSize = function(maxWidth, maxHeight, imageWidth, imageHeight) {
        var r = Math.min(Math.min(maxWidth, imageWidth) / imageWidth, Math.min(maxHeight, imageHeight) / imageHeight);

        return [Math.round(r * imageWidth), Math.round(r * imageHeight)];
    };

    $.fn.fancybox.defaults = {
        hideOnContentClick: false,
        zoomSpeedIn: 500,
        zoomSpeedOut: 500,
        frameWidth: 1024,
        frameHeight: 600,
        overlayShow: false,
        overlayOpacity: 0.5,
        itemLoadCallback: null
    };

})(jQuery);



//-------------------------------------Carousel-------------------------------//
$.fn.infiniteCarousel = function() {

    function repeat(str, num) {
        return new Array(num + 1).join(str);
    }

    return this.each(function() {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),

            singleWidth = $single.outerWidth(),
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
            currentPage = 1,
            pages = Math.ceil($items.length / visible);


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect

        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);

        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;

            $wrapper.filter(':not(:animated)').animate({
                scrollLeft: '+=' + left
            }, 500, function() {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                }

                currentPage = page;
            });

            return false;
        }

        $wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');

        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function() {
            return gotoPage(currentPage - 1);
        });

        $('a.forward', this).click(function() {
            return gotoPage(currentPage + 1);
        });

        // create a public interface to move to a specific page
        $(this).bind('goto', function(event, page) {
            gotoPage(page);
        });
    });
};

$(document).ready(function() {
    $('.infiniteCarousel').infiniteCarousel();
});



