$(function(){
    //sort
    $('.browse .sort .option').click(function(){
        var url = location.href.replace(/\/sort:[a-z0-9\-]+/g,'');
        url = url.replace(/\/direction:[a-z0-9\-]+/g,'');

        var direction = $('.value',this).attr('title') || '';

        location.href = url + '/sort:' + $('.value',this).text() + '/direction:' + direction;
    });

		$('.screen .items .img').live('mouseover', function(){
			index = $('.screen .items .img').index(this);
			if (index%3==0) $(this).addClass('first');

        var curr = $(this);
        var pos = $(this).position();
        var scroll = $(this).parent().parent().attr('id');
        scroll = scroll*880;
        var teste = $('.back .text',this).text();
        var description = $('.hidden.description',this).text();
        var price = $('.hidden.price',this).text();
        var details = $('.hidden.details',this).text();
        $('.popup2 .teste').text(teste);
        $('.popup2 .description').text(description);
        $('.popup2 .price').text(price);
        $('.popup2 .details').attr('href',details);

        $('.popup2').removeClass('popup2-2');

        if (curr.hasClass('first'))
				{
            pos.left = pos.left+350;
            $('.popup2').addClass('popup2-2');
        }

        $('.popup2').css({'left':(pos.left-80-scroll)+'px', 'top':(pos.top+130)+'px'}).show();
		});
		$('.screen .items .img').live('mouseout', function(event){
        if(event.relatedTarget.getAttribute('id') != 'popup2'){
            $('#popup2').hide();
        }
		});

    $('.fake-select').click(function(){
        var id = $(this).attr('id');
        var height = 0;

        if($('.'+id).is(':visible')){
            $('.'+id).animate({'height':'0px'},200,'linear',function(){$(this).hide()});
        }
        else{
            $('.'+id).show();
            $('.'+id+' .option').each(function(){
                height = height + $(this).height() + 17;
            });
            if(height > 300) height = 300;
            $('.'+id).animate({'height':height+'px'},200,'linear');
        }
    });
});

