$(window).load(function(){
	
	theMenu();
	
	catalogFog();
	
	catScroller();
	
	prodFirstPic();
	
	download();
	
	
	
});

$('#bguploaded').load(function(){
	var width = $(this).width();
	$(this).css(
		'left', (($(window).width() - width)/2) + 'px'
	).fadeIn();
	
});

function theMenu(){	
	var menu = $('#menu .menu');
	var b2b = $('#menu .b2b');
	
	$(menu).hover(function(){
		
		$(this).children('.theMenu').animate({
			width: '257px',
			height: 'auto',
			overflow: 'hidden'
		}, {queue: false, duration:600});
		
	}, function(){
		
		$(this).children('.theMenu').stop().hide();
		$(this).children('.theMenu').css({
			width: '0px',
			height: 'auto',
			overflow: 'hidden'
		});
		
	});
	
	
	$(b2b).hover(function(){
		
		$(this).children('.theMenu').animate({
			width: '257px',
			height: 'auto',
			overflow: 'hidden'
		}, {queue: false, duration:600});
		
	}, function(){
		
		$(this).children('.theMenu').stop().hide();
		$(this).children('.theMenu').css({
			width: '0px',
			height: 'auto',
			overflow: 'hidden'
		});
		
	});
	
	
}


function catalogFog(){
	
	$('.catalog .hover').attr('data-hover', 'yes');
	
	$('.sex').mouseover(function(){
		$('.catalog .hover').removeClass('hover');
		$(this).addClass('hover');
	});
	
	$('.sex').mouseout(function(){
		$(this).removeClass('hover');
		$('[data-hover=yes]').addClass('hover');
	});
}

function catScroller(){
	
	var step = 140;
	var scroll = 0;
	var height = 0;
	var up;
	var down;
	
	var cheight;
	
	$('.catScroller').hover(function(event){
		
		scroll = $(this).children('.catsInScroller').first()
		height = $(scroll).height();
		cheight = $(this).height();
		
		up = $(this).find('.doup').first();
		down = $(this).find('.dodown').first();
		
		//arrows();
	},
	function(event){
		
	});
	

}

if($('.doup')){
	$('.doup').first().mousedown(function(){ slide_Down(this,0); });
	$('.doup').first().mouseup(function(){ slide_Down(this,1); });
	$('.dodown').first().mousedown(function(){ slide_Up(this,0); });
	$('.dodown').first().mouseup(function(){ slide_Up(this,1); });

}

function slide_Up(btn, option){

	pContainer = $(btn).parents(".catScroller");//$(".catScroller").first();
	pSlider =  $(btn).parents(".catScroller").children(".catsInScroller").first();//$(".catsInScroller").first();
	
	maxTop = $(pSlider).height() - $(pContainer).height();

	if(option == 0){
		$(pSlider).animate({
			marginTop : "-" + maxTop + "px"
		},{
			duration: 2000,
			easing: 'linear'
		}
		);
	} else {
		$(pSlider).stop(true,false);
	}

}

function slide_Down(btn, option){

	pContainer = $(btn).parents(".catScroller");//$(".catScroller").first();
	pSlider =  $(btn).parents(".catScroller").children(".catsInScroller").first();//$(".catsInScroller").first();

	if(option == 0){
		$(pSlider).animate({
			marginTop : "0px"
		},{
			duration: 2000,
			easing: 'linear'
		}
		);
	} else {
		$(pSlider).stop(true,false);
	}

}


function prodFirstPic(){
	$('#firstProdPic').hover(function(){
		$(this).children('.thumbs').first().slideDown();
	}, 
	function(){
		$(this).children('.thumbs').first().slideUp();
	});
}

function download(){
	$('.gthumbc').hover(function(){
		$(this).children('.dnl').first().slideDown();
	},
	function(){
		$(this).children('.dnl').first().slideUp();
	});
}

function fbs_click(link, name) {
	var u = location.href;
	var t = document.title;

	
	/*window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'Facebook Share','toolbar=0,status=0,width=626,height=436');
	*/
	
	
	window.open('https://www.facebook.com/dialog/feed?app_id=154363287986995&link=' + encodeURIComponent(u) + '&picture=' + encodeURIComponent($(link).attr('rel')) + '&name=' + encodeURIComponent(name) + '&caption=' + encodeURIComponent(t) + '&description=' + encodeURIComponent($('meta[name=description]').attr('content')) + '&message=' + encodeURIComponent(t) + '&redirect_uri=' + encodeURIComponent(u),'Facebook Share','toolbar=0,status=0,width=626,height=436');

	
	return false;
}

function tw_click(t) {
	var u = location.href;
	window.open('http://twitter.com/share?url='+encodeURIComponent(u)+'&text='+encodeURIComponent(t),'Twitter','toolbar=0,status=0,width=626,height=436');
	return false;
}


$(".catsInScroller .prodEl .thumb").each(function(btn){
	$(this).click(function(event){
		oldLink = $(this).attr('href');
		$('#iframeImage').css({'display':'block'});
		$('#firstProdPic').css({'display':'none'});
		event.preventDefault();
		$(this).next().attr('action',oldLink);
		$(this).next().submit();
	});
});
