var brandScrollTimer;
var mOffset = parseInt(0);
var realHeight = '-'+($('.brandList li').length * 20-210);	

$(function(){
	windowHeight = $(window).height();
	windowWidth = $(window).width();
	contentHeight = $('.mainSiteContainer').innerHeight();
	Cufon.replace('.mFont', {hover: true});
	
	//Social Media Hover
	$('.btnFacebook').mouseover(function(){
		$(this).addClass('hover');
		$('.speechFacebook').show();
	}).mouseout(function() {
		$(this).removeClass('hover');
		$('.speechFacebook').hide();
	});
	$('.btnTwitter').mouseover(function(){
		$(this).addClass('hover');
		$('.speechTwitter').show();
	}).mouseout(function() {
		$(this).removeClass('hover');
		$('.speechTwitter').hide();
	});
	
	//Catalog Hover
	$('.catalogWrapper').mouseover(function() {
		$('.catalogBtn').addClass('hover');
		$('.catalogSpeech').show();
	}).mouseout(function(){
		$('.catalogBtn').removeClass('hover');
		$('.catalogSpeech').hide();
	});
	
	//Brand List Scroller
	$('.brandListContainer').bind('mousewheel', function(event, d){
		if(d < 0){
			if(mOffset > realHeight){
				mOffset = mOffset-50;
				$('.brandList').animate({
					top: mOffset
				}, 100);
			}
		}else{
			if(mOffset < 0){
				mOffset = mOffset+50;
				$('.brandList').animate({
					top: mOffset
				}, 100);
			}
		}
	});
	
	$('.contentImage').css('height', $('.contentDetails').height());
	
	var currentPosition = 1;
	
	//Footer Ajax Lightboxes
	$('.footerNavigation a, .btnAjaxLink').live('click', function(){
		currentPosition = $(window).scrollTop();
		$(window).scrollTop(1);
		$('body').css('overflow', 'hidden');
		$('.mOverlay').fadeIn();
		$.ajax({
			url: $(this).attr('href'),
			'success': function(data){
				$('.ajaxContent').remove();
				$('body').append(data);
				Cufon.replace('.mFont');
			}
		});
		
		return false;
	});
	
	// Product Details Lightbox
	$('.productOpener').live('click', function(){
		currentPosition = $(window).scrollTop();
		$(window).scrollTop(1);
		$('body').css('overflow', 'hidden');
		$('.mOverlay').fadeIn();
		$.ajax({
			url: $(this).attr('href'),
			'success': function(data){
				$('.ajaxContent').remove();
				$('body').append(data);
				Cufon.replace('.mFont');
			}
		});
		
		return false;
	});
	
	//Lightbox close
	$('.btnClose , .mOverlay').live('click', function(){
		$('.mOverlay, .ajaxContent').fadeOut();
		$('body').css('overflow', 'visible');
		$(window).scrollTop(currentPosition);
	});
	
	//Search Tabs
	$('.searchTabsContainer a').click(function(){
		if(!$(this).hasClass('selectedSearch')){
			$('.selectedSearch').removeClass('selectedSearch');
			$('.selectedListing').fadeOut().removeClass('selectedListing');
			$(this).addClass('selectedSearch');
			$('.'+$(this).attr('rel')).fadeIn().addClass('selectedListing');
		}
	});
});

function scrollTop(){
	if(mOffset > realHeight){
		mOffset = mOffset-50;
		$('.brandList').animate({
			top: mOffset
		}, 100);
	}
}

//Contact Page Map Switch 
function showMap(mapID){
	$('.map1, .map2').hide();
	$('.map'+mapID).show();
}

function submitForm(){
	$('#search').submit();
}
