﻿/* onload settings */
$().ready(function () {
	$('.product-list ul').equalHeights();
	$('.category-list ul').equalHeights();
	$('#main-nav ul li ul li:last-child').addClass('last');
	$('#product-photos ul li a,#product-photos .photo a').fancybox({
		'overlayShow':true,
		'enableEscapeButton':true,
		'hideOnOverlayClick':true,
		'hideOnContentClick':true
	});
	if($('#keyvisual').length > 0) startKVRotation();
});

/* show / hide forms */
$('.loginform .sw').click(function() {
	$('.loginform').hide();
	$('.forgotpassword').show('slow');
});
$('.forgotpassword .sw').click(function() {
	$('.forgotpassword').hide();
	$('.loginform').show('slow');
});

/* execute at modal window launch */
function modalLoaded() {
	$('.change-address ul').equalHeights();
}
/* modal window launch */
if($('.new-window').length) {
	$('#lightbox').jqm({ajax: '@href', trigger: 'a.new-window', onLoad: modalLoaded});
}

/* keyvisual toggle */
$('#keyvisual .sw li').click(function () {
	if($(this)[0].className == 'active') return false;
	var active = $(this)[0].className;
	$('#keyvisual .sw .active').removeClass('active');
	$('#keyvisual .sw .' + active).addClass('active');
	$('#keyvisual .kv .active').fadeOut(200).delay(200).removeClass('active');
	$('#keyvisual .kv .' + active).fadeIn(500).addClass('active');
	/* reset rotation timing */
	clearInterval(KVRotation);
	startKVRotation();
});

/* keyvisual rotate */
function startKVRotation() {
	KVRotation = setInterval('rotateKV()',5000);
}
function rotateKV() {
	var activeKV = $('#keyvisual .kv .active');
	var activeSW = $('#keyvisual .sw .active');
	activeKV.fadeOut(200).removeClass('active');
	activeSW.removeClass('active');
	if(activeKV.next().length > 0) {
		activeKV.next().fadeIn(500).addClass('active');
		activeSW.next().addClass('active');
	} else {
		$('#keyvisual .kv li:first-child').fadeIn(500).addClass('active');
		$('#keyvisual .sw li:first-child').addClass('active');
	}
}

function closeAddressPicker(){
    $('#lightbox').jqmHide();
    var l = window.location.href;
    window.location.href = l;
    return false;
}