// Initialization script

jQuery(function(){
	
	$('.qmclear').remove();

	setWinHeight();
	$(window).resize(function(){
		setWinHeight();
	});
		
	$('.scroll.enabled')
		//.scrollable({ circular: false })
		.mouseenter(function() {
			try {
				//$(this).data('scrollable').next();
				$(this).children('ul').children('li.brand').stop().animate({ left: '-153px' });
				$(this).children('ul').children('li.bedding').stop().animate({ left: '0' });
			} catch(err) {
				//console.log(err);
			}
		})
		.mouseleave(function(){
			try {
				//$(this).data('scrollable').begin();
				$(this).children('ul.items').children('li.brand').stop().animate({ left: '0' });
				$(this).children('ul.items').children('li.bedding').stop().animate({ left: '153px' });
			} catch(err) {
				//console.log(err);
			}
		});
	
	$('#grid')
		.delegate('a', 'click', function(event){
			event.preventDefault();
			if (!($(this).closest('div.scroll').hasClass('disabled'))) {
				var $href = $(this).attr('href').toString();
				$('#underlay').fadeIn();
				$('#information_list .brand').hide();
				$('#information').animate({ top: '70px', height: winHeight }, function(){
						try {
							$($href)
								.show()
								.jScrollPane({
									wheelSpeed: 300,
									scrollbarWidth: 12,
									scrollbarMargin: 0,
									showArrows: true
								})
								.children('div.content')
								.children('div.scrollshow')
									.each(function(){
										if ($(this).data('scrollable')==null) {
											try {
												$(this).scrollable({ circular: true })
													.autoscroll(6000)
													.navigator({ navi: '.navi' });
											} catch(err) {
												//console.log(err);
											}
										}
									});
						} catch(err) {
							//console.log(err);
						}
				});
			} //-if (!($(this).closest('div.scroll').hasClass('.disabled')))
		});
	
	$('.close')
		.click(function(){
			try {
				$('#information').animate({ top: '-500px', height: '400px' }, function(){
						$('#information_list .brand').each(function(){
								var $this = $(this);
								if ($this.parent().hasClass('jScrollPaneContainer')) {
									try {
										$this.jScrollPaneRemove();
										$this.attr('style', '');
										/*$(this).unwrap().attr('style', '').hide();
										$('.jScrollCap').remove();
										$('.jScrollPaneTrack').remove();
										$('.jScrollArrowUp').remove();
										$('.jScrollArrowDown').remove();*/
									} catch(err) {
										//console.log(err);
									}
								}
							})
						});
				$('#information_list .brand').hide();
				$('#underlay').fadeOut();
				return false;
			} catch(err) {
				//console.log(err);
			}
		});
					
	$('a#toggleLayout')
		.live('click', function(){
			$('body').toggleClass('fixed');
		});
	
	drawCopyrightYear();
	
	$('a[rel$="external"]')
		.click(function(){
			this.target = "_blank";
		});
	
}); // $(function(){})

function setWinHeight() {
	$viewportHeight = $(window).height();
	winHeight = $viewportHeight - 100;
}


function drawCopyrightYear() {
	var today = new Date();
	var fullyear = today.getFullYear();
	$('#cpyear').html(fullyear);
}

