﻿$(document).ready(function(){
	if ($.browser.msie && $.browser.version == 6) {
		ieFixScroll();
		$(window).scroll(function(){ ieFixScroll() });
	}
	
	$('#product').click(function(){
		$(this).toggleClass('act');
		if($(this).is('.act')) $('#right-colum').fadeIn(500);
		else $('#right-colum').fadeOut(500);
		return(false);
	});
	$('#desc').click(function(){
		$(this).toggleClass('act');
		if($(this).is('.act')) $('#left-colum').fadeIn(500);
		else $('#left-colum').fadeOut(500);
		return(false);
	});
	$('#hidden').click(function(){
		$('#menu-top').animate({top:0-$('#menu-top').height()},300);
		return(false);
	});
	$('#detail').click(function(){
		$('#menu-top').animate({top:0},300);
		return(false);
	});
	$('a.close').click(function(){
		var parent = $(this).parent().fadeOut(500);
		if( $(parent).is('#right-colum') ) $('#product').removeClass('act');
		else if( $(parent).is('#left-colum') ) $('#desc').removeClass('act');
		return(false);
	});
	
	$('#list a').click(function(){
		var current = $('a.current,a.loading','#list >ul');
		var goTo = false;
		
		if( $(this).is('.next') ){
			goTo = $(current).parent().next().children('a');
			if( !$(goTo).length ) goTo = $('#list >ul >li').first().children('a');
		}else if( $(this).is('.prev') ){
			goTo = $(current).parent().prev().children('a');
			if( !$(goTo).length ) goTo = $('#list >ul >li').last().children('a');
		}else if(!$(this).is('.current') || $(this).is('.loading')){
			goTo = $(this);
		}
		
		if(goTo){
			$(current).removeClass('current loading');
			$('#bg-img >div').remove();
			var href = $(goTo).addClass('loading').attr('href');
			var img = $('#bg-img').prepend('<div><img src="'+href+'" alt="img" /></div>').children('div').children('img');
			$(img).load(function(){
				$(img).css('visibility','visible').hide().fadeIn(1000,function(){ 
					$('#bg-img >img').remove();
					$(img).clone().prependTo('#bg-img');
					$(img).parent().remove();
				});
				$('#list >ul a.loading').attr('class','current');
				$('#img-info').html( $('~div.info',goTo).html() );
			});
		}
		return(false);
	});
	
/*	$('body >h1,#content').hide();

	$('#detail-2').click(function(){
		$(this).toggleClass('act');
		$(this).toggleText('Скрыть','Информация');
		
		if($(this).is('.act')) $('body >h1,#content').fadeOut(500);
		else $('body >h1,#content').fadeIn(500);
		
		return(false);
	});

*/

$('body >h1,#content').css({'margin-left':'-9999px','height':'100px'});

$('#detail-2').click(function(){
        $(this).toggleClass('act').toggleText('Скрыть','Информация');
        
        if($(this).is('.act')) $('body >h1,#content').fadeOut(500);
		else $('body >h1,#content').css({'margin-left':0,'height':'auto','display':'none'}).fadeIn(500);      
        return(false);
    });


});


/*
function ieFixScroll(){
	$('#footer').stop(true).animate({paddingTop:1},1).animate({paddingTop:0},1);
	$('h1').css('top',50+$(window).scrollTop());
	$('#bg-img').css('top',$(window).scrollTop());
	$('#menu-top').css('top',$(window).scrollTop());
}
*/
function ieFixScroll(){
    $('#footer').stop(true).animate({paddingTop:1},1).animate({paddingTop:0},1);
    $('h1').css('top',50+$(window).scrollTop());
    $('#bg-img,#detail,#detail-2,#menu-top').css('top',$(window).scrollTop());
}

jQuery.fn.toggleText = function(a,b) {
	return this.html(this.html().replace(new RegExp("("+a+"|"+b+")"),
	function(x){return(x==a)?b:a;}));
}



