Cufon.replace('#leftbox h2', { fontFamily: 'Museo 700' });
Cufon.replace('#leftbox h4', { fontFamily: 'Museo 700' });
Cufon.replace('#recent h2', { fontFamily: 'Museo 700' });
Cufon.replace('#footcont h2', { fontFamily: 'Museo 700' });
Cufon.replace('.fitem div h2', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('.fitem div h4', { fontFamily: 'Museo 700' });
Cufon.replace('.product-description h2', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('.item-ship h3', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('h2.item-comment-title', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('h3.add-cart-price', { fontFamily: 'Museo 700', hover: true });	
Cufon.replace('h3.white-title', { fontFamily: 'Museo 700', hover: true });	
Cufon.replace('ul.white-info-list li h3', { fontFamily: 'Museo 700', hover: true });			
Cufon.replace('h3.more-artist-title', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('.similar-box-title h2', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('a.add-cart-action-h', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('.add-cart-action-blank', { fontFamily: 'Museo 700', hover: true });

Cufon.replace('.intro h2', { fontFamily: 'Museo 300' });
Cufon.replace('.getstarted p, .getstarted div', { fontFamily: 'Museo 300' });
Cufon.replace('#recent h3', { fontFamily: 'Museo 300' });
Cufon.replace('#footcont h3', { fontFamily: 'Museo 300' });

Cufon.replace('.getstarted a.login', { fontFamily: 'Museo 300', hover: true });
Cufon.replace('.intro .getstarted a', { fontFamily: 'Museo 300', hover: true });
Cufon.replace('.links a', { fontFamily: 'Museo 300', hover: true });
Cufon.replace('.infos a', { fontFamily: 'Museo 300', hover: true });
Cufon.replace('.fitem div li a', { fontFamily: 'Museo 300', hover: true });
Cufon.replace('#leftbox .searchops a, #leftbox .featul a', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('#nav a', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('.paging li', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('.message', { fontFamily: 'Museo 700', hover: true });
Cufon.replace('.museo700', { fontFamily: 'Museo 700' });
Cufon.replace('.museo300', { fontFamily: 'Museo 300' });		
		
Cufon.replace('.btn-blue', { fontFamily: 'Museo 700', textShadow:'2px 2px #0089ca', hover: true });
Cufon.replace('.btn-green', { fontFamily: 'Museo 700', textShadow:'2px 2px #75b52a', hover: true });
Cufon.replace('.collab-title h1, .list-proj-th div', { fontFamily: 'Museo 700' });
Cufon.replace('.collab-title h2, #collab-rf h3, #collab-rf .resources p ', { fontFamily: 'Museo 300' });
Cufon.replace('#collab-lf div.list-proj-th div.c4', { fontFamily: 'Museo 700', textShadow:'2px 2px #676666'});

/* rebuilds the parameters based on the current results */
function buy_controller_results(page) {	
	$('#results_loading').attr('style','display:block;');
	$('#results').attr('style','display:none;');	
	if (page != '') { $('#page').val(page); }		
	$.post('/buy/results/', $("#buy_results").serialize(), 
		function(data) { 
			// displaying results
			$('#results').html(data);
			$('#results_loading').attr('style','display:none;');
			$('#results').attr('style','display:block;');
			
			creation_list_hover();
		}
	);
}

/* adds a hover event to each creation list item after the results have been built */
function creation_list_hover() {
	// adding hover event for each creation
	$("div.item").hover(
		item_hover = function () {
			$(this).children(".infos").css("bottom","0px");
			var iuri = $.URLEncode($(this).siblings('.owner').children('a').eq('0').attr('href'));
			var itit = $(this).siblings('.owner').children('a').eq('0').text();
			//$(this).find('li.i2').html('<div class="bm-pop"> <a href="#" title="Share This">Share This</a> <div class="bm-pop-links"> <a href="http://www.facebook.com/share.php?u='+iuri+'" title="Facebook" class="i1">Facebook</a> <a href="http://twitter.com/home?status='+itit+' - '+iuri+'" title="Twitter" class="i2">Twitter</a> <a href="http://www.stumbleupon.com/submit?url='+iuri+'&title='+itit+'" title="Stumbleupon" class="i3">Stumbleupon</a> <a href="http://www.tumblr.com/share?v=3&u='+iuri+'&t='+itit+'" title="Tumbler" class="i4">Tumbler</a> <a href="http://digg.com/submit?phase=2&url='+iuri+'&title='+itit+'&bodytext='+itit+'" title="Digg" class="i5">Digg</a> </div> </div>');
			
			var twitter = $(this).children('.infos').children('.twitter').text();
			var facebook = $(this).children('.infos').children('.facebook').text();
			$(this).find('li.i2').html('<div class="bm-pop"> <a href="#" title="Share This">Share This</a> <div class="bm-pop-links"> <a href="http://www.facebook.com/share.php?'+facebook+'" title="Facebook" class="i1" target="_blank">Facebook</a> <a href="http://twitter.com/home?status='+twitter+'" title="Twitter" class="i2" target="_blank">Twitter</a> <a href="http://www.stumbleupon.com/submit?url='+iuri+'&title='+itit+'" title="Stumbleupon" class="i3">Stumbleupon</a> <a href="http://www.tumblr.com/share?v=3&u='+iuri+'&t='+itit+'" title="Tumbler" class="i4">Tumbler</a> <a href="http://digg.com/submit?phase=2&url='+iuri+'&title='+itit+'&bodytext='+itit+'" title="Digg" class="i5">Digg</a> </div> </div>');
			
			
			Cufon.replace('.bm-pop a', { fontFamily: 'Museo 300', hover: true });
			$(this).find('li.i2').mouseover(function() {
				$(this).find('div.bm-pop-links').show();
			}).mouseout(function(){ 
				$(this).find('div.bm-pop-links').hide();
			});
		}, 
		function () {
			$(this).children(".infos").css("bottom","-132px");
			$(this).children('div.pop').find('li.i2').children('div').remove();
			$(this).children('div.pop').find('li.i2').html('<a href="#" title="Share This">Share This</a>');
			Cufon.replace($(this).children('div.pop').find('li.i2').children('a'), { fontFamily: 'Museo 300', hover: true });
		}
	);
}

// changing font to cufon
Cufon.replace('.message', { fontFamily: 'Museo 700', hover: true });
			
		$(function () { 
			$('.anythingSlider').anythingSlider({
				easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
				autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
				delay: 12000,                    // How long between slide transitions in AutoPlay mode
				startStopped: false,            // If autoPlay is on, this can force it to start stopped
				animationTime: 600,             // How long the slide transition takes
				hashTags: true,                 // Should links change the hashtag in the URL?
				buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
				pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
				startText: "Go",             // Start text
				stopText: "Stop",               // Stop text
				navigationFormatter: null       // Details at the top of the file on this use (advanced use)
			});
			
			
			if ($('.tips').length > 0) {
				$('.tips').tipsy({gravity: 'w'});
			}
						
		$(document).ready(function() {	
			creation_list_hover();
			
			// posting search form on load
			if ($("#buy_results").length > 0) { buy_controller_results(''); }		
			
			$("a[rel='creation_detail']").colorbox({ scroll: false });
			$('#cats').selectbox();
			
			$(".search form").prepend('<div class="catse"></div>');
			$(".search form .catse").append($('#cats_input, #cats_container'));
			$('.search form .catse').mouseleave(function(){
				$(this).children('#cats_container').fadeOut();
				$(this).siblings('input[type="text"]').click().focus();
			});
			
			$('.recent-carousel').jcarousel();
			$('.more-work-carousel').jcarousel();
						
			// price slider
			if ($('#slider1').length > 0) {
				if ($('#price_max').val() > 4000) {
					$("#slider-price-o").text('$' + $('#price_min').val() + ' - Any');
				}else{
					$("#slider-price-o").text('$' + $('#price_min').val() + ' - $' + $('#price_max').val());
				}
			
				$("#slider1").slider({ range: true, min: 0, max: 4001, values: [$('#price_min').val(), $('#price_max').val()],
					slide: function(event, ui) {
						if (ui.values[1] > 4000) {
							$("#slider-price-o").text('$' + ui.values[0] + ' - Any');
						}else{
							$("#slider-price-o").text('$' + ui.values[0] + ' - $' + ui.values[1]);
						}
					},
					stop: function(event, ui) {
						$('#price_min').val(ui.values[0]);
						$('#price_max').val(ui.values[1]);
						
						buy_controller_results('1');
					}
				});
			}
			
			// size slider
			if ($('#slider1').length > 0) {
				var sizes = new Array()
				sizes["1"]='Small'; sizes["2"]='Medium'; sizes["3"]='Large'; sizes["4"]='X-Large';
				
				$("#slider-size-o").text(sizes[$('#size_min').val()] + ' to ' + sizes[$('#size_max').val()]);
			
				$("#slider2").slider({ range: true, min: 1, max: 4, values: [$('#size_min').val(), $('#size_max').val()],
					slide: function(event, ui) {
						if (ui.values[0] == ui.values[1]) {
							$("#slider-size-o").text(sizes[ui.values[0]]);
						} else {
							$("#slider-size-o").text(sizes[ui.values[0]] + ' to ' + sizes[ui.values[1]]);
						}
					},
					stop: function(event, ui) {
						$('#size_min').val(ui.values[0]);
						$('#size_max').val(ui.values[1]);
						
						buy_controller_results('1');
					}
				});
			}
		});
			
			$("li.fitem").hover(
				 function () {
					$(this).children("div.pop").addClass("open").css("bottom","0px");
					var fiuri = $.URLEncode($(this).find('h2').children('a').attr('href'));
					var fitit = $(this).find('h2').children('a').text();
					//$(this).find('li.i2').html('<div class="bm-pop"> <a href="#" title="Share This">Share This</a> <div class="bm-pop-links"> <a href="http://www.facebook.com/share.php?u='+fiuri+'" title="Facebook" class="i1">Facebook</a> <a href="http://twitter.com/home?status='+fitit+' - '+fiuri+'" title="Twitter" class="i2">Twitter</a> <a href="http://www.stumbleupon.com/submit?url='+fiuri+'&title='+fitit+'" title="Stumbleupon" class="i3">Stumbleupon</a> <a href="http://www.tumblr.com/share?v=3&u='+fiuri+'&t='+fitit+'" title="Tumbler" class="i4">Tumbler</a> <a href="http://digg.com/submit?phase=2&url='+fiuri+'&title='+fitit+'&bodytext='+fitit+'" title="Digg" class="i5">Digg</a> </div> </div>');
					
					var twitter = $(this).children('.twitter').text();
					var facebook = $(this).children('.facebook').text();
					$(this).find('li.i2').html('<div class="bm-pop"> <a href="#" title="Share This">Share This</a> <div class="bm-pop-links"> <a href="http://www.facebook.com/share.php?'+facebook+'" title="Facebook" class="i1" target="_blank">Facebook</a> <a href="http://twitter.com/home?status='+twitter+'" title="Twitter" class="i2" target="_blank">Twitter</a> <a href="http://www.stumbleupon.com/submit?url='+fiuri+'&title='+fitit+'" title="Stumbleupon" class="i3">Stumbleupon</a> <a href="http://www.tumblr.com/share?v=3&u='+fiuri+'&t='+fitit+'" title="Tumbler" class="i4">Tumbler</a> <a href="http://digg.com/submit?phase=2&url='+fiuri+'&title='+fitit+'&bodytext='+fitit+'" title="Digg" class="i5">Digg</a> </div> </div>');
										
					Cufon.replace('.bm-pop a', { fontFamily: 'Museo 300', hover: true });
					$(this).find('li.i2').mouseover(function() {
						$(this).find('div.bm-pop-links').show();
					}).mouseout(function(){ 
						$(this).find('div.bm-pop-links').hide();
					});
				}, 
				function () {
					$(this).children("div.pop").removeClass("open").css("bottom","-120px");
					$(this).children('div.pop').find('li.i2').children('div').remove();
					$(this).children('div.pop').find('li.i2').html('<a href="#" title="Share This">Share This</a>');
					Cufon.replace($(this).children('div.pop').find('li.i2').children('a'), { fontFamily: 'Museo 300', hover: true });
				}
			);
			
			function test() {
				$("li.fitem .open li.i2").css("background","red");
				$("li.fitem .open li.i2").mouseover(function() {
					$(this).html('<div class="bm-pop"> <a href="#" title="Share This">Share This</a> <div class="bm-pop-links"> <a href="" title="Facebook" class="i1">Facebook</a> <a href="" title="Twitter" class="i2">Twitter</a> <a href="" title="Stumbleupon" class="i3">Stumbleupon</a> <a href="" title="Tumbler" class="i4">Tumbler</a> <a href="" title="Digg" class="i5">Digg</a> </div> </div>');
					Cufon.replace('.bm-pop a', { fontFamily: 'Museo 300', hover: true });
				}).mouseleave(function(){ 
					$(this).html('<a href="#" title="Share This">Share This</a>');
					Cufon.replace($(this).children('a'), { fontFamily: 'Museo 300', hover: true });
				});
			}

			$("li.fitem").each(function() {
				var hrefi = $(this).find('h2').find('a').attr('href');
				$(this).find('img').wrap('<a href="'+hrefi+'" class="imglink"></a>');
			});
			
			$("#header #nav a").hover(function() {
				if ($(this).hasClass('buy')) {
					$(this).siblings('.drop').fadeIn("fast");
				}else{
					$(this).parent().siblings().find('.drop').fadeOut();
				}
			});

			$("#nav").find('.drop').mouseleave(function(){
				$(this).fadeOut();
			});
			
			var br = 0;
			$('#leftbox .browse h2 a').hover(function() {
				$(this).parent().siblings('div').fadeIn("fast");
			});
			
			$('#leftbox .browse').mouseleave(function(){
				$(this).children('div').fadeOut();
			});
				
			$('#cats_container').append('<span></span>');
			
			$('form[id="buy_results"] input[type="checkbox"]').click(function() {
				var c = $('form[id="buy_results"] input[type="checkbox"]:checked').length;
				
				buy_controller_results('1');
				
				if( c > 1 || $('a.clearm').not(':visible') ) {
					$('a.clearm').show();
					Cufon.replace('#leftbox a.clearm', { fontFamily: 'Museo 700', hover: true });
				}else{
					$('a.clearm').hide();
				}
			});
			
			$('a.clearm').click(function() {
				$('form[id="buy_results"] input[type="checkbox"]:checked').removeAttr("checked");
				$(this).hide();
				
				buy_controller_results('1');	
			});
			
			if ($('.product-image-holder').length > 0) {				
				$('.product-image-holder .product-image-left li').eq('0').fadeIn();
				//current_product_image = '';
				
				var im = 0;
				$('.product-image-holder .product-image-right a').each(function() {
					$(this).attr("href", "#thm"+im);
					im++;
				});
				
				$('.product-image-holder .product-image-right a').click(function() {
					$('.product-image-holder .product-image-left li').hide();
					$('.product-image-holder .product-image-left').find($(this).attr('href')).fadeIn();
					//current_product_image = $(this).attr('href');
					return false;
				});
				
				var lm = 0;
				$('.product-image-holder .product-image-left li').each(function() {
					$(this).attr("id", "thm"+lm);
					lm++;
				});
				
				$('#product-zoom').click(function() {
					$("a[rel='creation_detail']").colorbox({open: true, scroll: false});
				});
			}
			
			if ($('.se-sha').length > 0) {
				var suri = $.URLEncode(window.location);
				var stit = $('.title-product h1').text();
				Cufon.replace('.title-product h1', { fontFamily: 'Museo 700'});
				$('.se-sha').wrap('<div class="bm-pop"></div>');
				//$('.share-event .bm-pop').html('<a href="#" title="Share This" class="se-sha"><span>Share This</span></a><div class="bm-pop-links"> <a href="http://www.facebook.com/share.php?u='+suri+'" title="Facebook" class="i1">Facebook</a> <a href="http://twitter.com/home?status='+stit+' - '+suri+'" title="Twitter" class="i2">Twitter</a> <a href="http://www.stumbleupon.com/submit?url='+suri+'&title='+stit+'" title="Stumbleupon" class="i3">Stumbleupon</a> <a href="http://www.tumblr.com/share?v=3&u='+suri+'&t='+stit+'" title="Tumbler" class="i4">Tumbler</a> <a href="http://digg.com/submit?phase=2&url='+suri+'&title='+stit+'&bodytext='+stit+'" title="Digg" class="i5">Digg</a> </div>');
				
				var twitter = $('.twitter').text();
				var facebook = $('.facebook').text();				
				$('.share-event .bm-pop').html('<a href="#" title="Share This" class="se-sha"><span>Share This</span></a><div class="bm-pop-links"> <a href="http://www.facebook.com/share.php?'+facebook+'" title="Facebook" class="i1" target="_blank">Facebook</a> <a href="http://twitter.com/home?status='+twitter+'" title="Twitter" class="i2" target="_blank">Twitter</a> <a href="http://www.stumbleupon.com/submit?url='+suri+'&title='+stit+'" title="Stumbleupon" class="i3">Stumbleupon</a> <a href="http://www.tumblr.com/share?v=3&u='+suri+'&t='+stit+'" title="Tumbler" class="i4">Tumbler</a> <a href="http://digg.com/submit?phase=2&url='+suri+'&title='+stit+'&bodytext='+stit+'" title="Digg" class="i5">Digg</a> </div>');
								
				Cufon.replace('.share-event .bm-pop a', { fontFamily: 'Museo 300', hover: true });
				$('.share-event .bm-pop').mouseover(
					function() {
						$(this).children('.bm-pop-links').show();
					}
				).mouseout(
					function() {
						$(this).children('.bm-pop-links').hide();
					}
				);
			}
			
		});
		
(function($) {
	/**
	* container: form container
	* button: show/hide container button
	* refresh: true/false - refresh page after success submit
	*/
	$.fn.ajaxSubmitForm = function(options)
	{
		new $.ajaxSubmitForm($.extend(options, {container: $(this)}));
		return this;
	};
	$.ajaxSubmitForm = function(options)
	{
		this.init(options);
	};
	$.extend($.ajaxSubmitForm.prototype,
	{
		options: {},
		container: null,

		init: function(options)
		{
			var self = this;
			
			this.options = $.extend({
				form: $($(options.container).find('form').get(0)),
				submit: $(options.container.find(':submit')),
				cancel: $(options.container.find(':reset')),
				button: null,
				refresh: true,
				onSuccess: null
			}, this.options, options);

			if (this.options.button) {
				this.options.button.click(function() {
					self.options.container.toggle();
				});
			};

			this.options.cancel.click(function() {
				self.options.container.hide();
			});

			$.metadata.setType("attr", "validate");

			this.options.form.validate({
				submitHandler: function() {
					// show sending data message
					self.blockContainer({ icon: 'loading.gif', msg: 'Sending data..', click: true });
					//send form
					self.options.form.ajaxSubmit({
						dataType:  'json',
						beforeSerialize: function() {
							$('textarea,input[type=text]').filter('[hint]').each(function() {
								if ($(this).val() == $(this).attr('hint')) {
									$(this).val('')
								}
							});
							return true;
						},
						success: function(response) {
							if (typeof(response.message) == 'object') {
								if (!response.success) {
									var msg = "";
									for (name in response.message) {
										msg += '<ul class="errors">' + name + '<li>' + response.message[name] + '</li></ul>';
									}
									self.blockContainer({ icon: 'exclamation.png', msg: 'Some errors found<br>' + msg, click: true });
								} else {
									if (self.options.onSuccess) {
										self.options.onSuccess.call(self);
									}
									else if (self.options.refresh) {
										document.location.replace(document.location);
									}
									self.unblockContainer();
								}
							} else {
								self.blockContainer({ icon: 'exclamation.png', msg: 'Error sending data to server 1!', click: true });
							}
						},
						error: function(responseText, statusText) {
							self.blockContainer({ icon: 'exclamation.png', msg: 'Error sending data to server!', click: true });
						}
					});
					return false;
				}
			});
		},

		blockContainer: function(opts)
		{
			var self = this;

			this.options.container.block({
				message: '<h2><img src="/i/' + opts.icon + '" align="absmiddle"><b style="padding-left: 5px; font-size: 11px; color:black;">' + opts.msg + '</b></h2>',
				css: { border: '1px solid #FF8080', padding: 10, '-moz-border-radius': '10px', width: '50%' },
				overlayCSS: { backgroundColor: '#E0E0E0' }
			});

			if (opts.click) {
				this.options.container.find('.blockOverlay,.blockMsg')
					.attr('title', 'Click to unblock')
					.click(function() {
						self.unblockContainer();
					})
			}
			
		},

		unblockContainer: function()
		{
			this.options.container.unblock();
		}
	});
	
	var shopCart = function()
	{
		this.updateShopCart();
	};
	$.extend(shopCart.prototype,
	{
		addShopCartEl: function(el)
		{
			var aItems = this.getShopCart(), id = el.attr('id') || '';
			if ($.inArray(id, aItems) != -1) {
				alert("This creation already in your shop cart! Change this to a dialog");
				//dialogCheckoutConfirm('This creation already in your shop cart! Checkout?');
			} else {
				// adding item to cart
				aItems.push(id);
				$.cookie('ShopCart', aItems.join(','), {path: '/'});
				this.updateShopCart();
				
				// redirecting to cart
				window.location = '/buy/cart';
			}
			return false;
		},

		getShopCart: function()
		{
			var val = $.cookie('ShopCart');
			return val ? val.split(",") : [];
		},

		delShopCartEl: function(el)
		{
			var aItems = this.getShopCart(), id = el.attr('id') || '', iOffset = $.inArray(id, aItems);
			aItems.splice(iOffset, 1);
			$.cookie('ShopCart', aItems.join(','), {path: '/'});
			this.updateShopCart();
		},

		updateShopCart: function()
		{
			var aItems = this.getShopCart();
			$('.shopCartNumber').html(aItems.length)
		},		
		
		setShopCart: function(ids)
		{
			$.cookie("ShopCart", ids, {path: "/"});
			this.updateShopCart();
		}
	});
	$.shopCart = new shopCart();
	
	$('a.addShopCartEl').click(function() {
		$.shopCart.addShopCartEl($(this));
		return false;
	});	
})(jQuery);

/**
*	show flag dialog
*/
(function($) {
	$.flagDialog = function(options)
	{
		this.init(options);
	};
	$.fn.flagDialog = function(options)
	{
		new $.flagDialog($.extend(options, {input: $(this)}));
		return this;
	};
	$.extend($.flagDialog.prototype,
	{
		init: function(options)
		{
			if (!options.url) {
				return false;
			}

			var self = this;
			var $dialog = $('#flagDialog');

			$dialog.find('.cancelFlagDialog').click(function() {
				$.iTooltip.hide();
				return false;
			});

			$dialog.find('form').attr('action', options.url);

			$(options.input).tooltip({
				event: 'click',
				sticky: true,
				className: 'complaintt',
				text: $dialog.clone(true)
			})
			.bind('show.tooltip', function(e, el) {
				$.iTooltip.helper.find('textarea').each(function() {
					$(this).val($(this).attr('hint') ? $(this).attr('hint') : "");
				});

				$.iTooltip.helper.find('label.error').hide();

				if (el.ttCFG.text.jquery) {
					$($.iTooltip.helper).find('#flagDialog').ajaxSubmitForm({
						refresh: false,
						onSuccess: function() {
							$.iTooltip.hide();
						}
					});
				}
			});
		}
	});
})(jQuery);
