// If JavaScript is enabled remove 'no-js' class and give 'js' class
jQuery('html').removeClass('no-js').addClass('js');

// Add .osx class to html if on Os/x
if ( navigator.appVersion.indexOf("Mac")!=-1 ) 
	jQuery('html').addClass('osx');

/* Opera fix: 
if ($.browser.opera) {
	$('.fade').removeClass('fade');
	$('.slide').removeClass('slide');
}
*/

// When DOM is fully loaded
jQuery(document).ready(function($) {

	(function() {

	/* --------------------------------------------------------	
		Twitter bootstrap - carousel, tooltip, popover 
	   --------------------------------------------------------	*/	

		// initialize carousel
		$('[rel=carousel]').carousel()
		// initialize tooltip
		$('[rel=tooltip]').tooltip();
		// initialize popover
		$('[rel=popover]').popover();


	    $('.accordion').on('show', function (e) {
	         $(e.target).prev('.accordion-heading').find('.accordion-toggle').addClass('active');
	    });

	    $('.accordion').on('hide', function (e) {
	        $(this).find('.accordion-toggle').not($(e.target)).removeClass('active');
	    });


	/* --------------------------------------------------------	
		External links
	   --------------------------------------------------------	*/	

	    $(window).load(function() {

			$('a[rel=external]').attr('target','_blank');
			
		});

	})();


/* --------------------------------------------------------	
	Flickr feed
   --------------------------------------------------------	*/	

	(function() {

		$('.flickr-feed').each(function(){

			var flickr_id 	   = $(this).data('flickr-id'),
				flickr_limit   = $(this).data('flickr-limit')	? $(this).data('flickr-limit') 		: 12,
				flickr_tags    = $(this).data('flickr-tags')   	? $(this).data('flickr-tags') 		: '',
				flickr_tagmode = $(this).data('flickr-tagmode')	? $(this).data('flickr-tagmode')	: 'any';

			$(this).jflickrfeed({

				limit: flickr_limit,
				qstrings: {
					id: flickr_id,
					tags: flickr_tags,
					tagmode: flickr_tagmode
				},
				itemTemplate: '<a href="{{link}}" rel="external"><img src="{{image_s}}" alt="{{title}}" /></a>'

			});
		})

	})();

/* --------------------------------------------------------	
	Zoom and link overlays (e.g. for thumbnails)
   --------------------------------------------------------	*/	

	(function() {

		$(window).load(function() {

			$('.link').each(function(){
				var $this = $(this);
				var $height = $this.find('img').height();
				var span = $('<span>').addClass('link-overlay').html('&nbsp;').css('top',$height/2).click(function(){
					if (href = $this.find('a:first').attr('href')) {
						top.location.href=href;
					}
				});
				$this.append(span);
			})
			$('.zoom').each(function(){
				var $this = $(this);
				var $height = $this.find('img').height();
				var span = $('<span>').addClass('zoom-overlay').html('&nbsp;').css('top',$height/2);
				$this.append(span);
			})

		});

	})();

/* --------------------------------------------------------	
	Responsible navigation
   --------------------------------------------------------	*/	
	
	(function() {

		var $mainNav    = $('.navbar .nav'),
			responsibleNav = '<option value="" selected>Navigate...</option>';

		// Responsive nav
		$mainNav.find('li').each(function() {
			var $this   = $(this),
				$link = $this.children('a'),
				depth   = $this.parents('ul').length - 1,
				indent  = '';

			if( depth ) {
				while( depth > 0 ) {
					indent += ' - ';
					depth--;
				}
			}

			if ($link.text())
				responsibleNav += '<option ' + ($this.hasClass('active') ? 'selected="selected"':'') + ' value="' + $link.attr('href') + '">' + indent + ' ' + $link.text() + '</option>';

		}).end().after('<select class="nav-responsive">' + responsibleNav + '</select>');

		$('.nav-responsive').on('change', function() {
			window.location = $(this).val();
		});
			
	})();


/* --------------------------------------------------------	
	Portfolio 
   --------------------------------------------------------	*/	

   (function() {

		$(window).load(function(){

			// container
			var $container = $('#portfolio-items');

			function filter_projects(tag)
			{
			  // filter projects
			  $container.isotope({ filter: tag });
			  // clear active class
			  $('#portfolio-filter li.active').removeClass('active');
			  // add active class to filter selector
			  $('#portfolio-filter').find("[data-filter='" + tag + "']").parent().addClass('active');
			  // update location hash
			  if (tag!='*')
				window.location.hash=tag.replace('.','');
			  if (tag=='*')
			  	window.location.hash='';
			}

			if ($container.length) {

				// conver data-tags to classes
				$('.project').each(function(){
					$this = $(this);
					var tags = $this.data('tags');
					if (tags) {
						var classes = tags.split(',');
						for (var i = classes.length - 1; i >= 0; i--) {
							$this.addClass(classes[i]);
						};
					}
				})

				// initialize isotope
				$container.isotope({
				  // options...
				  itemSelector : '.project',
				  layoutMode   : 'fitRows'
				});

				// filter items
				$('#portfolio-filter li a').click(function(){
					var selector = $(this).attr('data-filter');
					filter_projects(selector);
					return false;
				});

				// filter tags if location.has is available. e.g. http://example.com/work.html#design will filter projects within this category
				if (window.location.hash!='')
				{
					filter_projects( '.' + window.location.hash.replace('#','') );
				}

			}
		})

	})();


/* --------------------------------------------------------	
	Back to top button
   --------------------------------------------------------	*/	

	(function() {

   			$('<i id="back-to-top"></i>').appendTo($('body'));

			$(window).scroll(function() {

				if($(this).scrollTop() != 0) {
					$('#back-to-top').fadeIn();	
				} else {
					$('#back-to-top').fadeOut();
				}

			});
			
			$('#back-to-top').click(function() {
				$('body,html').animate({scrollTop:0},600);
			});	

	})();

/* --------------------------------------------------------	
	Contact-form
   --------------------------------------------------------	*/	

   (function() {

   		$('#contact-form-submit').data('original-text', $('#contact-form-submit').html() );

		$('#contact-form-submit').click(function(e){

			var form = $('#contact-form').serialize();

			$('#contact-form-submit').addClass('disabled').html('Sending ...');

			setTimeout(function(){

				// reset message field
				$('#contact-form-response').hide().attr('class','alert');

				// post form data using ajax
				$.post( 'php/contact-form.php', form, 

					function(response) {

						// reset contact form button with original text
						$('#contact-form-submit').removeClass('disabled').html( $('#contact-form-submit').data('original-text') );

						// email was sent
						if ( response.status == 1 ) {

							message = '<i class="icon-ok"></i> <b>Thank You!</b> <br />Thanks for leaving your message. We will get back to you soon.';
							$('#contact-form-response').addClass('alert-success');

						// there were errors, show them
						} else {

							message = '' + response.errors;
							$('#contact-form-response').addClass('alert-warning');

						}

						// show response message
						$('#contact-form-response').show().html(message);

					}
				,"json");

			},300);

		})

	})();

/* --------------------------------------------------------	
	Newsletter form
   --------------------------------------------------------	*/	

   (function() {

   		$('#newsletter-form').submit(function(e){

			var form = $('#newsletter-form').serialize();

			$('#newsletter-form').hide();
			$('.newsletter .ajax-loader').show();

			setTimeout(function(){
			// post form data using ajax
			$.post( 'php/newsletter-form.php', form, 

				function(response) {

					$('.newsletter .ajax-loader').hide();

					// email was sent
					if ( response.status == 1 ) {
						
						$('#newsletter-form').html("&#10004; Thanks, you have been subscribed!");
						$('#newsletter-form').show();

					// there were errors, show them
					} else {

						$('#newsletter-form').show();
						alert(response.errors);
					}
				}
			,"json");

			},600);

			// prevent from reloading a page. 
			e.preventDefault();
		})

	})();

/* --------------------------------------------------------	
	Swipe support for slider
   --------------------------------------------------------	*/	

   (function() {

   		var is_touch_device = !!('ontouchstart' in window);

		function swipe( e, direction ) {

			var $carousel = $(e.currentTarget);
			
			if( direction === 'left' )
				$carousel.find('.carousel-control.right').trigger('click');
			
			if( direction === 'right' )
				$carousel.find('.carousel-control.left').trigger('click');
		}
		
		if (is_touch_device === true) {

			$('#carousel').swipe({
				allowPageScroll : 'auto',
				swipeLeft       : swipe,
				swipeRight      : swipe
			});

		}

	})();

/* --------------------------------------------------------	
	Keyboard shortcuts
   --------------------------------------------------------	*/	

   (function() {

		$('a[rel=shortcut]').each(function(){

			var $this = $(this);
			var key = $this.data('key');
			var href = $this.attr('href');

			if (key && href) {
				$(document).bind('keydown', key, function(){
					top.location.href = href;
				});
			}
		})

	})();

/* --------------------------------------------------------	
	Init SimpleCart
   --------------------------------------------------------	*/	
   
   (function() {
	   var checkedout = false;

		simpleCart({
			currency: "AUD",
			checkout: {
				type: "PayPal",
				email: "michael@flowercow.com.au",
				success: "https://print.wetransfer.com/?to=michael@uphere.com.au",
				cancel: "http://stormprint.com.au/cart.html"
			},
			cartStyle: 'table',
			cartColumns: [
				{ attr: "name" , label: "Name" } ,
				{ attr: "price" , label: "Price", view: 'currency' } ,
				{ view: function (item, column) {
						return  "<a href=\"javascript:;\" class=\"simpleCart_decrement\">-</a>&nbsp;&nbsp;&nbsp;" +
						 		item.quantity() + 
								"&nbsp;&nbsp;&nbsp;<a href=\"javascript:;\" class=\"simpleCart_increment\">+</a>";
					},
					label: "Quantity"
				},
				{ attr: "total" , label: "SubTotal", view: 'currency' } ,
				{ view: "remove" , text: "Remove" , label: "Remove" },
			]
		});
		
		simpleCart.bind('beforeCheckout' , function(data){
			var isQuantity = true;
			simpleCart.each(function(item, x) {
				if (item.quantity() < 50) {
					isQuantity = false;
				}
			});
			if (!isQuantity) {
				alert("You can't order less than 50 pieces.");
				return false;
			}
			else {		
/*				data.email = "rcmahu1-business@yahoo.com";*/
				if (!checkedout) {
					simpleCart.extendCheckout({
							PayPal: function (opts) {
								var ref = new Date().getTime();
								// account email is required
								if (!opts.email) {
									return simpleCart.error("No email provided for PayPal checkout");
								}
			
								// build basic form options
								var data = {
										  cmd			: "_cart"
										, upload		: "1"
										, currency_code : simpleCart.currency().code
										, business		: "michael@flowercow.com.au"
										, rm			: opts.method === "GET" ? "0" : "2"
										, tax_cart		: (simpleCart.tax()*1).toFixed(2)
										, handling_cart : (simpleCart.shipping()*1).toFixed(2)
										, charset		: "utf-8"
										, invoice : ref
									},
									action = opts.sandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr",
									method = opts.method === "GET" ? "GET" : "POST";
			
			
								// check for return and success URLs in the options
								data['return'] = "https://print.wetransfer.com/?to=michael@uphere.com.au&msg=Reference Number: " + ref;
								if (opts.cancel) {
									data.cancel_return = opts.cancel;
								}
								if (opts.notify) {
									data.notify_url = opts.notify;
								}
			
			
								// add all the items to the form data
								simpleCart.each(function (item,x) {
									var counter = x+1,
										item_options = item.options(),
										optionCount = 0,
										send;
				
									// basic item data
									data["item_name_" + counter] = item.get("name");
									data["quantity_" + counter] = item.quantity();
									data["amount_" + counter] = (item.price()*1).toFixed(2);
									data["item_number_" + counter] = item.get("item_number") || counter;
			
			
									// add the options
									simpleCart.each(item_options, function (val,k,attr) {
										// paypal limits us to 10 options
										if (k < 10) {
					
											// check to see if we need to exclude this from checkout
											send = true;
											simpleCart.each(settings.excludeFromCheckout, function (field_name) {
												if (field_name === attr) { send = false; }
											});
											if (send) {
													optionCount += 1;
													data["on" + k + "_" + counter] = attr;
													data["os" + k + "_" + counter] = val;
											}
				
										}
									});
			
									// options count
									data["option_index_"+ x] = Math.min(10, optionCount);
								});
			
			
								// return the data for the checkout form
								return {
									  action	: action
									, method	: method
									, data		: data
								};
			
							}
					});
					checkedout = true;
					simpleCart.checkout();
					return false;
				}
				
				
			}
		});
		
		simpleCart.bind('beforeAdd', function(newItem) {
			var isNew = true;
			simpleCart.each(function(item, x) {
				if (item.get('name') == newItem.get('name')) {
					item.quantity(item.quantity() + newItem.quantity());
					isNew = false;
					simpleCart.update();
				}
			});
			return isNew;
		});
		
		simpleCart.bind('update', function() {
			simpleCart.each(function(item, x) {
				if (item.get('name').substring(0,2) == 'A3') {
					if (item.quantity() < 100) {
						item.price(1.35);
					}
					else {
						item.price(1.1);
					}
				}
				else if (item.get('name').substring(0,2) == 'A2') {
					if (item.quantity() < 100) {
						item.price(2.2);
					}
					else {
						item.price(1.65);
					}
				}
				else if (item.get('name').substring(0,2) == 'A1') {
					if (item.quantity() < 100) {
						item.price(9.9);
					}
					else {
						item.price(5.5);
					}
				}
			});
		});
		
		$('.cart').click(function(e) {
            window.location = "cart.html";
        });

	})();
	
/* --------------------------------------------------------	
	Popovers
   --------------------------------------------------------	*/	
   
	(function() {
	   
		function calcTotal(type, quantity, element) {
			var total, price50, price100;

			switch (type) {
				case 'a3':
					price50 = 1.35;
					price100 = 1.1;
					break;
				case 'a2':
					price50 = 2.2;
					price100 = 1.65;
					break;
				case 'a1':
					price50 = 9.9;
					price100 = 5.5;
					break;
			}

			if (quantity < 100) {
				total = price50 * quantity;
				$('.' + element + '-' + type).find('.item_price').text(price50);
			}
			else {
				total = price100 * quantity;
				$('.' + element + '-' + type).find('.item_price').text(price100);
			}
			
			$('.' + element + '-' + type).find('.total').text('$' + total.toFixed(2));
		}
		
		$('.pricing-50-price', '.pricing-a3').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A3 Size</div><div class="item_price hide">1.35</div><div class="price"><span class="total">$67.50</span>/<span contentEditable="true" class="item_Quantity">50</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.pricing-a3 .pricing-50-price'
		});
		
		$('a', '.pricing-a3 .pricing-50-price').click(function(e) {
            simpleCart.add({ 
				name: "A3 Size",
				price: 1.35,
				quantity: 50
			});
        });
		
		$('.pricing-100-price', '.pricing-a3').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A3 Size</div><div class="item_price hide">1.1</div><div class="price"><span class="total">$110.00</span>/<span contentEditable="true" class="item_Quantity">100</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.pricing-a3 .pricing-100-price'
		});
		
		$('a', '.pricing-a3 .pricing-100-price').click(function(e) {
            simpleCart.add({ 
				name: "A3 Size",
				price: 1.1,
				quantity: 100
			});
        });
		
		$('.pricing-50-price', '.pricing-a2').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A2 Size</div><div class="item_price hide">2.2</div><div class="price"><span class="total">$110.00</span>/<span contentEditable="true" class="item_Quantity">50</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.pricing-a2 .pricing-50-price'
		});
		
		$('a', '.pricing-a2 .pricing-50-price').click(function(e) {
            simpleCart.add({ 
				name: "A2 Size",
				price: 2.2,
				quantity: 50
			});
        });
		
		$('.pricing-100-price', '.pricing-a2').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A2 Size</div><div class="item_price hide">1.65</div><div class="price"><span class="total">$165.00</span>/<span contentEditable="true" class="item_Quantity">100</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.pricing-a2 .pricing-100-price'
		});
		
		$('a', '.pricing-a2 .pricing-100-price').click(function(e) {
            simpleCart.add({ 
				name: "A2 Size",
				price: 1.65,
				quantity: 100
			});
        });
		
		$('.pricing-50-price', '.pricing-a1').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A1 Size</div><div class="item_price hide">9.9</div><div class="price"><span class="total">$495.00</span>/<span contentEditable="true" class="item_Quantity">50</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.pricing-a1 .pricing-50-price'
		});
		
		$('a', '.pricing-a1 .pricing-50-price').click(function(e) {
            simpleCart.add({ 
				name: "A1 Size",
				price: 9.9,
				quantity: 50
			});
        });
		
		$('.pricing-100-price', '.pricing-a1').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A1 Size</div><div class="item_price hide">5.5</div><div class="price"><span class="total">$550.00</span>/<span contentEditable="true" class="item_Quantity">100</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.pricing-a1 .pricing-100-price'
		});
		
		$('a', '.pricing-a1 .pricing-100-price').click(function(e) {
            simpleCart.add({ 
				name: "A1 Size",
				price: 5.5,
				quantity: 100
			});
        });
		
		$('.page-pricing').on('click', '.price-inc', function(e) {
			var q = parseInt($(this).siblings('.item_Quantity').text()) + 1;
            $(this).siblings('.item_Quantity').text(q).trigger('keyup');
        });
		
		$('.page-pricing').on('click', '.price-dec', function(e) {
			var q = parseInt($(this).siblings('.item_Quantity').text()) - 1;
            $(this).siblings('.item_Quantity').text(q).trigger('keyup');
        });
		
		$('.page-pricing').on('keyup', '.item_Quantity', function(e) {
			var quantity = parseInt($(this).text());
			var type = $(this).parent().siblings('.item_name').text().substring(0,2).toLowerCase();
			calcTotal(type, quantity, 'pricing');
		});

		$('.order-a3').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A3 Size</div><div class="item_price hide">1.35</div><div class="price"><span class="total">$67.50</span>/<span contentEditable="true" class="item_Quantity">50</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.order-a3'
		});
		
		$('.order-a2').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A2 Size</div><div class="item_price hide">2.2</div><div class="price"><span class="total">$110.00</span>/<span contentEditable="true" class="item_Quantity">50</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.order-a2'
		});
		
		$('.order-a1').popover({
			html: true,
			trigger: 'hover',
			content:'<div class="simpleCart_shelfItem"><div class="item_name hide">A1 Size</div><div class="item_price hide">9.9</div><div class="price"><span class="total">$495.00</span>/<span contentEditable="true" class="item_Quantity">50</span>pcs<a class="price-inc" href="javascript:;"><img src="img/icon-arrow-up.png" /></a><a class="price-dec" href="javascript:;"><img src="img/icon-arrow-down.png" /></a></div><a href="javascript:;" class="item_add">Add to cart</a></div>',
			placement:'top',
			container:'.order-a1'
		});
		
		$('.footer-order-now').on('click', '.price-inc', function(e) {
			var q = parseInt($(this).siblings('.item_Quantity').text()) + 1;
            $(this).siblings('.item_Quantity').text(q).trigger('keyup');
        });
		
		$('.footer-order-now').on('click', '.price-dec', function(e) {
			var q = parseInt($(this).siblings('.item_Quantity').text()) - 1;
            $(this).siblings('.item_Quantity').text(q).trigger('keyup');
        });
		
		$('.footer-order-now').on('keyup', '.item_Quantity', function(e) {
			var quantity = parseInt($(this).text());
			var type = $(this).parent().siblings('.item_name').text().substring(0,2).toLowerCase();
			calcTotal(type, quantity, 'order');
		});
		
		$('body').on('click', 'a.item_add', function(e) {
            var clone = $(this).parents('.pricing-a3,.pricing-a2,.pricing-a1,.order-a3,.order-a2,.order-a1').clone();
			var position = $(this).parents('.pricing-a3,.pricing-a2,.pricing-a1,.order-a3,.order-a2,.order-a1').offset();
			
			clone.find('.popover').remove();
			clone.appendTo('body');
			clone.css({
				'position': 'absolute',
				'top': position.top + 'px',
				'left': position.left + 'px',
				'opacity': '.6'
			});
			
			clone.animate({
				'top': $('.cart').offset().top + 'px',
				'left': $('.cart').offset().left + 'px',
				'opacity': '.2'
			}, 600, 'swing', function() {
				clone.fadeOut(200, function() {
					clone.remove();
				});
			});
        });

	})();
	
/* --------------------------------------------------------	
	Landing pages red button
   --------------------------------------------------------	*/	
	
	(function() {
		
		$('.landing-red-text, .landing-red-icon').on('click', function(e) {
			$('.landing-red-text').fadeOut(function() {
				$(this).removeAttr('style').hide();
				$(this).html('<span style="font-size:28px">1300 662 502</span>').fadeIn();
				$(this).css('cursor', 'default');
			});
			$('.landing-red-text, .landing-red-icon').off('click').css('cursor', 'default');
		});
		
	})();

/* --------------------------------------------------------	
	Sample Works Carousel
   --------------------------------------------------------	*/	
   
	(function() {
	   
		$('#carousel_sample','.page-sample-works').carousel({
			interval: false
		});
	   
		$('.left-boxes-wrapper .box', '.page-sample-works').click(function(e) {
			$('.left-boxes-wrapper .box', '.page-sample-works').each(function(index, element) {
                if ($('img', element).attr('src').indexOf('-focus') > -1) {
					var newsrc = $('img', element).attr('src');
					newsrc = newsrc.replace('-focus', '');
					$('img', element).attr('src', newsrc);
				}
            });
			$('img', this).attr('src', $('img', this).attr('src').replace('.jpg', '-focus.jpg'));
		});

	})();

})