$(document).ready(function() {
	var jo = {
		zoomWidth: 250,
		zoomHeight: 250,
        xOffset : 75,
		position : 'left',
		title : false,
        zoomType: 'reverse',
		imageOpacity: 0.4,
		showEffect: 'fadein',
		hideEffect: 'fadeout'
	};
	
	$('.product_image_alts img').click(function() { 
		event.preventDefault();
		$('#image_href')[0].href = $(this)[0].src.replace("/i/", "/l/");
		return false;
	});
	
	$('.monthy_fun_jam .gallery_description').css('display', 'none');
	$('.monthy_fun_jam .gallery_img ').each(function() { 
		var c = $(this).attr('alt').split('|');
		$(this).parent().parent().append('<div class=monthly_caption><div class=month_grey>'+c[0]+'</div><div class=month_bold>'+c[2]+'</div><div>'+c[1]+'</div></div>');
	});

	if ($('#agree_to_fun').length == 1) {
		$('#monthly_add_button').click(function() {
			if (!$('#agree_to_fun').is(':checked')) {
				$('#monthly_error').css('display', 'block');
				return false;
			}
		});
	}

	if ($('#image_href').length) {
		$('#image_href').jqzoom(jo);
		$('#image_href').click(function(event) { event.preventDefault(); return false; })
	}
	
	if ($.fancybox) {	
		$('a[rel="archives"]').fancybox({
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'titlePosition' 	: 'over',
			'centerOnScroll'	: true,	
			'overlayOpacity'	: .8,
			'overlayColor'		: '#000',
			'padding'			: 50,
			'margin'			: 20,
		});
		
		$('a[rel="monthly"]').fancybox({
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'titlePosition' 	: 'over',
			'titleFormat' 		: function(title) { 
				return title.split('|')[1]+'<br>'+title.split('|')[2];
				},
			'centerOnScroll'	: true,	
			'overlayOpacity'	: .8,
			'overlayColor'		: '#000',
			'padding'			: 50,
			'margin'			: 20,
		});
	}
	

	$(".current").each(function(i) {
		$(this).children("img").css({ "border": '1px solid #0f0' });
		// this.src = this.src.replace(".jpg", "_o.jpg");
		var src = $(this).children("a").children("img").attr("src");
		$(this).children("a").children("img").attr("src", src.replace(".jpg", "_o.jpg"));
	 });
	$("#menu li img").hover(
		function () { 
			if ($(this).parent().parent()[0].className != "current") this.src = this.src.replace(".jpg", "_o.jpg");
		},
		function () {
			if ($(this).parent().parent()[0].className != "current") this.src = this.src.replace("_o.jpg", ".jpg");
		}
	);
	$('.music_row').hover(
		function () {
			$(this).find(".music_title a, .music_title div:first-child").css({ "padding-left": '5px' });
			$(this).find(".music_download a, .music_ticket a").css({ "background-color": '#fcfc00', "color": '#000' });
		},
		function () {
			$(this).find(".music_title a, .music_title div:first-child").css({ "padding-left": '0px' });
			$(this).find(".music_download a, .music_ticket a").css({ "background-color": '#000', "color": '#fff' });
		}
	);
	
	
	$.easing.easeIn = function (x, t, b, c, d) { 
	    return c*(t/=d)*t + b;
		}
	$.easing.easeOut = function (x, t, b, c, d) { 
		return -c*(t/=d)*(t-2) + b;
	}

	if ($('#slide_box').length) {
		var slidebox;
		var slidehref = 0;
		var slidelist = new Array();
		var dir = 0;
		var slide_im = $('#slide_box img').length;
		var slide_width = $('#slide_box').width();
		var slide_hold = 3000;
		var slide_speed = 900;
		
		$('#slide_box').width($('#slide_box').width()*slide_im)
		$('#slide_box a[href]').each(function(i) { slidelist[i] = this.href; })
		$('.slide_click').click(function() { window.location = slidelist[slidehref]; });
		
		$('.slide_love').click(function(e) {
			if (e.clientX) {
				clearInterval(slider_timer);
				if (this.id == "slide_right") dir = 0;
				else dir = 1;
				slider_timer = setInterval(function(){
					if (slidehref+1 == slidelist.length) dir = 1;
					else if (slidehref == 0) dir = 0;
                	
					if (dir) $('#slide_left').click();
					else $('#slide_right').click();
				}, slide_hold);
			}
			
			var l = $('#slide_box').position().left
			var slide_im = $('#slide_box img').length;
			slidebox = Math.ceil(Math.abs(l/slide_width));

			if (this.id == "slide_right") {
				if ((slidebox+1) == slide_im) return;
				if (l > -($('#slide_box').width()-slide_width)) {
					$('#slide_box').stop().animate({left: -((slidebox+1)*slide_width)+'px'}, {queue: false, duration: slide_speed, complete: slide_link(0)});
				}
			} else {
				if (l >= 0) return;
				if ((slidebox*slide_width-(l*-1)) > (slide_width/2) && (slidebox*slide_width-(l*-1)) > 0) slidebox <= 1?1:slidebox--
					$('#slide_box').stop().animate({left: -((slidebox-1)*slide_width)+'px'}, { duration: slide_speed, complete: slide_link(1)});
			}
		});

		function slide_link(i) {
			slidehref = i?slidebox-1:slidebox+1;
		}

		var slider_timer = setInterval(function(){
			if (slidehref+1 == slidelist.length) dir = 1;
			else if (slidehref == 0) dir = 0;
			if (dir) $('#slide_left').click();
			else $('#slide_right').click();
		}, slide_hold);
	}
	
	if ($('#lookbook').length) {
		var lookbook;
		var lookhref = 0;
		var looklist = new Array();
		var direction = 0;
		var lb_im = $('#lookbook img').length;

		$('#lookbook').width($('#lookbook').width()*lb_im)
		$('#lookbook a[href]').each(function(i) { looklist[i] = this.href; })
		$('.look_click').click(function() { window.location = looklist[lookhref]; });

		$('.look_love').click(function(e) {
			if (e.clientX) {
				clearInterval(slidertimer);
				if (this.id == "look_right") direction = 0;
				else direction = 1;
				slidertimer = setInterval(function(){
					if (lookhref+1 == looklist.length) direction = 1;
					else if (lookhref == 0) direction = 0;
                	
					if (direction) $('#look_left').click();
					else $('#look_right').click();
				}, 3000);
			}

			var l = $('#lookbook').position().left
			var lb_im = $('#lookbook img').length;
			lookbook = Math.ceil(Math.abs(l/315));

			if (this.id == "look_right") {
				if ((lookbook+1) == lb_im) return;
				if (l > -($('#lookbook').width()-315)) {
					$('#lookbook').stop().animate({left: -((lookbook+1)*315)+'px'}, {queue: false, duration: 800, complete: looklink(0)});
				}
			} else {
				if (l >= 0) return;
				if ((lookbook*315-(l*-1)) > 400 && (lookbook*315-(l*-1)) > 0) lookbook <= 1?1:lookbook--
					$('#lookbook').stop().animate({left: -((lookbook-1)*315)+'px'}, { duration: 800, complete: looklink(1)});
			}
		});

		function looklink(i) {
			lookhref = i?lookbook-1:lookbook+1;
		}

		var slidertimer = setInterval(function(){
			if (lookhref+1 == looklist.length) direction = 1;
			else if (lookhref == 0) direction = 0;
			if (direction) $('#look_left').click();
			else $('#look_right').click();
		}, 3000);
	}
});

function archive_search() {
	$(".gallery_img").each(function(i) {
		if ($(this)[0]['alt'].toLowerCase().indexOf($V('search_archive').toLowerCase()) == -1)
			$(this).parent().parent().parent().fadeOut('fast');
		else $(this).parent().parent().parent().fadeIn('fast');
	});
}

