/*
	cookie policy funkcija
*/
function __cookie_policy( opts ) {
	/* default vrijednosti i unesene opcije */
	var settings =	$.extend( {
		wrap:		'#cookie-policy',
		button:		'#cookie-policy-agree',
		name:		'CookiePolicyName',
		value:		'CookiePolicyValue',
		expires:	365,
		path:		'/'
	}, opts || {} );
	/* dal je expires broj */
	if ( isNaN( Number( settings.expires ) ) === true ) {
		settings.expires =	365;
	}
	/* odradi klik */
	$( settings.button ).click(function() {
		/* makni wrap */
		$( settings.wrap ).remove();
		/* postavi cookie */
		$.cookie( settings.name, settings.value, {
			expires:	settings.expires,
			path:		settings.path
		});
	});
};/*
	http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
*/
String.prototype.format = function() {
    var formatted = this;
    for (var i = 0; i < arguments.length; i++) {
        var regexp = new RegExp('\\{'+i+'\\}', 'gi');
        formatted = formatted.replace(regexp, arguments[i]);
    }
    return formatted;
};
/*
	is mail
*/
function is_mail( t ) {
	// mail regex
	var mt = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	// 
	return mt.test( t );
}
/*
	attr funkcija
	element:	element na kojem se trazi atribut
	attr:		naziv atributa
	canbenull:	dal moze biti null, ako ne onda se vraca prazan string
*/
function __attr( element, attr, canbenull ) {
	canbenull =		canbenull === false ? false : true;
	/* element */
	element =		typeof( element ) === 'string' ? $( element ) : element;
	/* attr */
	var v =			element.prop( attr );
	v =				typeof( v ) === 'undefined' ? null : ( v === 'undefined' ? null : v);
	/* return data */
	return canbenull === true && v === null ? null : ( v === null ? '' : v );
}
function uri(t) {
	t = String( t );
	t = t.toLowerCase();
	t = t.replace(/[!?#*_.;,:@\\\|\"\'\$\%&\(\)+=\{\}\[\]<>~]/g, '');
	t = t.replace(/[ \/]/g, '-');
	t = t.replace(/ć/g,"c");
	t = t.replace(/č/g,"c");
	t = t.replace(/š/g,"s");
	t = t.replace(/ž/g,"z");
	t = t.replace(/đ/g,"d");
	// napravi replace dva dasha sve dok postoje dva u komadu
	while (t.match(/--/)) {
		t = t.replace('--', '-');
	}
	// ako je na početku dash makni ga
	if (t.substr(0, 1) == '-') {t = t.substr(1, t.length);}
	// ako je na kraju dash makni ga
	if (t.substr(t.length - 1, 1) == '-') {t = t.substr(0, t.length - 1);}
	/* ne moze biti broj na pocetku */
	if ( t.match('^[0-9]') ) { t =	'uri-' + t;}
	return t;
}
/*
	max width elementa
*/
function max_width( selector, mw ) {
	/* max width check */
	if ( !selector || !mw ) {return false;}
	/* odaberi elemente i provjeri sve */
	selector =		typeof( selector ) === 'string' ? $( selector ) : selector;
	selector.each(function () {
		var t =		$( this );
		var w =		Number( t.width() );
			w =		isNaN( w ) === true ? 99999 : w;
			if ( w > mw ) {
				t.css('width', String( mw ) + 'px' );
			}
	});
}
/*
	min width
*/
function min_width( selector, mw ) {
	/* max width check */
	if ( !selector || !mw ) {return false;}
	/* odaberi elemente i provjeri sve */
	selector =		typeof( selector ) === 'string' ? $( selector ) : selector;
	selector.each(function () {
		var t =		$( this );
		var w =		Number( t.width() );
			w =		isNaN( w ) === true ? mw : w;
			if ( w < mw ) {
				t.css('width', String( mw ) + 'px' );
			}
	});
}



/* mobile menu */

jQuery(document).ready(function($){
	var $lateral_menu_trigger = $('#cd-menu-trigger'),
		$content_wrapper = $('#main-site'),
		$navigation = $('#site-wrap');

	//open-close lateral menu clicking on the menu icon
	$lateral_menu_trigger.on('click', function(event){
		event.preventDefault();
		
		$lateral_menu_trigger.toggleClass('is-clicked');
		$navigation.toggleClass('lateral-menu-is-open');
		$content_wrapper.toggleClass('lateral-menu-is-open').one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(){
			// firefox transitions break when parent overflow is changed, so we need to wait for the end of the trasition to give the body an overflow hidden
			$('body').toggleClass('overflow-hidden');
		});
		$('#cd-lateral-nav').toggleClass('lateral-menu-is-open');
		
		//check if transitions are not supported - i.e. in IE9
		if($('html').hasClass('no-csstransitions')) {
			$('body').toggleClass('overflow-hidden');
		}
	});

	//close lateral menu clicking outside the menu itself
	$content_wrapper.on('click', function(event){
		if( !$(event.target).is('#cd-menu-trigger, #cd-menu-trigger span') ) {
			$lateral_menu_trigger.removeClass('is-clicked');
			$navigation.removeClass('lateral-menu-is-open');
			$content_wrapper.removeClass('lateral-menu-is-open').one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(){
				$('body').removeClass('overflow-hidden');
			});
			$('#cd-lateral-nav').removeClass('lateral-menu-is-open');
			//check if transitions are not supported
			if($('html').hasClass('no-csstransitions')) {
				$('body').removeClass('overflow-hidden');
			}

		}
	});

	//open (or close) submenu items in the lateral menu. Close all the other open submenu items.
	$('.item-has-children').children('a').on('click', function(event){
		event.preventDefault();
		$(this).toggleClass('submenu-open').next('.sub-menu').slideToggle(200).end().parent('.item-has-children').siblings('.item-has-children').children('a').removeClass('submenu-open').next('.sub-menu').slideUp(200);
	});
});




function toTop(){
	
   //if(mobile == false){

    	if(!$('#nekoToTop').length)
	    $('body').append('<a href="#" id="nekoToTop"><i class="icon-up-open"></i></a>');

	    $( document ).scroll(function () {
	    	if ($(this).scrollTop() > 100) {
	    		$('#nekoToTop').slideDown();
	    	} else {
	    		$('#nekoToTop').fadeOut();
	    	}

	    });

	    $('#nekoToTop').click(function (e) {
	    	e.preventDefault();
	    	$("html, body").animate({
	    		scrollTop: 0
	    	}, 800, 'easeInOutCirc');
	    	
	    });
  /* }else{

    	if($('#nekoToTop').length)
    	$('#nekoToTop').remove();

    }*/

};/*
	google map
*/
function __google_map( my_options ) {
	var my_options =	my_options || false;
	// google map add
	__google_map_add( my_options );
}
/*
	add mapu
*/
function __google_map_add( my_options ) {
	var er =		'';
	// MORA postojati
	if ( typeof( my_options.map_x ) == 'undefined' || !my_options.map_x ) {
		er +=		'Missing map_x!\n';
	}
	if ( typeof( my_options.map_y ) == 'undefined' || !my_options.map_y ) {
		er +=		'Missing map_y!\n';
	}
	if ( typeof( my_options.obj_x ) == 'undefined' || !my_options.obj_x ) {
		er +=		'Missing obj_x!\n';
	}
	if ( typeof( my_options.obj_y ) == 'undefined' || !my_options.obj_y ) {
		er +=		'Missing obj_y!\n';
	}
	if ( typeof( my_options.title ) == 'undefined' || !my_options.title ) {
		er +=		'Missing title!\n';
	}
	if ( typeof( my_options.description ) == 'undefined' || !my_options.description ) {
		er +=		'Missing description!';
	}
	my_options.click_me_to_close =		typeof( my_options.close_me ) === 'undefined' ? 'Click me to close map!' : my_options.close_me;
	// ima errora?
	if ( er.length > 1 ) {
		alert( er );
		return false;
	}
	// dodaj cover i wrap
	var html =			'<div id="google-map-popup"><div id="closer" onclick="__google_map_close();">'+my_options.click_me_to_close+'</div>' +
							'<div class="inner" id="google-map-inner"></div>' +
						'</div>';
	$( 'body' ).append( html );
	// shadow?
	if ( typeof( my_options.shadow ) == 'undefined' || !my_options.shadow ) {
		my_options.shadow =		'';
	}
	// latitude and longitude
	var latlng = new google.maps.LatLng( my_options.map_x, my_options.map_y );
	// options for google
	var myOptions = {
		zoom: 16,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.HYBRID,
		labels: true,
		streetViewControl: false
	};
	// where does map go
	var map = new google.maps.Map(document.getElementById("google-map-inner"), myOptions);
	// ikona
	// lokacija na karti
	var aquapos = new google.maps.LatLng( my_options.obj_x, my_options.obj_y );
	var marker = new google.maps.Marker({
		position:	aquapos,
		map:		map,
		icon:		my_options.icon,
		shadow:     my_options.shadow,
		title:		my_options.title,
		animation:	google.maps.Animation.DROP
	});
	var infowindow1 = new google.maps.InfoWindow({
		content:			my_options.description
	});
	google.maps.event.addListener(marker, 'click', function () {
	   infowindow1.open(map, marker);
	});
}
/*
	close map
*/
function __google_map_close() {
	$('#google-map-popup').remove();
};/*
	jquery Carousel with connectivity option
	&copy; 2013, Bruno Zorić<bruno.zoric@gmail.com>
*/
( function ( $, document, window ) {
	// carousel funkcija
	$.fn.Carousel =	function( opts ) {
		// defaults
		var defaults = {
			id:					null,
			container:			'.carousel-container',
			clip:				'.carousel-clip',
			list:				'.articles-wrapper',
			items:				'.box',
			navPrev:			'a.prev',
			navNext:			'a.next',
			pagination:			null,
			offsetTop:			0,
			offsetBottom:		0,
			moveByWidth:		250,
			moveBy:				1,
			allwaysShow:		1,
			animateDuration:	1000,
			animateEasing:		'swing',// linear | swing
			connectWith:		null,
			data:				null
		};
		//
		return this.each(function ( index ) {
			// settings
			var originalSettings =	$.extend( defaults, opts || {} );
			// data za postavljanje na carousel wrap
			originalSettings.data =		{
				total:		0,
				current:	0,
				selected:	0
			};
			// wrap
			var $this =		$( this ).on( 'movePrev', function( ev ) {
				// nađi id
				var id =		__id( this );
				// move prev
				__movePrev( id );
			}).on( 'moveNext', function( ev ) {
				// nađi id
				var id =		__id( this );
				// move next
				__moveNext( id );
			}).on( 'moveTo', function( ev, page ) {
				// nađi id
				var id =		__id( this );
				// move to page
				__moveToPage( id, page );
			});
			// id
			var id =		$this.attr( 'id' );
				var idSample =	'jquery-Carousel-wrap-';
				// postavi i pronađi id
				if ( typeof( id ) === 'undefined' || id === 'undefined' || id === null || id.length === 0 ) {
					// slozi id
					id =	idSample + index;
					// dok postoji id?
					while ( $( '#' +id ).length > 0 ) {
						index++;
						id =	idSample + index;
					}
					// postavi id
					$this.prop( 'id', id );
				}
				// postavi rel
				__id( $this, id );
					// settings id
					originalSettings.id =		id;
			// max height
			var maxHeight =		0;
				// svi itemi
				var $itemsAll =	$this.find( originalSettings.items );
				//alert( $itemsAll.length );
				// total itema
				originalSettings.data.total =	$itemsAll.length;
			// te postavi total elemenata
			$itemsAll.each(function( index, element ) {
				//alert( index );
				// visina trenutnog elementa
				var h =		Number( $( this ).height() );
				// ako je veća od maxHeight onda stavi trenutnu
				if ( h > maxHeight ) {
					maxHeight =		h;
					itemHeight =	h;
				}
			}).eq( 0 ).addClass( 'current' );
			// postavljen je offset top ?
			if ( originalSettings.offsetTop > 0 ) {
				maxHeight =		maxHeight + originalSettings.offsetTop;
			}
			// postavljen je offset bottom ?
			if ( originalSettings.offsetBottom > 0 ) {
				maxHeight =		maxHeight + originalSettings.offsetBottom;
			}
			// postavi clip visinu
			$this.find( originalSettings.clip ).css( 'height', String( maxHeight ) + 'px' );
			// ima navPrev?
			if ( originalSettings.navPrev !== null && originalSettings.navPrev.length > 0 ) {
				// postavi prev
				var navPrev =	$this.find( originalSettings.navPrev ).click(function( ev ) {
					// nađi id
					var id =		__id( this );
					// settings
					var settings =	__settings( id );
					// pomakni za -
					__movePrev( id );
					// ima connectWith?
					if ( settings.connectWith ) {
						// move next na spojenom carouselu
						$( settings.connectWith ).trigger( 'movePrev' );
					}
					// uvijek vrati false
					return false;
				});
					// postavi id na nav next
					__id( navPrev, id );
			}
			// ima navNext
			if ( originalSettings.navNext !== null && originalSettings.navNext.length > 0 ) {
				// postavi next
				var navNext =	$this.find( originalSettings.navNext ).click(function( ev ) {
					// nađi id
					var id =		__id( this );
					// settings
					var settings =	__settings( id );
					// pomakni za +
					//__moveNext( id );
					$( '#' + id ).trigger( 'moveNext' );
					// ima connectWith?
					if ( settings.connectWith ) {
						// move next na spojenom carouselu
						$( settings.connectWith ).trigger( 'moveNext' );
					}
					// uvijek vrati false
					return false;
				});
					// postavi id na nav next
					__id( navNext, id );
			}
			// paginacija ako postoji
			if ( originalSettings.pagination !== null && originalSettings.pagination.length > 0 ) {
				// izracunaj broj stranica
				var pages =		Math.ceil( originalSettings.data.total / originalSettings.moveBy );
				// postavi paginaciju, prvo ide ul
				var _ul =	'<ul class="clearafter" data-id="' + id + '">';
				for ( var i = 1; i <= pages; i++ ) {
					_ul +=	('<li class="' + ( i === 1 ? 'first current' : ( i === originalSettings.data.total ? 'last' : '' ) ) + '"><a rel="' + i + '">' + i + '</a></li>');
				}
				_ul +=		'</ul>';
				// postavi listu u paginaciju
				$this.find( originalSettings.pagination ).empty().append(
					$( _ul ).find( 'li a' ).click(function() {
						var a =		$( this );
						var li =	a.parent();
						var ul =	li.parent();
						var rel =	a.attr( 'rel' );
						// nađi id
						var id =		__id( ul );
						// move to
						$( '#' + id ).trigger( 'moveTo', [ rel ] );
					}).end()
				);
			}
			// postavi postavke
			__settings( id, originalSettings );
			// postavi button statuse
			__setButtonStatus( originalSettings );
			// null original settingsa
			originalSettings =	null;
			$itemsAll =			null;
			/*
				id
			*/
			function __id( element, id ) {
				// postavljen je id
				if ( typeof( id ) === 'string' && id !== null && id.length > 0 ) {
					// postavi element
					$( element ).attr( 'data-id', id );
					// vrati id za svaki slucaj
					return id;
				}
				// vrati id
				else {
					return $( element ).attr( 'data-id' );
				}
			}
			/*
				postavi settings
			*/
			function __settings( id, settings ) {
				settings =		settings || null;
				// element
				var element =	$( '#' + id );
				// postavljen je id i settings i oboje su objekti
				if ( typeof( id ) === 'string' && typeof( settings ) === 'object' && id && settings ) {
					// postavi data
					// * razlog? retardirani javascript drzi pointer na prije postavljeni objekt
					// * tako da kad se napravi novi insert sa data on postavi sve stare data na nove vrijednosti
					// ** retardacija!
					var data =	{
						id:					settings.id,
						container:			settings.container,
						clip:				settings.clip,
						list:				settings.list,
						items:				settings.items,
						navPrev:			settings.navPrev,
						navNext:			settings.navNext,
						pagination:			settings.pagination,
						offsetTop:			settings.offsetTop,
						offsetBottom:		settings.offsetBottom,
						moveByWidth:		settings.moveByWidth,
						moveBy:				settings.moveBy,
						allwaysShow:		settings.allwaysShow,
						animateDuration:	settings.animateDuration,
						animateEasing:		settings.animateEasing,
						connectWith:		settings.connectWith,
						data:				{
							total:				settings.data.total,
							current:			settings.data.current,
							selected:			settings.data.selected
						}
					};
					element.data( '__CAROUSEL__', data );
				}
				// samo id je postavljen
				else if ( typeof ( id ) === 'string' && id !== null && id.length > 0 ) {
					// vrati carousel podatke
					return element.data( '__CAROUSEL__' );
				}
			}
			/*
				status buttona ( enabled, disabled )
			*/
			function __setButtonStatus( settings ) {
				var wrap =		$( '#' + settings.id );
				var navPrev =	wrap.find( settings.navPrev );
				var navNext =	wrap.find( settings.navNext );
				// current === 0?
				// disable previous gumba
				if ( settings.data.current === 0 ) {
					navPrev.addClass( 'disabled' );
				}
				// enable previous gumba
				else if ( settings.data.current <= settings.data.total - settings.moveBy ) {
					navPrev.removeClass( 'disabled' );
				}
				// disable next gumba
				if ( settings.data.current >= settings.data.total - settings.moveBy ) {
					navNext.addClass( 'disabled' );
				}
				// enable next gumba
				else if ( settings.data.current < settings.data.total - settings.moveBy ) {
					navNext.removeClass( 'disabled' );
				}
			}
			/*
				pomakni carousel za - settings.moveBy
			*/
			function __movePrev( id ) {
				// settings objekt
				var settings =		__settings( id );
				// prev se mice za moveBy
				var moveTo =	settings.data.current - settings.moveBy;
					settings.data.selected =		settings.data.selected - 1 < 0 ? 0 : settings.data.selected - 1;
				// ako je moveTo < 0 onda postavi na 0
				if ( moveTo < 0 ) {
					moveTo =	0;
				}
				// makni current sa itema
				$( '#' + id ).find( settings.items ).removeClass( 'current' )
					// te dodaj na trenutni item
					.eq( settings.data.selected ).addClass( 'current' );
				// ako je slucajno current === 0 onda vrati false
				if ( settings.data.current === 0 ) {
					return false;
				}
				// postavi current
				settings.data.current =		moveTo;
				// move to
				__moveTo( moveTo, settings );
			}
			/*
				pomakni carousel za + settings.moveBy
			*/
			function __moveNext( id ) {
				// settings objekt
				var settings =		__settings( id );
				// prev se mice za moveBy
				var moveTo =	settings.data.current + settings.moveBy;
				var newSelected =	settings.data.selected + 1 >= settings.data.total ? settings.data.total : settings.data.selected + 1;
				// ako je selected >= total
				if ( newSelected >= settings.data.total ) {
					return false;
				}
				settings.data.selected =	newSelected;
				// ako je moveTo < 0 onda postavi na 0
				if ( moveTo > settings.data.total - settings.allwaysShow ) {
					moveTo =	settings.data.total - settings.allwaysShow;
				}
				// makni current sa itema
				$( '#' + id ).find( settings.items ).removeClass( 'current' )
					// te dodaj na trenutni item
					.eq( settings.data.selected ).addClass( 'current' );
				// settings.data.current
				var sdc =	settings.data.current;
					// settings.current
					settings.data.current =	moveTo;
				// ako je slucajno current === 0 onda vrati false
				if ( sdc >= settings.data.total - settings.allwaysShow ) {
					return false;
				}
				// move to
				__moveTo( moveTo, settings );
			}
			/*
				move to page
				pomakni carousel na određenu stranicu
			*/
			function __moveToPage( id, page ) {
				// reduced
				var reduced =		0;
				// settings objekt
				var settings =		__settings( id );
				// kamo ide?
				var moveTo =		( page - 1 ) * settings.moveBy;
				// move to je preveliko?
				if ( moveTo + settings.allwaysShow > settings.data.total ) {
					moveTo =		settings.data.total - settings.allwaysShow;
					reduced =		1;
				}
				// ako moveTo === current
				if ( moveTo === settings.data.current ) {
					return false;
				}
				// selected
				settings.data.selected =	( moveTo / settings.moveBy ) + reduced;
				// settings.current
				settings.data.current =		moveTo;
				// page stavi na potrebni
				// move to
				__moveTo( moveTo, settings );
			}
			/*
				moveTo
			*/
			function __moveTo( moveTo, settings ) {
				// ima paginacije?
				if ( settings.pagination !== null && settings.pagination.length > 0 ) {
					// makni current sa itema
					$( '#' + settings.id ).find( settings.pagination + ' li' ).removeClass( 'current' )
						// te dodaj na trenutni item
						.eq( settings.data.selected ).addClass( 'current' );
				}
				// margina lijevo
				var marginLeft =	( moveTo * settings.moveByWidth ) * -1;
				// animiraj wrapper unutar c na marginLeft
				$( '#' + settings.id ).find( settings.list ).stop().animate({
					'margin-left':		Number( marginLeft ) + 'px'
				}, settings.animateDuration, settings.animateEasing, function() {
					// postavi settings
					__settings( settings.id, settings );
					// status buttona za prev i next
					__setButtonStatus( settings );
				});
			}
		});
	}
}( jQuery, document, this ) );;// ColorBox v1.3.19 - jQuery lightbox plugin
// (c) 2011 Jack Moore - jacklmoore.com
// License: http://www.opensource.org/licenses/mit-license.php
(function ($, document, window) {
    var
    // Default settings object.	
    // See http://jacklmoore.com/colorbox for details.
    defaults = {
        transition: "elastic",
        speed: 300,
        width: false,
        initialWidth: "600",
        innerWidth: false,
        maxWidth: false,
        height: false,
        initialHeight: "450",
        innerHeight: false,
        maxHeight: false,
        scalePhotos: true,
        scrolling: true,
        inline: false,
        html: false,
        iframe: false,
        fastIframe: true,
        photo: false,
        href: false,
        title: false,
        rel: false,
        opacity: 0.9,
        preloading: true,
        current: "slika {current} od {total}",
        previous: "pro�la",
        next: "sljede�a",
        close: "zatvori",
        open: false,
        returnFocus: true,
        reposition: true,
        loop: true,
        slideshow: false,
        slideshowAuto: true,
        slideshowSpeed: 2500,
        slideshowStart: "pokreni slideshow",
        slideshowStop: "zaustavi slideshow",
        onOpen: false,
        onLoad: false,
        onComplete: false,
        onCleanup: false,
        onClosed: false,
        overlayClose: true,		
        escKey: true,
        arrowKey: true,
        top: false,
        bottom: false,
        left: false,
        right: false,
        fixed: false,
        data: undefined
    },
	
    // Abstracting the HTML and event identifiers for easy rebranding
    colorbox = 'colorbox',
    prefix = 'cbox',
    boxElement = prefix + 'Element',
    
    // Events	
    event_open = prefix + '_open',
    event_load = prefix + '_load',
    event_complete = prefix + '_complete',
    event_cleanup = prefix + '_cleanup',
    event_closed = prefix + '_closed',
    event_purge = prefix + '_purge',
    
    // Special Handling for IE
    isIE = !$.support.opacity && !$.support.style, // IE7 & IE8
    isIE6 = isIE && !window.XMLHttpRequest, // IE6
    event_ie6 = prefix + '_IE6',

    // Cached jQuery Object Variables
    $overlay,
    $box,
    $wrap,
    $content,
    $topBorder,
    $leftBorder,
    $rightBorder,
    $bottomBorder,
    $related,
    $window,
    $loaded,
    $loadingBay,
    $loadingOverlay,
    $title,
    $current,
    $slideshow,
    $next,
    $prev,
    $close,
    $groupControls,
    
    // Variables for cached values or use across multiple functions
    settings,
    interfaceHeight,
    interfaceWidth,
    loadedHeight,
    loadedWidth,
    element,
    index,
    photo,
    open,
    active,
    closing,
    loadingTimer,
    publicMethod,
    div = "div",
    init;

	// ****************
	// HELPER FUNCTIONS
	// ****************
    
	// Convience function for creating new jQuery objects
    function $tag(tag, id, css) {
		var element = document.createElement(tag);

		if (id) {
			element.id = prefix + id;
		}

		if (css) {
			element.style.cssText = css;
		}

		return $(element);
    }

	// Determine the next and previous members in a group.
	function getIndex(increment) {
		var 
		max = $related.length, 
		newIndex = (index + increment) % max;
		
		return (newIndex < 0) ? max + newIndex : newIndex;
	}

	// Convert '%' and 'px' values to integers
	function setSize(size, dimension) {
		return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : $window.height()) / 100) : 1) * parseInt(size, 10));
	}
	
	// Checks an href to see if it is a photo.
	// There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
	function isImage(url) {
		return settings.photo || /\.(gif|png|jpe?g|bmp|ico)((#|\?).*)?$/i.test(url);
	}
	
	// Assigns function results to their respective properties
	function makeSettings() {
        var i;
        settings = $.extend({}, $.data(element, colorbox));
        
		for (i in settings) {
			if ($.isFunction(settings[i]) && i.slice(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
			    settings[i] = settings[i].call(element);
			}
		}
        
		settings.rel = settings.rel || element.rel || 'nofollow';
		settings.href = settings.href || $(element).attr('href');
		settings.title = settings.title || element.title;
        
        if (typeof settings.href === "string") {
            settings.href = $.trim(settings.href);
        }
	}

	function trigger(event, callback) {
		$.event.trigger(event);
		if (callback) {
			callback.call(element);
		}
	}

	// Slideshow functionality
	function slideshow() {
		var
		timeOut,
		className = prefix + "Slideshow_",
		click = "click." + prefix,
		start,
		stop,
		clear;
		
		if (settings.slideshow && $related[1]) {
			start = function () {
				$slideshow
					.text(settings.slideshowStop)
					.unbind(click)
					.bind(event_complete, function () {
						if (settings.loop || $related[index + 1]) {
							timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
						}
					})
					.bind(event_load, function () {
						clearTimeout(timeOut);
					})
					.one(click + ' ' + event_cleanup, stop);
				$box.removeClass(className + "off").addClass(className + "on");
				timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
			};
			
			stop = function () {
				clearTimeout(timeOut);
				$slideshow
					.text(settings.slideshowStart)
					.unbind([event_complete, event_load, event_cleanup, click].join(' '))
					.one(click, function () {
						publicMethod.next();
						start();
					});
				$box.removeClass(className + "on").addClass(className + "off");
			};
			
			if (settings.slideshowAuto) {
				start();
			} else {
				stop();
			}
		} else {
            $box.removeClass(className + "off " + className + "on");
        }
	}

	function launch(target) {
		if (!closing) {
			
			element = target;
			
			makeSettings();
			
			$related = $(element);
			
			index = 0;
			
			if (settings.rel !== 'nofollow') {
				$related = $('.' + boxElement).filter(function () {
					var relRelated = $.data(this, colorbox).rel || this.rel;
					return (relRelated === settings.rel);
				});
				index = $related.index(element);
				
				// Check direct calls to ColorBox.
				if (index === -1) {
					$related = $related.add(element);
					index = $related.length - 1;
				}
			}
			
			if (!open) {
				open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
				
				$box.show();
				
				if (settings.returnFocus) {
					$(element).blur().one(event_closed, function () {
						$(this).focus();
					});
				}
				
				// +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
				$overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
				
				// Opens inital empty ColorBox prior to content being loaded.
				settings.w = setSize(settings.initialWidth, 'x');
				settings.h = setSize(settings.initialHeight, 'y');
				publicMethod.position();
				
				if (isIE6) {
					$window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
						$overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
					}).trigger('resize.' + event_ie6);
				}
				
				trigger(event_open, settings.onOpen);
				
				$groupControls.add($title).hide();
				
				$close.html(settings.close).show();
			}
			
			publicMethod.load(true);
		}
	}

	// ColorBox's markup needs to be added to the DOM prior to being called
	// so that the browser will go ahead and load the CSS background images.
	function appendHTML() {
		if (!$box && document.body) {
			init = false;

			$window = $(window);
			$box = $tag(div).attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''}).hide();
			$overlay = $tag(div, "Overlay", isIE6 ? 'position:absolute' : '').hide();
			$wrap = $tag(div, "Wrapper");
			$content = $tag(div, "Content").append(
				$loaded = $tag(div, "LoadedContent", 'width:0; height:0; overflow:hidden'),
				$loadingOverlay = $tag(div, "LoadingOverlay").add($tag(div, "LoadingGraphic")),
				$title = $tag(div, "Title"),
				$current = $tag(div, "Current"),
				$next = $tag(div, "Next"),
				$prev = $tag(div, "Previous"),
				$slideshow = $tag(div, "Slideshow").bind(event_open, slideshow),
				$close = $tag(div, "Close")
			);
			
			$wrap.append( // The 3x3 Grid that makes up ColorBox
				$tag(div).append(
					$tag(div, "TopLeft"),
					$topBorder = $tag(div, "TopCenter"),
					$tag(div, "TopRight")
				),
				$tag(div, false, 'clear:left').append(
					$leftBorder = $tag(div, "MiddleLeft"),
					$content,
					$rightBorder = $tag(div, "MiddleRight")
				),
				$tag(div, false, 'clear:left').append(
					$tag(div, "BottomLeft"),
					$bottomBorder = $tag(div, "BottomCenter"),
					$tag(div, "BottomRight")
				)
			).find('div div').css({'float': 'left'});
			
			$loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none');
			
			$groupControls = $next.add($prev).add($current).add($slideshow);

			$(document.body).append($overlay, $box.append($wrap, $loadingBay));
		}
	}

	// Add ColorBox's event bindings
	function addBindings() {
		if ($box) {
			if (!init) {
				init = true;

				// Cache values needed for size calculations
				interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
				interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
				loadedHeight = $loaded.outerHeight(true);
				loadedWidth = $loaded.outerWidth(true);
				
				// Setting padding to remove the need to do size conversions during the animation step.
				$box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth});

				// Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
				$next.click(function () {
					publicMethod.next();
				});
				$prev.click(function () {
					publicMethod.prev();
				});
				$close.click(function () {
					publicMethod.close();
				});
				$overlay.click(function () {
					if (settings.overlayClose) {
						publicMethod.close();
					}
				});
				
				// Key Bindings
				$(document).bind('keydown.' + prefix, function (e) {
					var key = e.keyCode;
					if (open && settings.escKey && key === 27) {
						e.preventDefault();
						publicMethod.close();
					}
					if (open && settings.arrowKey && $related[1]) {
						if (key === 37) {
							e.preventDefault();
							$prev.click();
						} else if (key === 39) {
							e.preventDefault();
							$next.click();
						}
					}
				});

				$('.' + boxElement, document).live('click', function (e) {
			        // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
			        // See: http://jacklmoore.com/notes/click-events/
			        if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey)) {
			            e.preventDefault();
			            launch(this);
			        }
			    });
			}
			return true;
		}
		return false;
	}

	// Don't do anything if ColorBox already exists.
	if ($.colorbox) {
		return;
	}

	// Append the HTML when the DOM loads
	$(appendHTML);


	// ****************
	// PUBLIC FUNCTIONS
	// Usage format: $.fn.colorbox.close();
	// Usage from within an iframe: parent.$.fn.colorbox.close();
	// ****************
	
	publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
		var $this = this;
		
        options = options || {};
        
        appendHTML();

		if (addBindings()) {
			if (!$this[0]) {
				if ($this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
	                return $this;
	            }
	            // if no selector was given (ie. $.colorbox()), create a temporary element to work with
				$this = $('<a/>');
				options.open = true; // assume an immediate open
			}
			
			if (callback) {
				options.onComplete = callback;
			}
			
			$this.each(function () {
				$.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
			}).addClass(boxElement);
			
	        if (($.isFunction(options.open) && options.open.call($this)) || options.open) {
				launch($this[0]);
			}
		}
        
		return $this;
	};

	publicMethod.position = function (speed, loadedCallback) {
        var 
        top = 0, 
        left = 0, 
        offset = $box.offset(),
        scrollTop = $window.scrollTop(), 
        scrollLeft = $window.scrollLeft();
        
        $window.unbind('resize.' + prefix);

        // remove the modal so that it doesn't influence the document width/height        
        $box.css({top: -9e4, left: -9e4});

        if (settings.fixed && !isIE6) {
			offset.top -= scrollTop;
			offset.left -= scrollLeft;
            $box.css({position: 'fixed'});
        } else {
            top = scrollTop;
            left = scrollLeft;
            $box.css({position: 'absolute'});
        }

		// keeps the top and left positions within the browser's viewport.
        if (settings.right !== false) {
            left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.right, 'x'), 0);
        } else if (settings.left !== false) {
            left += setSize(settings.left, 'x');
        } else {
            left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
        }
        
        if (settings.bottom !== false) {
            top += Math.max($window.height() - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
        } else if (settings.top !== false) {
            top += setSize(settings.top, 'y');
        } else {
            top += Math.round(Math.max($window.height() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
        }

        $box.css({top: offset.top, left: offset.left});

		// setting the speed to 0 to reduce the delay between same-sized content.
		speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
        
		// this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
		// but it has to be shrank down around the size of div#colorbox when it's done.  If not,
		// it can invoke an obscure IE bug when using iframes.
		$wrap[0].style.width = $wrap[0].style.height = "9999px";
		
		function modalDimensions(that) {
			$topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
			$content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
		}
		
		$box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left}, {
			duration: speed,
			complete: function () {
				modalDimensions(this);
				
				active = false;
				
				// shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
				$wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
				$wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
                
                if (settings.reposition) {
	                setTimeout(function () {  // small delay before binding onresize due to an IE8 bug.
	                    $window.bind('resize.' + prefix, publicMethod.position);
	                }, 1);
	            }

				if (loadedCallback) {
					loadedCallback();
				}
			},
			step: function () {
				modalDimensions(this);
			}
		});
	};

	publicMethod.resize = function (options) {
		if (open) {
			options = options || {};
			
			if (options.width) {
				settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
			}
			if (options.innerWidth) {
				settings.w = setSize(options.innerWidth, 'x');
			}
			$loaded.css({width: settings.w});
			
			if (options.height) {
				settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
			}
			if (options.innerHeight) {
				settings.h = setSize(options.innerHeight, 'y');
			}
			if (!options.innerHeight && !options.height) {
				$loaded.css({height: "auto"});
				settings.h = $loaded.height();
			}
			$loaded.css({height: settings.h});
			
			publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
		}
	};

	publicMethod.prep = function (object) {
		if (!open) {
			return;
		}
		
		var callback, speed = settings.transition === "none" ? 0 : settings.speed;
		
		$loaded.remove();
		$loaded = $tag(div, 'LoadedContent').append(object);
		
		function getWidth() {
			settings.w = settings.w || $loaded.width();
			settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
			return settings.w;
		}
		function getHeight() {
			settings.h = settings.h || $loaded.height();
			settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
			return settings.h;
		}
		
		$loaded.hide()
		.appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
		.css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
		.css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
		.prependTo($content);
		
		$loadingBay.hide();
		
		// floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
		//$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
		
        $(photo).css({'float': 'none'});
        
		// Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
		if (isIE6) {
			$('select').not($box.find('select')).filter(function () {
				return this.style.visibility !== 'hidden';
			}).css({'visibility': 'hidden'}).one(event_cleanup, function () {
				this.style.visibility = 'inherit';
			});
		}
		
		callback = function () {
            var preload, i, total = $related.length, iframe, frameBorder = 'frameBorder', allowTransparency = 'allowTransparency', complete, src, img;
            
            if (!open) {
                return;
            }
            
            function removeFilter() {
                if (isIE) {
                    $box[0].style.removeAttribute('filter');
                }
            }
            
            complete = function () {
                clearTimeout(loadingTimer);
                $loadingOverlay.hide();
                trigger(event_complete, settings.onComplete);
            };
            
            if (isIE) {
                //This fadeIn helps the bicubic resampling to kick-in.
                if (photo) {
                    $loaded.fadeIn(100);
                }
            }
            
            $title.html(settings.title).add($loaded).show();
            
            if (total > 1) { // handle grouping
                if (typeof settings.current === "string") {
                    $current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show();
                }
                
                $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
                $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
				
                if (settings.slideshow) {
                    $slideshow.show();
                }
				
                // Preloads images within a rel group
                if (settings.preloading) {
					preload = [
						getIndex(-1),
						getIndex(1)
					];
					while (i = $related[preload.pop()]) {
						src = $.data(i, colorbox).href || i.href;
						if ($.isFunction(src)) {
							src = src.call(i);
						}
						if (isImage(src)) {
							img = new Image();
							img.src = src;
						}
					}
                }
            } else {
                $groupControls.hide();
            }
            
            if (settings.iframe) {
                iframe = $tag('iframe')[0];
                
                if (frameBorder in iframe) {
                    iframe[frameBorder] = 0;
                }
                if (allowTransparency in iframe) {
                    iframe[allowTransparency] = "true";
                }
                // give the iframe a unique name to prevent caching
                iframe.name = prefix + (+new Date());
                if (settings.fastIframe) {
                    complete();
                } else {
                    $(iframe).one('load', complete);
                }
                iframe.src = settings.href;
                if (!settings.scrolling) {
                    iframe.scrolling = "no";
                }
                $(iframe).addClass(prefix + 'Iframe').appendTo($loaded).one(event_purge, function () {
                    iframe.src = "//about:blank";
                });
            } else {
                complete();
            }
            
            if (settings.transition === 'fade') {
                $box.fadeTo(speed, 1, removeFilter);
            } else {
                removeFilter();
            }
		};
		
		if (settings.transition === 'fade') {
			$box.fadeTo(speed, 0, function () {
				publicMethod.position(0, callback);
			});
		} else {
			publicMethod.position(speed, callback);
		}
	};

	publicMethod.load = function (launched) {
		var href, setResize, prep = publicMethod.prep;
		
		active = true;
		
		photo = false;
		
		element = $related[index];
		
		if (!launched) {
			makeSettings();
		}
		
		trigger(event_purge);
		
		trigger(event_load, settings.onLoad);
		
		settings.h = settings.height ?
				setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
				settings.innerHeight && setSize(settings.innerHeight, 'y');
		
		settings.w = settings.width ?
				setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
				settings.innerWidth && setSize(settings.innerWidth, 'x');
		
		// Sets the minimum dimensions for use in image scaling
		settings.mw = settings.w;
		settings.mh = settings.h;
		
		// Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
		// If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
		if (settings.maxWidth) {
			settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
			settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
		}
		if (settings.maxHeight) {
			settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
			settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
		}
		
		href = settings.href;
		
        loadingTimer = setTimeout(function () {
            $loadingOverlay.show();
        }, 100);
        
		if (settings.inline) {
			// Inserts an empty placeholder where inline content is being pulled from.
			// An event is bound to put inline content back when ColorBox closes or loads new content.
			$tag(div).hide().insertBefore($(href)[0]).one(event_purge, function () {
				$(this).replaceWith($loaded.children());
			});
			prep($(href));
		} else if (settings.iframe) {
			// IFrame element won't be added to the DOM until it is ready to be displayed,
			// to avoid problems with DOM-ready JS that might be trying to run in that iframe.
			prep(" ");
		} else if (settings.html) {
			prep(settings.html);
		} else if (isImage(href)) {
			$(photo = new Image())
			.addClass(prefix + 'Photo')
			.error(function () {
				settings.title = false;
				prep($tag(div, 'Error').text('This image could not be loaded'));
			})
			.load(function () {
				var percent;
				photo.onload = null; //stops animated gifs from firing the onload repeatedly.
				
				if (settings.scalePhotos) {
					setResize = function () {
						photo.height -= photo.height * percent;
						photo.width -= photo.width * percent;	
					};
					if (settings.mw && photo.width > settings.mw) {
						percent = (photo.width - settings.mw) / photo.width;
						setResize();
					}
					if (settings.mh && photo.height > settings.mh) {
						percent = (photo.height - settings.mh) / photo.height;
						setResize();
					}
				}
				
				if (settings.h) {
					photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
				}
				
				if ($related[1] && (settings.loop || $related[index + 1])) {
					photo.style.cursor = 'pointer';
					photo.onclick = function () {
                        publicMethod.next();
                    };
				}
				
				if (isIE) {
					photo.style.msInterpolationMode = 'bicubic';
				}
				
				setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
					prep(photo);
				}, 1);
			});
			
			setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
				photo.src = href;
			}, 1);
		} else if (href) {
			$loadingBay.load(href, settings.data, function (data, status, xhr) {
				prep(status === 'error' ? $tag(div, 'Error').text('Request unsuccessful: ' + xhr.statusText) : $(this).contents());
			});
		}
	};
        
	// Navigates to the next page/image in a set.
	publicMethod.next = function () {
		if (!active && $related[1] && (settings.loop || $related[index + 1])) {
			index = getIndex(1);
			publicMethod.load();
		}
	};
	
	publicMethod.prev = function () {
		if (!active && $related[1] && (settings.loop || index)) {
			index = getIndex(-1);
			publicMethod.load();
		}
	};

	// Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
	publicMethod.close = function () {
		if (open && !closing) {
			
			closing = true;
			
			open = false;
			
			trigger(event_cleanup, settings.onCleanup);
			
			$window.unbind('.' + prefix + ' .' + event_ie6);
			
			$overlay.fadeTo(200, 0);
			
			$box.stop().fadeTo(300, 0, function () {
                 
				$box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
				
				trigger(event_purge);
				
				$loaded.remove();
				
				setTimeout(function () {
					closing = false;
					trigger(event_closed, settings.onClosed);
				}, 1);
			});
		}
	};

	// Removes changes ColorBox made to the document, but does not remove the plugin
	// from jQuery.
	publicMethod.remove = function () {
		$([]).add($box).add($overlay).remove();
		$box = null;
		$('.' + boxElement)
			.removeData(colorbox)
			.removeClass(boxElement)
			.die();
	};

	// A method for fetching the current element ColorBox is referencing.
	// returns a jQuery object.
	publicMethod.element = function () {
		return $(element);
	};

	publicMethod.settings = defaults;

}(jQuery, document, this));;/*!
 * jQuery Cookie Plugin v1.3.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2013 Klaus Hartl
 * Released under the MIT license
 */
(function (factory) {
	if (typeof define === 'function' && define.amd) {
		// AMD. Register as anonymous module.
		define(['jquery'], factory);
	} else {
		// Browser globals.
		factory(jQuery);
	}
}(function ($) {

	var pluses = /\+/g;

	function decode(s) {
		if (config.raw) {
			return s;
		}
		return decodeURIComponent(s.replace(pluses, ' '));
	}

	function decodeAndParse(s) {
		if (s.indexOf('"') === 0) {
			// This is a quoted cookie as according to RFC2068, unescape...
			s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
		}

		s = decode(s);

		try {
			return config.json ? JSON.parse(s) : s;
		} catch(e) {}
	}

	var config = $.cookie = function (key, value, options) {

		// Write
		if (value !== undefined) {
			options = $.extend({}, config.defaults, options);

			if (typeof options.expires === 'number') {
				var days = options.expires, t = options.expires = new Date();
				t.setDate(t.getDate() + days);
			}

			value = config.json ? JSON.stringify(value) : String(value);

			return (document.cookie = [
				config.raw ? key : encodeURIComponent(key),
				'=',
				config.raw ? value : encodeURIComponent(value),
				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
				options.path    ? '; path=' + options.path : '',
				options.domain  ? '; domain=' + options.domain : '',
				options.secure  ? '; secure' : ''
			].join(''));
		}

		// Read
		var cookies = document.cookie.split('; ');
		var result = key ? undefined : {};
		for (var i = 0, l = cookies.length; i < l; i++) {
			var parts = cookies[i].split('=');
			var name = decode(parts.shift());
			var cookie = parts.join('=');

			if (key && key === name) {
				result = decodeAndParse(cookie);
				break;
			}

			if (!key) {
				result[name] = decodeAndParse(cookie);
			}
		}

		return result;
	};

	config.defaults = {};

	$.removeCookie = function (key, options) {
		if ($.cookie(key) !== undefined) {
			// Must not alter options, thus extending a fresh object...
			$.cookie(key, '', $.extend({}, options, { expires: -1 }));
			return true;
		}
		return false;
	};

}));;/*!
*  Sharrre.com - Make your sharing widget!
*  Version: beta 1.3.5
*  Author: Julien Hany
*  License: MIT http://en.wikipedia.org/wiki/MIT_License or GPLv2 http://en.wikipedia.org/wiki/GNU_General_Public_License
*/

; (function ($, window, document, undefined) {

    /* Defaults
    ================================================== */
    var pluginName = 'sharrre',
  defaults = {
      className: 'sharrre',
      share: {
          googlePlus: false,
          facebook: false,
          twitter: false,
          digg: false,
          delicious: false,
          stumbleupon: false,
          linkedin: false,
          pinterest: false
      },
      shareTotal: 0,
      template: '',
      title: '',
      url: document.location.href,
      text: document.title,
      urlCurl: 'sharrre.php',  //PHP script for google plus...
      count: {}, //counter by social network
      total: 0,  //total of sharing
      shorterTotal: true, //show total by k or M when number is to big
      enableHover: true, //disable if you want to personalize hover event with callback
      enableCounter: true, //disable if you just want use buttons
      enableTracking: false, //tracking with google analitycs
      hover: function () { }, //personalize hover event with this callback function
      hide: function () { }, //personalize hide event with this callback function
      click: function () { }, //personalize click event with this callback function
      render: function () { }, //personalize render event with this callback function
      buttons: {  //settings for buttons
          googlePlus: {  //http://www.google.com/webmasters/+1/button/
              url: '',  //if you need to personnalize button url
              urlCount: false,  //if you want to use personnalize button url on global counter
              size: 'medium',
              lang: 'en-US',
              annotation: ''
          },
          facebook: { //http://developers.facebook.com/docs/reference/plugins/like/
              url: '',  //if you need to personalize url button
              urlCount: false,  //if you want to use personnalize button url on global counter
              action: 'like',
              layout: 'button_count',
              width: '',
              send: 'false',
              faces: 'false',
              colorscheme: '',
              font: '',
              lang: 'en_US'
          },
          twitter: {  //http://twitter.com/about/resources/tweetbutton
              url: '',  //if you need to personalize url button
              urlCount: false,  //if you want to use personnalize button url on global counter
              count: 'horizontal',
              hashtags: '',
              via: '',
              related: '',
              lang: 'en'
          },
          digg: { //http://about.digg.com/downloads/button/smart
              url: '',  //if you need to personalize url button
              urlCount: false,  //if you want to use personnalize button url on global counter
              type: 'DiggCompact'
          },
          delicious: {
              url: '',  //if you need to personalize url button
              urlCount: false,  //if you want to use personnalize button url on global counter
              size: 'medium' //medium or tall
          },
          stumbleupon: {  //http://www.stumbleupon.com/badges/
              url: '',  //if you need to personalize url button
              urlCount: false,  //if you want to use personnalize button url on global counter
              layout: '1'
          },
          linkedin: {  //http://developer.linkedin.com/plugins/share-button
              url: '',  //if you need to personalize url button
              urlCount: false,  //if you want to use personnalize button url on global counter
              counter: ''
          },
          pinterest: { //http://pinterest.com/about/goodies/
              url: '',  //if you need to personalize url button
              media: '',
              description: '',
              layout: 'horizontal'
          }
      }
  },
    /* Json URL to get count number
    ================================================== */
  urlJson = {
      googlePlus: "",

      //new FQL method by Sire
      facebook: "https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27{url}%27&callback=?",
      //old method facebook: "http://graph.facebook.com/?id={url}&callback=?",
      //facebook : "http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls={url}&format=json"

      twitter: '',// "http://cdn.api.twitter.com/1/urls/count.json?url={url}&callback=?",
      digg: "http://services.digg.com/2.0/story.getInfo?links={url}&type=javascript&callback=?",
      delicious: 'http://feeds.delicious.com/v2/json/urlinfo/data?url={url}&callback=?',
      //stumbleupon: "http://www.stumbleupon.com/services/1.01/badge.getinfo?url={url}&format=jsonp&callback=?",
      stumbleupon: "",
      linkedin: "http://www.linkedin.com/countserv/count/share?format=jsonp&url={url}&callback=?",
      pinterest: "http://api.pinterest.com/v1/urls/count.json?url={url}&callback=?"
  },
    /* Load share buttons asynchronously
    ================================================== */
  loadButton = {
      googlePlus: function (self) {
          var sett = self.options.buttons.googlePlus;
          //$(self.element).find('.buttons').append('<div class="button googleplus"><g:plusone size="'+self.options.buttons.googlePlus.size+'" href="'+self.options.url+'"></g:plusone></div>');
          $(self.element).find('.buttons').append('<div class="button googleplus"><div class="g-plusone" data-size="' + sett.size + '" data-href="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-annotation="' + sett.annotation + '"></div></div>');
          window.___gcfg = {
              lang: self.options.buttons.googlePlus.lang
          };
          var loading = 0;
          if (typeof gapi === 'undefined' && loading == 0) {
              loading = 1;
              (function () {
                  var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
                  po.src = '//apis.google.com/js/plusone.js';
                  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
              })();
          }
          else {
              gapi.plusone.go();
          }
      },
      facebook: function (self) {
          var sett = self.options.buttons.facebook;
          $(self.element).find('.buttons').append('<div class="button facebook"><div id="fb-root"></div><div class="fb-like" data-href="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-send="' + sett.send + '" data-layout="' + sett.layout + '" data-width="' + sett.width + '" data-show-faces="' + sett.faces + '" data-action="' + sett.action + '" data-colorscheme="' + sett.colorscheme + '" data-font="' + sett.font + '" data-via="' + sett.via + '"></div></div>');
          var loading = 0;
          if (typeof FB === 'undefined' && loading == 0) {
              loading = 1;
              (function (d, s, id) {
                  var js, fjs = d.getElementsByTagName(s)[0];
                  if (d.getElementById(id)) { return; }
                  js = d.createElement(s); js.id = id;
                  js.src = '//connect.facebook.net/' + sett.lang + '/all.js#xfbml=1';
                  fjs.parentNode.insertBefore(js, fjs);
              } (document, 'script', 'facebook-jssdk'));
          }
          else {
              FB.XFBML.parse();
          }
      },
      twitter: function (self) {
          var sett = self.options.buttons.twitter;
          $(self.element).find('.buttons').append('<div class="button twitter"><a href="https://twitter.com/share" class="twitter-share-button" data-url="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-count="' + sett.count + '" data-text="' + self.options.text + '" data-via="' + sett.via + '" data-hashtags="' + sett.hashtags + '" data-related="' + sett.related + '" data-lang="' + sett.lang + '">Tweet</a></div>');
          var loading = 0;
          if (typeof twttr === 'undefined' && loading == 0) {
              loading = 1;
              (function () {
                  var twitterScriptTag = document.createElement('script');
                  twitterScriptTag.type = 'text/javascript';
                  twitterScriptTag.async = true;
                  twitterScriptTag.src = '//platform.twitter.com/widgets.js';
                  var s = document.getElementsByTagName('script')[0];
                  s.parentNode.insertBefore(twitterScriptTag, s);
              })();
          }
          else {
              $.ajax({ url: '//platform.twitter.com/widgets.js', dataType: 'script', cache: true }); //http://stackoverflow.com/q/6536108
          }
      },
      digg: function (self) {
          var sett = self.options.buttons.digg;
          $(self.element).find('.buttons').append('<div class="button digg"><a class="DiggThisButton ' + sett.type + '" rel="nofollow external" href="http://digg.com/submit?url=' + encodeURIComponent((sett.url !== '' ? sett.url : self.options.url)) + '"></a></div>');
          var loading = 0;
          if (typeof __DBW === 'undefined' && loading == 0) {
              loading = 1;
              (function () {
                  var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
                  s.type = 'text/javascript';
                  s.async = true;
                  s.src = '//widgets.digg.com/buttons.js';
                  s1.parentNode.insertBefore(s, s1);
              })();
          }
      },
      delicious: function (self) {
          if (self.options.buttons.delicious.size == 'tall') {//tall
              var css = 'width:50px;',
        cssCount = 'height:35px;width:50px;font-size:15px;line-height:35px;',
        cssShare = 'height:18px;line-height:18px;margin-top:3px;';
          }
          else {//medium
              var css = 'width:93px;',
        cssCount = 'float:right;padding:0 3px;height:20px;width:26px;line-height:20px;',
        cssShare = 'float:left;height:20px;line-height:20px;';
          }
          var count = self.shorterTotal(self.options.count.delicious);
          if (typeof count === "undefined") {
              count = 0;
          }
          $(self.element).find('.buttons').append(
      '<div class="button delicious"><div style="' + css + 'font:12px Arial,Helvetica,sans-serif;cursor:pointer;color:#666666;display:inline-block;float:none;height:20px;line-height:normal;margin:0;padding:0;text-indent:0;vertical-align:baseline;">' +
      '<div style="' + cssCount + 'background-color:#fff;margin-bottom:5px;overflow:hidden;text-align:center;border:1px solid #ccc;border-radius:3px;">' + count + '</div>' +
      '<div style="' + cssShare + 'display:block;padding:0;text-align:center;text-decoration:none;width:50px;background-color:#7EACEE;border:1px solid #40679C;border-radius:3px;color:#fff;">' +
      '<img src="http://www.delicious.com/static/img/delicious.small.gif" height="10" width="10" alt="Delicious" /> Add</div></div></div>');

          $(self.element).find('.delicious').on('click', function () {
              self.openPopup('delicious');
          });
      },
      stumbleupon: function (self) {
          var sett = self.options.buttons.stumbleupon;
          $(self.element).find('.buttons').append('<div class="button stumbleupon"><su:badge layout="' + sett.layout + '" location="' + (sett.url !== '' ? sett.url : self.options.url) + '"></su:badge></div>');
          var loading = 0;
          if (typeof STMBLPN === 'undefined' && loading == 0) {
              loading = 1;
              (function () {
                  var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true;
                  li.src = '//platform.stumbleupon.com/1/widgets.js';
                  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s);
              })();
              s = window.setTimeout(function () {
                  if (typeof STMBLPN !== 'undefined') {
                      STMBLPN.processWidgets();
                      clearInterval(s);
                  }
              }, 500);
          }
          else {
              STMBLPN.processWidgets();
          }
      },
      linkedin: function (self) {
          var sett = self.options.buttons.linkedin;
          $(self.element).find('.buttons').append('<div class="button linkedin"><script type="in/share" data-url="' + (sett.url !== '' ? sett.url : self.options.url) + '" data-counter="' + sett.counter + '"></script></div>');
          var loading = 0;
          if (typeof window.IN === 'undefined' && loading == 0) {
              loading = 1;
              (function () {
                  var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true;
                  li.src = '//platform.linkedin.com/in.js';
                  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s);
              })();
          }
          else {
              window.IN.init();
          }
      },
      pinterest: function (self) {
          var sett = self.options.buttons.pinterest;
          $(self.element).find('.buttons').append('<div class="button pinterest"><a href="http://pinterest.com/pin/create/button/?url=' + (sett.url !== '' ? sett.url : self.options.url) + '&media=' + sett.media + '&description=' + sett.description + '" class="pin-it-button" count-layout="' + sett.layout + '">Pin It</a></div>');

          (function () {
              var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true;
              li.src = '//assets.pinterest.com/js/pinit.js';
              var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s);
          })();
      }
  },
    /* Tracking for Google Analytics
    ================================================== */
  tracking = {
      googlePlus: function () { },
      facebook: function () {
          //console.log('facebook');
          fb = window.setInterval(function () {
              if (typeof FB !== 'undefined') {
                  FB.Event.subscribe('edge.create', function (targetUrl) {
                      _gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);
                  });
                  FB.Event.subscribe('edge.remove', function (targetUrl) {
                      _gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);
                  });
                  FB.Event.subscribe('message.send', function (targetUrl) {
                      _gaq.push(['_trackSocial', 'facebook', 'send', targetUrl]);
                  });
                  //console.log('ok');
                  clearInterval(fb);
              }
          }, 1000);
      },
      twitter: function () {
          //console.log('twitter');
          tw = window.setInterval(function () {
              if (typeof twttr !== 'undefined') {
                  twttr.events.bind('tweet', function (event) {
                      if (event) {
                          _gaq.push(['_trackSocial', 'twitter', 'tweet']);
                      }
                  });
                  //console.log('ok');
                  clearInterval(tw);
              }
          }, 1000);
      },
      digg: function () {
          //if somenone find a solution, mail me !
          /*$(this.element).find('.digg').on('click', function(){
          _gaq.push(['_trackSocial', 'digg', 'add']);
          });*/
      },
      delicious: function () { },
      stumbleupon: function () { },
      linkedin: function () {
          function LinkedInShare() {
              _gaq.push(['_trackSocial', 'linkedin', 'share']);
          }
      },
      pinterest: function () {
          //if somenone find a solution, mail me !
      }
  },
    /* Popup for each social network
    ================================================== */
  popup = {
      googlePlus: function (opt) {
          window.open("https://plus.google.com/share?hl=" + opt.buttons.googlePlus.lang + "&url=" + encodeURIComponent((opt.buttons.googlePlus.url !== '' ? opt.buttons.googlePlus.url : opt.url)), "", "toolbar=0, status=0, width=900, height=500");
      },
      facebook: function (opt) {
          window.open("http://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent((opt.buttons.facebook.url !== '' ? opt.buttons.facebook.url : opt.url)) + "&t=" + opt.text + "", "", "toolbar=0, status=0, width=900, height=500");
      },
      twitter: function (opt) {
          window.open("https://twitter.com/intent/tweet?text=" + encodeURIComponent(opt.text) + "&url=" + encodeURIComponent((opt.buttons.twitter.url !== '' ? opt.buttons.twitter.url : opt.url)) + (opt.buttons.twitter.via !== '' ? '&via=' + opt.buttons.twitter.via : ''), "", "toolbar=0, status=0, width=650, height=360");
      },
      digg: function (opt) {
          window.open("http://digg.com/tools/diggthis/submit?url=" + encodeURIComponent((opt.buttons.digg.url !== '' ? opt.buttons.digg.url : opt.url)) + "&title=" + opt.text + "&related=true&style=true", "", "toolbar=0, status=0, width=650, height=360");
      },
      delicious: function (opt) {
          window.open('http://www.delicious.com/save?v=5&noui&jump=close&url=' + encodeURIComponent((opt.buttons.delicious.url !== '' ? opt.buttons.delicious.url : opt.url)) + '&title=' + opt.text, 'delicious', 'toolbar=no,width=550,height=550');
      },
      stumbleupon: function (opt) {
          window.open('http://www.stumbleupon.com/badge/?url=' + encodeURIComponent((opt.buttons.stumbleupon.url !== '' ? opt.buttons.stumbleupon.url : opt.url)), 'stumbleupon', 'toolbar=no,width=550,height=550');
      },
      linkedin: function (opt) {
          window.open('https://www.linkedin.com/cws/share?url=' + encodeURIComponent((opt.buttons.linkedin.url !== '' ? opt.buttons.linkedin.url : opt.url)) + '&token=&isFramed=true', 'linkedin', 'toolbar=no,width=550,height=550');
      },
      pinterest: function (opt) {
          window.open('http://pinterest.com/pin/create/button/?url=' + encodeURIComponent((opt.buttons.pinterest.url !== '' ? opt.buttons.pinterest.url : opt.url)) + '&media=' + encodeURIComponent(opt.buttons.pinterest.media) + '&description=' + opt.buttons.pinterest.description, 'pinterest', 'toolbar=no,width=700,height=300');
      }
  };

    /* Plugin constructor
    ================================================== */
    function Plugin(element, options) {
        this.element = element;

        this.options = $.extend(true, {}, defaults, options);
        this.options.share = options.share; //simple solution to allow order of buttons

        this._defaults = defaults;
        this._name = pluginName;

        this.init();
    };

    /* Initialization method
    ================================================== */
    Plugin.prototype.init = function () {
        var self = this;
        if (this.options.urlCurl !== '') {
            urlJson.googlePlus = this.options.urlCurl + '?url={url}&type=googlePlus'; // PHP script for GooglePlus...
            urlJson.stumbleupon = this.options.urlCurl + '?url={url}&type=stumbleupon'; // PHP script for Stumbleupon...
        }
        $(this.element).addClass(this.options.className); //add class

        //HTML5 Custom data
        if (typeof $(this.element).data('title') !== 'undefined') {
            this.options.title = $(this.element).attr('data-title');
        }
        if (typeof $(this.element).data('url') !== 'undefined') {
            this.options.url = $(this.element).data('url');
        }
        if (typeof $(this.element).data('text') !== 'undefined') {
            this.options.text = $(this.element).data('text');
        }

        //how many social website have been selected
        $.each(this.options.share, function (name, val) {
            if (val === true) {
                self.options.shareTotal++;
            }
        });

        if (self.options.enableCounter === true) {  //if for some reason you don't need counter
            //get count of social share that have been selected
            $.each(this.options.share, function (name, val) {
                if (val === true) {
                    //self.getSocialJson(name);
                    try {
                        self.getSocialJson(name);
                    } catch (e) {
                    }
                }
            });
        }
        else if (self.options.template !== '') {  //for personalized button (with template)
            this.options.render(this, this.options);
        }
        else { // if you want to use official button like example 3 or 5
            this.loadButtons();
        }

        //add hover event
        $(this.element).hover(function () {
            //load social button if enable and 1 time
            if ($(this).find('.buttons').length === 0 && self.options.enableHover === true) {
                self.loadButtons();
            }
            self.options.hover(self, self.options);
        }, function () {
            self.options.hide(self, self.options);
        });

        //click event
        $(this.element).click(function () {
            self.options.click(self, self.options);
            return false;
        });
    };

    /* loadButtons methode
    ================================================== */
    Plugin.prototype.loadButtons = function () {
        var self = this;
        $(this.element).append('<div class="buttons"></div>');
        $.each(self.options.share, function (name, val) {
            if (val == true) {
                loadButton[name](self);
                if (self.options.enableTracking === true) { //add tracking
                    tracking[name]();
                }
            }
        });
    };

    /* getSocialJson methode
    ================================================== */
    Plugin.prototype.getSocialJson = function (name) {
        var self = this,
    count = 0,
    url = urlJson[name].replace('{url}', encodeURIComponent(this.options.url));
        if (this.options.buttons[name].urlCount === true && this.options.buttons[name].url !== '') {
            url = urlJson[name].replace('{url}', this.options.buttons[name].url);
        }
        //console.log('name : ' + name + ' - url : '+url); //debug
        if (url != '' && self.options.urlCurl !== '') {  //urlCurl = '' if you don't want to used PHP script but used social button
            $.getJSON(url, function (json) {
                if (typeof json.count !== "undefined") {  //GooglePlus, Stumbleupon, Twitter, Pinterest and Digg
                    var temp = json.count + '';
                    temp = temp.replace('\u00c2\u00a0', '');  //remove google plus special chars
                    count += parseInt(temp, 10);
                }
                //get the FB total count (shares, likes and more)
                else if (json.data && json.data.length > 0 && typeof json.data[0].total_count !== "undefined") { //Facebook total count
                    count += parseInt(json.data[0].total_count, 10);
                }
                else if (typeof json[0] !== "undefined") {  //Delicious
                    count += parseInt(json[0].total_posts, 10);
                }
                else if (typeof json[0] !== "undefined") {  //Stumbleupon
                }
                self.options.count[name] = count;
                self.options.total += count;
                self.renderer();
                self.rendererPerso();
                //console.log(json); //debug
            })
      .error(function () {
          self.options.count[name] = 0;
          self.rendererPerso();
      });
        }
        else {
            self.renderer();
            self.options.count[name] = 0;
            self.rendererPerso();
        }
    };

    /* launch render methode
    ================================================== */
    Plugin.prototype.rendererPerso = function () {
        //check if this is the last social website to launch render
        var shareCount = 0;
        for (e in this.options.count) { shareCount++; }
        if (shareCount === this.options.shareTotal) {
            this.options.render(this, this.options);
        }
    };

    /* render methode
    ================================================== */
    Plugin.prototype.renderer = function () {
        var total = this.options.total,
    template = this.options.template;
        if (this.options.shorterTotal === true) {  //format number like 1.2k or 5M
            total = this.shorterTotal(total);
        }

        if (template !== '') {  //if there is a template
            template = template.replace('{total}', total);
            $(this.element).html(template);
        }
        else { //template by defaults
            $(this.element).html(
                            '<div class="box"><a class="count" href="#">' + total + '</a>' +
                            (this.options.title !== '' ? '<a class="share" href="#">' + this.options.title + '</a>' : '') +
                            '</div>'
                          );
        }
    };

    /* format total numbers like 1.2k or 5M
    ================================================== */
    Plugin.prototype.shorterTotal = function (num) {
        if (num >= 1e6) {
            num = (num / 1e6).toFixed(2) + "M"
        } else if (num >= 1e3) {
            num = (num / 1e3).toFixed(1) + "k"
        }
        return num;
    };

    /* Methode for open popup
    ================================================== */
    Plugin.prototype.openPopup = function (site) {
        popup[site](this.options);  //open
        if (this.options.enableTracking === true) { //tracking!
            var tracking = {
                googlePlus: { site: 'Google', action: '+1' },
                facebook: { site: 'facebook', action: 'like' },
                twitter: { site: 'twitter', action: 'tweet' },
                digg: { site: 'digg', action: 'add' },
                delicious: { site: 'delicious', action: 'add' },
                stumbleupon: { site: 'stumbleupon', action: 'add' },
                linkedin: { site: 'linkedin', action: 'share' },
                pinterest: { site: 'pinterest', action: 'pin' }
            };
            _gaq.push(['_trackSocial', tracking[site].site, tracking[site].action]);
        }
    };

    /* Methode for add +1 to a counter
    ================================================== */
    Plugin.prototype.simulateClick = function () {
        var html = $(this.element).html();
        $(this.element).html(html.replace(this.options.total, this.options.total + 1));
    };

    /* Methode for add +1 to a counter
    ================================================== */
    Plugin.prototype.update = function (url, text) {
        if (url !== '') {
            this.options.url = url;
        }
        if (text !== '') {
            this.options.text = text;
        }
    };

    /* A really lightweight plugin wrapper around the constructor, preventing against multiple instantiations
    ================================================== */
    $.fn[pluginName] = function (options) {
        var args = arguments;
        if (options === undefined || typeof options === 'object') {
            return this.each(function () {
                if (!$.data(this, 'plugin_' + pluginName)) {
                    $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
                }
            });
        } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
            return this.each(function () {
                var instance = $.data(this, 'plugin_' + pluginName);
                if (instance instanceof Plugin && typeof instance[options] === 'function') {
                    instance[options].apply(instance, Array.prototype.slice.call(args, 1));
                }
            });
        }
    };
})(jQuery, window, document);;
