/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","hidden");
		});
	}
	$.fn.equalWidths = function(minWidth, maxWidth) {
		widest = (minWidth) ? minWidth : 0;
		this.each(function() {
			if($(this).width() > widest) {
				widest = $(this).width();
			}
		});
		if((maxWidth) && widest > maxWidth) widest = maxWidth;
		return this.each(function() {
			$(this).width(widest).css("overflow","hidden");
		});
	}
})(jQuery);










/*
 * jQuery infinitecarousel plugin
 * @author admin@catchmyfame.com - http://www.catchmyfame.com
 * @version 1.2.2
 * @date August 31, 2009
 * @category jQuery plugin
 * @copyright (c) 2009 admin@catchmyfame.com (www.catchmyfame.com)
 * @license CC Attribution-Share Alike 3.0 - http://creativecommons.org/licenses/by-sa/3.0/
 */
(function($){$.fn.extend({infiniteCarousel:function(options)
{var defaults={transitionSpeed:1500,displayTime:6000,textholderHeight:.2,displayProgressBar:1,displayThumbnails:1,displayThumbnailNumbers:1,displayThumbnailBackground:1,thumbnailWidth:'20px',thumbnailHeight:'20px',thumbnailFontSize:'.7em'};var options=$.extend(defaults,options);return this.each(function(){var randID=Math.round(Math.random()*100000000);var o=options;var obj=$(this);var curr=1;var numImages=$('img',obj).length;var imgHeight=$('img:first',obj).height();var imgWidth=$('img:first',obj).width();var autopilot=1;$('div',obj).hide();$(obj).width(imgWidth).height(imgHeight);if(o.displayProgressBar)
{$(obj).append('<div id="progress'+randID+'" style="position:absolute;bottom:0;background:#bbb;left:'+$(obj).css('paddingLeft')+'"></div>');$('#progress'+randID).width(imgWidth).height(5).css('opacity','.5');}
$(obj).css({'position':'relative'});$('li:last',obj).prependTo($('ul',obj));$('ul',obj).css('left',-imgWidth+'px');$('ul',obj).width(9999);$('ul',obj).css({'list-style':'none','margin':'0','padding':'0','position':'relative'});$('li',obj).css({'display':'block','float':'left'});$(obj).append('<div id="textholder'+randID+'" class="textholder" style="position:absolute;bottom:0px;margin-bottom:'+-imgHeight*o.textholderHeight+'px;left:'+$(obj).css('paddingLeft')+'"></div>');var correctTHWidth=parseInt($('#textholder'+randID).css('paddingTop'));var correctTHHeight=parseInt($('#textholder'+randID).css('paddingRight'));$('#textholder'+randID).width(imgWidth-(correctTHWidth*2)).height((imgHeight*o.textholderHeight)-(correctTHHeight*2));showtext($('li:eq(1) div',obj).html());html='';html+='';$(obj).append(html);html='';html+='';$(obj).append(html);$('#pause_btn'+randID).css('opacity','.5').hover(function(){$(this).animate({opacity:'1'},250)},function(){$(this).animate({opacity:'.5'},250)});$('#pause_btn'+randID).click(function(){autopilot=0;$('#progress'+randID).stop().fadeOut();clearTimeout(clearInt);$('#pause_btn'+randID).fadeOut(250);$('#play_btn'+randID).fadeIn(250);showminmax();});$('#play_btn'+randID).css('opacity','.5').hover(function(){$(this).animate({opacity:'1'},250)},function(){$(this).animate({opacity:'.5'},250)});$('#play_btn'+randID).click(function(){autopilot=1;anim('next');$('#play_btn'+randID).hide();clearInt=setInterval(function(){anim('next');},o.displayTime+o.transitionSpeed);setTimeout(function(){$('#pause_btn'+randID).show();$('#progress'+randID).fadeIn().width(imgWidth).height(5);},o.transitionSpeed);});$('#btn_rt'+randID).click(function(){autopilot=0;$('#progress'+randID).stop().fadeOut();anim('next');setTimeout(function(){$('#play_btn'+randID).fadeIn(250);},o.transitionSpeed);clearTimeout(clearInt);});$('#btn_lt'+randID).css('opacity','1').click(function(){autopilot=0;$('#progress'+randID).stop().fadeOut();anim('prev');setTimeout(function(){$('#play_btn'+randID).fadeIn(250);},o.transitionSpeed);clearTimeout(clearInt);});if(o.displayThumbnails)
{$(obj).after('<div class="thumbs" id="thumbs'+randID+'"></div>');$('#thumbs'+randID);for(i=0;i<=numImages-1;i++)
{thumb=$('img:eq('+(i+1)+')',obj).attr('src');$('#thumbs'+randID).append('<a class="thumb" id="thumb'+randID+'_'+(i+1)+'">'+(i+1)+'</a>');if(i==0)$('#thumb'+randID+'_1').addClass("active");}
thumb=$('img:first',obj).attr('src');$('#thumb'+randID+'_'+numImages);$('#thumbs'+randID+' a.thumb:not(:first)').css({'opacity':'.65'}).removeClass("active");$('#thumbs'+randID+' a.thumb').hover(function(){$(this).animate({'opacity':.99},150)},function(){if(curr!=this.id.split('_')[1])$(this).animate({'opacity':.65},250)});$('#thumbs'+randID+' a').bind('click',thumbclick);if(!o.displayThumbnailNumbers)$('#thumbs'+randID+' a').text('');if(!o.displayThumbnailBackground)$('#thumbs'+randID+' a');}
function thumbclick(event)
{target_num=this.id.split('_');if(curr!=target_num[1])
{$('#thumb'+randID+'_'+curr).css({'border-color':'#ccc'});$('#progress'+randID).stop().fadeOut();clearTimeout(clearInt);$('#thumbs'+randID+' a').css({'cursor':'default'}).unbind('click');autopilot=0;setTimeout(function(){$('#play_btn'+randID).fadeIn(250);},o.transitionSpeed);}
if(target_num[1]>curr)
{diff=target_num[1]-curr;anim('next',diff);}
if(target_num[1]<curr)
{diff=curr-target_num[1];anim('prev',diff);}}
function showtext(t)
{if(t!=null)
{$('#textholder'+randID).html(t).animate({marginBottom:'-80px','opacity':1},500);showminmax();}}
function showminmax()
{if(!autopilot)
{$('#textholder'+randID).append(html);$('#min').fadeIn(250).click(function(){$('#textholder'+randID).animate({marginBottom:'-80px','opacity':1},500,function(){$("#min,#max").toggle();});});$('#max').click(function(){$('#textholder'+randID).animate({marginBottom:'-80px','opacity':1},500,function(){$("#min,#max").toggle();});});$('#close').fadeIn(250).click(function(){$('#textholder'+randID).animate({marginBottom:'-80px','opacity':1},500);});}}
function borderpatrol(elem)
{$('#thumbs'+randID+' a').css({'border-color':'#ccc'}).animate({opacity:0.65},500).removeClass("active");setTimeout(function(){elem.addClass("active").animate({'opacity':.99},500);},o.transitionSpeed);}
function anim(direction,dist)
{$('#textholder'+randID).animate({'opacity':0},500);$('#pause_btn'+randID).fadeOut(250);$('#play_btn'+randID).fadeOut(250);if(direction=="next")
{if(curr==numImages)curr=0;if(dist>1)
{borderpatrol($('#thumb'+randID+'_'+(curr+dist)));$('li:lt(2)',obj).clone().insertAfter($('li:last',obj));$('ul',obj).animate({left:-imgWidth*(dist+1)},o.transitionSpeed,function(){$('li:lt(2)',obj).remove();for(j=1;j<=dist-2;j++)
{$('li:first',obj).clone().insertAfter($('li:last',obj));$('li:first',obj).remove();}
$('#play_btn'+randID).fadeIn(250);showtext($('li:eq(1) div',obj).html());$(this).css({'left':-imgWidth});curr=curr+dist;$('#thumbs'+randID+' a').bind('click',thumbclick).css({'cursor':'pointer'});});}
else
{borderpatrol($('#thumb'+randID+'_'+(curr+1)));$('#thumbs'+randID+' a').css({'cursor':'default'}).unbind('click');$('li:first',obj).clone().insertAfter($('li:last',obj));$('ul',obj).animate({left:-imgWidth*2},o.transitionSpeed,function(){$('li:first',obj).remove();$('ul',obj).css('left',-imgWidth+'px');if(autopilot)$('#pause_btn'+randID).fadeIn(250);showtext($('li:eq(1) div',obj).html());if(autopilot)
{$('#progress'+randID).width(imgWidth).height(5);$('#progress'+randID).animate({'width':0},o.displayTime,function(){$('#pause_btn'+randID).fadeOut(50);setTimeout(function(){$('#pause_btn'+randID).fadeIn(250)},o.transitionSpeed)});}
curr=curr+1;$('#thumbs'+randID+' a').bind('click',thumbclick).css({'cursor':'pointer'});});}}
if(direction=="prev")
{if(dist>1)
{borderpatrol($('#thumb'+randID+'_'+(curr-dist)));$('li:gt('+(numImages-(dist+1))+')',obj).clone().insertBefore($('li:first',obj));$('ul',obj).css({'left':(-imgWidth*(dist+1))}).animate({left:-imgWidth},o.transitionSpeed,function(){$('li:gt('+(numImages-1)+')',obj).remove();$('#play_btn'+randID).fadeIn(250);showtext($('li:eq(1) div',obj).html());curr=curr-dist;$('#thumbs'+randID+' a').bind('click',thumbclick).css({'cursor':'pointer'});});}
else
{borderpatrol($('#thumb'+randID+'_'+(curr-1)));$('#thumbs'+randID+' a').css({'cursor':'default'}).unbind('click');$('li:last',obj).clone().insertBefore($('li:first',obj));$('ul',obj).css('left',-imgWidth*2+'px').animate({left:-imgWidth},o.transitionSpeed,function(){$('li:last',obj).remove();if(autopilot)$('#pause_btn'+randID).fadeIn(250);showtext($('li:eq(1) div',obj).html());curr=curr-1;if(curr==0)curr=numImages;$('#thumbs'+randID+' a').bind('click',thumbclick).css({'cursor':'pointer'});});}}}
var clearInt=setInterval(function(){anim('next');},o.displayTime+o.transitionSpeed);$('#progress'+randID).animate({'width':0},o.displayTime+o.transitionSpeed,function(){$('#pause_btn'+randID).fadeOut(100);setTimeout(function(){$('#pause_btn'+randID).fadeIn(250)},o.transitionSpeed)});});}});})(jQuery);
















/*
 * 	Easy Slider 1.7 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#slider").easySlider();
 *	
 * 	<div id="slider">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($){$.fn.easySlider=function(options){var defaults={prevId:'prevBtn',prevText:'Previous',nextId:'nextBtn',nextText:'Next',controlsShow:true,controlsBefore:'',controlsAfter:'',controlsFade:true,firstId:'firstBtn',firstText:'First',firstShow:false,lastId:'lastBtn',lastText:'Last',lastShow:false,vertical:false,speed:800,auto:false,pause:2000,continuous:false,numeric:false,numericId:'controls'};var options=$.extend(defaults,options);this.each(function(){var obj=$(this);var s=$("li",obj).length;var w=$("li",obj).width();var h=$("li",obj).height();var clickable=true;obj.width(w);obj.height(h);obj.css("overflow","hidden");var ts=s-1;var t=0;$("ul",obj).css('width',s*w);if(options.continuous){$("ul",obj).prepend($("ul li:last-child",obj).clone().css("margin-left","-"+w+"px"));$("ul",obj).append($("ul li:nth-child(2)",obj).clone());$("ul",obj).css('width',(s+1)*w);};if(!options.vertical)$("li",obj).css('float','left');if(options.controlsShow){var html=options.controlsBefore;if(options.numeric){html+='<ol id="'+options.numericId+'"></ol>';}else{if(options.firstShow)html+='<span id="'+options.firstId+'"><a href=\"javascript:void(0);\">'+options.firstText+'</a></span>';html+=' <span id="'+options.prevId+'"><a href=\"javascript:void(0);\">'+options.prevText+'</a></span>';html+=' <span id="'+options.nextId+'"><a href=\"javascript:void(0);\">'+options.nextText+'</a></span>';if(options.lastShow)html+=' <span id="'+options.lastId+'"><a href=\"javascript:void(0);\">'+options.lastText+'</a></span>';};html+=options.controlsAfter;$(obj).after(html);};if(options.numeric){for(var i=0;i<s;i++){$(document.createElement("li")).attr('id',options.numericId+(i+1)).html('<a rel='+i+' href=\"javascript:void(0);\">'+(i+1)+'</a>').appendTo($("#"+options.numericId)).click(function(){animate($("a",$(this)).attr('rel'),true);});};}else{$("a","#"+options.nextId).click(function(){animate("next",true);});$("a","#"+options.prevId).click(function(){animate("prev",true);});$("a","#"+options.firstId).click(function(){animate("first",true);});$("a","#"+options.lastId).click(function(){animate("last",true);});};function setCurrent(i){i=parseInt(i)+1;$("li","#"+options.numericId).removeClass("current");$("li#"+options.numericId+i).addClass("current");};function adjust(){if(t>ts)t=0;if(t<0)t=ts;if(!options.vertical){$("ul",obj).css("margin-left",(t*w*-1));}else{$("ul",obj).css("margin-top",(t*h*-1));}
clickable=true;if(options.numeric)setCurrent(t);};function animate(dir,clicked){if(clickable){clickable=false;var ot=t;switch(dir){case"next":t=(ot>=ts)?(options.continuous?t+1:ts):t+1;break;case"prev":t=(t<=0)?(options.continuous?t-1:0):t-1;break;case"first":t=0;break;case"last":t=ts;break;default:t=dir;break;};var diff=Math.abs(ot-t);var speed=diff*options.speed;if(!options.vertical){p=(t*w*-1);$("ul",obj).animate({marginLeft:p},{queue:false,duration:speed,complete:adjust});}else{p=(t*h*-1);$("ul",obj).animate({marginTop:p},{queue:false,duration:speed,complete:adjust});};if(!options.continuous&&options.controlsFade){if(t==ts){$("a","#"+options.nextId).hide();$("a","#"+options.lastId).hide();}else{$("a","#"+options.nextId).show();$("a","#"+options.lastId).show();};if(t==0){$("a","#"+options.prevId).hide();$("a","#"+options.firstId).hide();}else{$("a","#"+options.prevId).show();$("a","#"+options.firstId).show();};};if(clicked)clearTimeout(timeout);if(options.auto&&dir=="next"&&!clicked){;timeout=setTimeout(function(){animate("next",false);},diff*options.speed+options.pause);};};};var timeout;if(options.auto){;timeout=setTimeout(function(){animate("next",false);},options.pause);};if(options.numeric)setCurrent(0);if(!options.continuous&&options.controlsFade){$("a","#"+options.prevId).hide();$("a","#"+options.firstId).hide();};});};})(jQuery);

























/*************************************************
**  jQuery Masonry version 1.3.2
**  Copyright David DeSandro, licensed MIT
**  http://desandro.com/resources/jquery-masonry
**************************************************/
(function(e){var n=e.event,o;n.special.smartresize={setup:function(){e(this).bind("resize",n.special.smartresize.handler)},teardown:function(){e(this).unbind("resize",n.special.smartresize.handler)},handler:function(j,l){var g=this,d=arguments;j.type="smartresize";o&&clearTimeout(o);o=setTimeout(function(){jQuery.event.handle.apply(g,d)},l==="execAsap"?0:100)}};e.fn.smartresize=function(j){return j?this.bind("smartresize",j):this.trigger("smartresize",["execAsap"])};e.fn.masonry=function(j,l){var g={getBricks:function(d,b,a){var c=a.itemSelector===undefined;b.$bricks=a.appendedContent===undefined?c?d.children():d.find(a.itemSelector):c?a.appendedContent:a.appendedContent.filter(a.itemSelector)},placeBrick:function(d,b,a,c,h){b=Math.min.apply(Math,a);for(var i=b+d.outerHeight(true),f=a.length,k=f,m=c.colCount+1-f;f--;)if(a[f]==b)k=f;d.applyStyle({left:c.colW*k+c.posLeft,top:b},e.extend(true,{},h.animationOptions));for(f=0;f<m;f++)c.colY[k+f]=i},setup:function(d,b,a){g.getBricks(d,a,b);if(a.masoned)a.previousData=d.data("masonry");a.colW=b.columnWidth===undefined?a.masoned?a.previousData.colW:a.$bricks.outerWidth(true):b.columnWidth;a.colCount=Math.floor(d.width()/a.colW);a.colCount=Math.max(a.colCount,1)},arrange:function(d,b,a){var c;if(!a.masoned||b.appendedContent!==undefined)a.$bricks.css("position","absolute");if(a.masoned){a.posTop=a.previousData.posTop;a.posLeft=a.previousData.posLeft}else{d.css("position","relative");var h=e(document.createElement("div"));d.prepend(h);a.posTop=Math.round(h.position().top);a.posLeft=Math.round(h.position().left);h.remove()}if(a.masoned&&b.appendedContent!==undefined){a.colY=a.previousData.colY;for(c=a.previousData.colCount;c<a.colCount;c++)a.colY[c]=a.posTop}else{a.colY=[];for(c=a.colCount;c--;)a.colY.push(a.posTop)}e.fn.applyStyle=a.masoned&&b.animate?e.fn.animate:e.fn.css;b.singleMode?a.$bricks.each(function(){var i=e(this);g.placeBrick(i,a.colCount,a.colY,a,b)}):a.$bricks.each(function(){var i=e(this),f=Math.ceil(i.outerWidth(true)/a.colW);f=Math.min(f,a.colCount);if(f===1)g.placeBrick(i,a.colCount,a.colY,a,b);else{var k=a.colCount+1-f,m=[];for(c=0;c<k;c++){var p=a.colY.slice(c,c+f);m[c]=Math.max.apply(Math,p)}g.placeBrick(i,k,m,a,b)}});a.wallH=Math.max.apply(Math,a.colY);d.applyStyle({height:a.wallH-a.posTop},e.extend(true,[],b.animationOptions));a.masoned||setTimeout(function(){d.addClass("masoned")},1);l.call(a.$bricks);d.data("masonry",a)},resize:function(d,b,a){a.masoned=!!d.data("masonry");var c=d.data("masonry").colCount;g.setup(d,b,a);a.colCount!=c&&g.arrange(d,b,a)}};return this.each(function(){var d=e(this),b={};b.masoned=!!d.data("masonry");var a=b.masoned?d.data("masonry").options:{},c=e.extend({},e.fn.masonry.defaults,a,j),h=a.resizeable;b.options=c.saveOptions?c:a;l=l||function(){};g.getBricks(d,b,c);if(!b.$bricks.length)return this;g.setup(d,c,b);g.arrange(d,c,b);!h&&c.resizeable&&e(window).bind("smartresize.masonry",function(){g.resize(d,c,b)});h&&!c.resizeable&&e(window).unbind("smartresize.masonry")})};e.fn.masonry.defaults={singleMode:false,columnWidth:undefined,itemSelector:undefined,appendedContent:undefined,saveOptions:true,resizeable:true,animate:false,animationOptions:{}}})(jQuery);





















/*
 * In-Field Label jQuery Plugin
 * http://fuelyourcoding.com/scripts/infield.html
 *
 * Copyright (c) 2009 Doug Neiner
 * Dual licensed under the MIT and GPL licenses.
 * Uses the same license as jQuery, see:
 * http://docs.jquery.com/License
 *
 * @version 0.1
 */
(function($){$.InFieldLabels=function(label,field,options){var base=this;base.$label=$(label);base.$field=$(field);base.$label.data("InFieldLabels",base);base.showing=true;base.init=function(){base.options=$.extend({},$.InFieldLabels.defaultOptions,options);base.$label.css('position','absolute');var fieldPosition=base.$field.position();base.$label.css({'left':fieldPosition.left,'top':fieldPosition.top}).addClass(base.options.labelClass);if(base.$field.val()!=""){base.$label.hide();base.showing=false;};base.$field.focus(function(){base.fadeOnFocus();}).blur(function(){base.checkForEmpty(true);}).bind('keydown.infieldlabel',function(e){base.hideOnChange(e);}).change(function(e){base.checkForEmpty();}).bind('onPropertyChange',function(){base.checkForEmpty();});};base.fadeOnFocus=function(){if(base.showing){base.setOpacity(base.options.fadeOpacity);};};base.setOpacity=function(opacity){base.$label.stop().animate({opacity:opacity},base.options.fadeDuration);base.showing=(opacity>0.0);};base.checkForEmpty=function(blur){if(base.$field.val()==""){base.prepForShow();base.setOpacity(blur?1.0:base.options.fadeOpacity);}else{base.setOpacity(0.0);};};base.prepForShow=function(e){if(!base.showing){base.$label.css({opacity:0.0}).show();base.$field.bind('keydown.infieldlabel',function(e){base.hideOnChange(e);});};};base.hideOnChange=function(e){if((e.keyCode==16)||(e.keyCode==9))return;if(base.showing){base.$label.hide();base.showing=false;};base.$field.unbind('keydown.infieldlabel');};base.init();};$.InFieldLabels.defaultOptions={fadeOpacity:0.5,fadeDuration:300,labelClass:'infield'};$.fn.inFieldLabels=function(options){return this.each(function(){var for_attr=$(this).attr('for');if(!for_attr)return;var $field=$("input#"+for_attr+"[type='text'],"+"input#"+for_attr+"[type='password'],"+"textarea#"+for_attr);if($field.length==0)return;(new $.InFieldLabels(this,$field[0],options));});};})(jQuery);
























jQuery.fn.shuffle = (function(){
   
    function fisherYatesShuffle(arr) {
       
        // Fisher-Yates shuffle has been proven
        // to be more random than the conventional
        // arr.sort(function(){return Math.random()-.5})
        // [url]http://www.robweir.com/blog/2010/02/microsoft-random-browser-ballot.html[/url]
       
        var i = arr.length,
            r, tempI, tempR;
       
        if ( i === 0 ) {
            return arr;
        }
       
        while ( i-- ) {
           
            // Generate random index:
            r = Math.floor(Math.random() * (i + 1));
           
            // Shuffle:
            tempI = arr[i];
            tempR = arr[r];
            arr[i] = tempR;
            arr[r] = tempI;
           
        }
       
        return arr;
       
    }
   
    return function(s) {
       
        return this.each(function(){
 
            var container = jQuery(this);
           
            // Append shuffled children
            container.append(
                fisherYatesShuffle(container.find(s))
            );
           
        });
       
    };
 
})();

/*
 * Copyright (c) 2011 Arron Bailiss <arron@arronbailiss.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */


(function($) {
	
	var settings = {
		'toArea'     : null, // The selector where the dynamically loaded content should be inserted in the current page and extracted from on the dynamically loaded page
		'updateTitle': true, // Set to false to stop the page title being updated with the dynamically loaded content's page title
		'callback'   : null, // Called after the page content has been loaded
		'fromArea'	 : null
	};
	var History = null;
	var selector = '';
	var justPushedState = false;
	var loading = false;
	
	var methods = {
		init : function(options) { // Initialises the plugin
			selector = this.selector;
			if (options) $.extend(settings, options);
			
			if (settings.toArea === null) {
				$.error('Missing required parameter toArea on jQuery.dynamicPage');
				return false;
			}
			
			if (methods.supported()) methods.bindEvents.call($(this));
			return $(this);
		},
		supported : function() { // Checks support for functionality
			History = window.History;
			return History.enabled;
		},
		bindEvents : function() { // Bind plugin events
			$(selector).live('click', function(e) { // Bind event for dynamic content loading links
				e.preventDefault();
				methods.loadContent.call($(this), $(this).attr('href'), true);
			});
			History.Adapter.bind(window, 'statechange', function(e) { // Bind state change for preserving back/forwards browser button functionality when loading dynamic content
				var state = History.getState();
				if (state !== null && !justPushedState) methods.loadContent(state.url);
			});
		},
		loadContent : function(url, doState) { // Fired when a dynamic content loading link is clicked
			if (!loading) {
				$(settings.toArea).html('<p style="text-align:center; padding-top:100px"><img src="images/loader.gif" /></p>');
			    loading = true;
				$.ajax({
			  		url: url,
			  		success: function(text) {
				   		var oldContent = $(settings.toArea).find(settings.fromArea);
						//$(settings.toArea).hide();
						newPage = $(text);
						newContent = newPage.find(settings.fromArea);
						if (newContent.length > 0) {
							if (doState !== undefined) { // Magic HTML5 loveliness
							    stateObj = { url: url };
							    justPushedState = true;
							    History.pushState(stateObj, '', url);
							    justPushedState = false;
						    }
							
				      		//oldContent.remove();
							//setTimeout(function () {
				      		$(settings.toArea).hide().html(newContent).fadeIn(500);
							//},500);
				      		// Set New Title
				      		document.title = newPage.filter('title').text();
							
							if (typeof settings.callback == 'function') settings.callback.call($(this), url); // Fire the callback
					    	loading = false;
						} else {
							window.location = url;
						}
			        	
		    		}
					
					
		  		});
				
				
			    /*$(settings.toArea).load(url+' '+settings.toArea+' > *', function(resp) { // Load the clicked link's href page's content in to toArea
				    if (settings.updateTitle) document.title = $(resp).filter('title').text(); // Update the page title
				    if (doState !== undefined) { // Magic HTML5 loveliness
					    stateObj = { url: url };
					    justPushedState = true;
					    History.pushState(stateObj, '', url);
					    justPushedState = false;
				    }

				    if (typeof settings.callback == 'function') settings.callback.call($(this), url); // Fire the callback
				    loading = false;
			    });*/
			}
		}
	};
	
	$.fn.dynamicPage = function(method) {
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		}
		else if (typeof method === 'object' || !method) {
			return methods.init.apply(this, arguments);
		}
		else {
			$.error('Method '+method+' does not exist on jQuery.dynamicPage');
		}
	};
})(jQuery);































$(document).ready(function() {
	// find the div.fade elements and hook the hover event
	$('.blocServices .bloc h2 a, .lienRealisations a, .zoneServices ul a, .newsletter a').each(function(){
		$(this).hover(function() {
			// on hovering over find the element we want to fade *up*
			var fade = $('> span', this);
			fade.fadeIn(500);
		}, function () {
			var fade = $('> span', this);
			fade.fadeOut(500);
		});
	 
		
	})
	$('.webcreation .blocPresta .bloc').equalHeights();
	$('.liste_projets .projet .descProjetInner').equalHeights();
	
	$('#carousel').infiniteCarousel({
		displayTime: 6000,
		textholderHeight : .25,	
		displayThumbnailBackground: 0

	});
	
	$('.listeLogos ul').shuffle('li');
	$('.listeLogos').easySlider({
		vertical:true,
		auto: true,
		continuous:true,
		controlsShow:false
	});
	
	$('#news').masonry({
	  singleMode: true, 
	  itemSelector: '.NewsSummary',
	  columnWidth: 240
	});
	
	$("label").inFieldLabels({fadeOpacity:0.3});
	
	//Modal newsletter
	//select all the a tag with name equal to modal
    $('.newsletter_btn').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = '#dialog';
     
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
     
        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth,'height':maskHeight});
         
        //transition effect    
        $('#mask').fadeIn(1000);   
        $('#mask').fadeTo("slow",0.8); 
     
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
               
        //Set the popup window to center
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
     
        //transition effect
        $(id).fadeIn(2000);
     
    });
     
    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });    
     
    //if mask is clicked
    $('#mask').click(function () {
        $(this).hide();
        $('.window').hide();
    }); 
	
	//Prévalidation du formulaire
	$('#subForm').before('<div class="error error-nl"><ul></ul></div>');
  	$(".error-nl").hide();
	
	function checkEmail(email) { 
		var pattern = /^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/;
		 var emailVal = $("#" + email).val();
		return pattern.test(emailVal);
	  }
  	$("#subForm input:submit").click(function() { 
      
      // First, disable the form from submitting
      $('form#subForm').submit(function() { return false; });
            
      // Hacking together id for email field
      // Replace the xxxxx below:
      // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
      var id = "ekjuj";
      var emailId = id + "-" + id;
	  var emailVal = $("#" + emailId).val();
      
      // Validate email address with regex
	  if (emailVal == '' ){
			
			$(".error ul").html("<li>Veuillez indiquer votre adresse email.</li>");
			$(".error").fadeIn();
			return false;
		}
      else if (!checkEmail(emailId)) {
        $(".error ul").html("<li>Votre adresse email est erronée. Veuillez la corriger.</li>");
		
		$(".error").fadeIn();
        return false;
      }

      
      var dataString = 'email=' + emailVal;
     
      
      // Submit the form via ajax
      $.ajax({
        url: "campaignmonitor/add.php",
        type: "POST",
        data: dataString,
        success: function(){
          // Server-side validation
          
            $("#subForm").hide(); // If successfully submitted hides the form
            $("#confirmation").fadeIn("slow");  // Shows "Thanks for subscribing" div
            $("#confirmation").tabIndex = -1;
            $("#confirmation").focus(); // For screen reader accessibility
            // Fire off Google Analytics fake pageview
            //var pageTracker = _gat._getTracker("UA-XXXXX-X");
            //pageTracker._trackPageview("/newsletter_signup");

        }
      });
    });
	


$('.nextlink a, .prevlink a').dynamicPage({
    'toArea': '#detail_projet',
    'updateTitle': true,
	'fromArea' : '#detail',
    'callback': function() {
        //alert('Content loaded!');
    }
});
		
	
})
