var selectedModule;
var moduleDimensions = {
	mikimoto: {
		width: 805,
		height: 535
	},
	roberto_coin: {
		width: 906,
		height: 535
	},
	omega_watches: {
		width: 805,
		height: 525
	},
	pennypreville: {
		width: 802,
		height: 549
	}
};

var resizeFancyBox = function() {
	$('#fancybox-close').css({
		right: '-50px'
	});
	
	$('#fancybox-wrap, #fancybox-outer, #fancybox-content').css({
		'height': moduleDimensions[selectedModule].height,
		'width': moduleDimensions[selectedModule].width
	});
	
	$('#fancybox-content').css({
		'border-width': 30
	});
	$.fancybox.center();
};

var showLogo = function(elm) {
	$('.fade', elm).stop().animate({
		opacity: 0.0
	}, 400 );
	$('.logo', elm).stop().animate({
		opacity: 1.0
	}, 800 );
};

var hideLogo = function(elm) {
	$('.fade', elm).stop().animate({
		opacity: 1.0
	}, 400 );
	$('.logo', elm).stop().animate({
		opacity: 0.0
	}, 400 );
};

Cufon.replace('nav a', {
	fontFamily: 'sackers',
	hover: true
});

Cufon.replace('#rosette, button, .content-box.staff p, .popup-window a, #popup-bio p', {
	fontFamily: 'gotham',
	hover: true
});

Cufon.replace('#title h1', {
	fontFamily: 'engravers'
});

// Check for IE6
function is_ie6(){
	return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
}

(function($) {
	
	// Uniform
	$("input:radio").uniform();
	
	// Fix for back button caching
	if (window.addEventListener) {
		window.addEventListener('unload', function() {}, false);
	}
	
	// Activate home page flash
	
	// Check to see if flash is available and display the flash piece if it is.
	if($.flash.available) {
		var cacheBuster = Math.floor(Math.random() * 999999999);
		$('#flash-wrapper').flash({
			swf: 'public/flash/shell.swf?'+cacheBuster,
			width: 950,
			height: 500,
			allowScriptAccess: "always",
			bgcolor: '#ffffff',
			allowFullscreen: "true",
			flashvars: {
				file: 'public/flash/beauty_banner.swf?url=http://www.octannerstore.com/events/news'
			}
		});
	}
	else {
		$('#flash-wrapper a').show();
	}
	
	
	// Initialize fancybox
	// Load the classic theme
	Galleria.loadTheme(skinPath + '/javascript/galleria.classic.min.js');
	
	// Initialize Galleria
	$('#galleria').galleria();
	
	
	// fancybox
	$('.open-photo-gallery').fancybox({
		'scrolling': 'no',
		'type': 'iframe',
		'width': 664,
		'height': 564
	});
	
	$('.directions-link').fancybox({
		'scrolling': 'no',
		'type': 'iframe',
		'width': 664,
		'height': 564
	});
	
	$('.gifts-popup').fancybox({
		'scrolling': 'no',
		'type': 'iframe',
		'width': 664,
		'height': 427,
		'onComplete': function() {
			hideLogo();
		}
	});
	
	$('.jewelry-popup').fancybox({
		'scrolling': 'no',
		'type': 'iframe',
		'width': 664,
		'height': 447,
		'onComplete': function() {
			hideLogo();
		},
		'onClosed': function() {
			$('#fancybox-wrap, #fancybox-outer, #fancybox-content').css({
				height: 447,
				width: 664
			});
			
			$('#fancybox-close').css({
				right: '-10px'
			});
		}
	});
	
	$('.watches-popup').fancybox({
		'scrolling': 'no',
		'type': 'iframe',
		'width': 664,
		'height': 477,
		'onComplete': function() {
			hideLogo();
		}
	});
	
	$('.bio-popup').fancybox({
		'scrolling': 'no',
		'type': 'iframe',
		'width': 664,
		'height': 500,
		'onComplete': function() {
			hideLogo();
		}
	});
	
	$('.module').click(function() {
		selectedModule = $(this).data('role');
	}).fancybox({
		'scrolling': 'no',
		'type': 'iframe',
		'padding': 30,
		'width': 800,
		'height': 500,
		'onComplete': function() {
			$('#fancybox-close').css({
				right: '-50px'
			});
			$('#fancybox-wrap, #fancybox-outer, #fancybox-content').css({
				height: moduleDimensions[selectedModule].height,
				width: moduleDimensions[selectedModule].width
			});
			$.fancybox.center();
		}
	});
	
	// Run image fade for thumbnail rollovers
	if (is_ie6()) {
		$('.content-box').hover(
			function() {
				$('.fade', this).stop().fadeOut(400);
				$('.logo', this).stop().fadeIn(800);
			},
			function() {
				$('.fade', this).stop().fadeIn(400);
				$('.logo', this).stop().fadeOut(400);
			}
		);
	}
	else {
		$('.content-box').hover(
			function() {
				showLogo(this);
			},
			function() {
				hideLogo(this);
			}
		);
	}
	
	// Right column accordion option
	$(".msg_body").hide();
	$(".msg_body.first").show().find('.gem-image').fadeIn(500);
	
	// Toggle the component with class msg_body
	if ($('.gem-image').length > 0) {
		$(".msg_head").click(function(){
			var clicked = $(this);
			$('.msg_head.active').removeClass('active').parent().find('.gem-image').fadeOut(300, function(){
				$(this).parent().slideUp(500);
				clicked.addClass('active').parent().find('.msg_body').slideDown(500, function(){
					$(this).find('.gem-image').fadeIn(500);
				});
			});
			return false;
		});
	}
	else {
		$(".msg_head").click(function(){
			var clicked = $(this);
			$('.msg_head.active').removeClass('active');
			$('.msg_body').slideUp(500);
			clicked.addClass('active').parent().find('.msg_body').slideDown(500);
			return false;
		});
	}
	
	// Rotating images
	
	$('.rotating-pics').cycle({
		fx: 'fade',
		timeout:  3000,
		speed: 3500
	});
	
	// Left nav current page indicator
	var currentNavItem = '#left-column nav ul li a.'+currentView;
	$(currentNavItem).addClass('active');
	
	if (currentSection !== '') {
		// Primary nav current section indicator
		var currentPrimaryNavItem = $('#container header nav a.' + currentSection);
		$(currentPrimaryNavItem).addClass('active');
	}
	
})(this.jQuery);
