$(document).ready(function() {
	rand = Math.round(2*Math.random())+1;
	
	$("a[rel='blank']").click(function(){
		window.open($(this).attr('href'));
		return false
	});

	$('#wrapper').append('<div id="preloader"><img src="img/str-left-hover.gif" alt="" /><img src="img/str-right-hover.gif" alt="" /></div>')
	
	

	
/*	$('.portfolio.main div span').hover(function(){
          $(this).children('em').children('a').addClass('active');                                      
     },function(){
          $('.portfolio div a').removeClass('active');               
     });*/
	
	$('#right.portfolio strong a ').click(function(){
		$.scrollTo($('#head'),{speed:1000});
		return false									   
	});
	

	
	
	$('.portfolio.main .list span a').click(function(){
		var linka = $(this).attr('href');
		var namea = $(this).attr('class');
		$('.portfolio.main .list div').removeClass('active');
		$(this).parent().parent().addClass('active');
		window.location.hash = namea;
		$('#overlay').width($(window).width()).height($(document).height());
		$('#zoom').css('top',$(document).scrollTop()+90).show()
		$('#overlay').fadeIn(500);
		
	
		
		
		$.get(linka,function(data){
   			var done = $(data).find('.inner').html();
			$('#zoom').html(done);
			
			update();
			}
		);
		return false
	});
	
	
	
	
	try
    {
    	$('#fav').jcarousel({scroll:1});   
    }
    catch(e) {;}

	$('#fav').css('overflow','visible');
	
	
	$('.bg').css('height',$('.q').height()-114+'px')
	
	$('#fav li:first-child div').addClass('active');
	$('#fav-text span').html($('#fav li div.active img').attr('alt'));
	
	$('#fav li div').hover(function(){
		$('#fav li div').removeClass('active');	
		$(this).addClass('active');				
		alttext = $('img',this).attr('alt');
		$('#fav-text span').html(alttext);
	},function(){
		$('#fav li div').removeClass('active');		
		$(this).addClass('active');			
	});
	
	$('#overlay').click(function(){
		$('#overlay').fadeOut(500);		
		$('#zoom').hide();
		$('#zoom object').remove();

		$('#zoom.inn').html('');
	});
	
	$('.jcarousel-next').hover(function(){
		if ($(this).hasClass('jcarousel-next-disabled')) {
		}
		else {
			$(this).addClass('active')
		}
	},function(){
		$(this).removeClass('active');
	});
	
	$('.jcarousel-prev').hover(function(){
		if ($(this).hasClass('jcarousel-prev-disabled')) {
		}
		else {
			$(this).addClass('active')
		}
	},function(){
		$(this).removeClass('active');
	});
	$('#overlay').css('opacity','0.6');


	$(window).resize(function(){
		$('#overlay').width('1%').width($(document).width());
		$('#overlay').height('1%').height($(document).height());	
		$('.bg').height('1%').css('height',$('.q').height()-114+'px');
	});
	/*
	$('.portfolio.main div').click(function(){
		num = $(this).prevAll().size() + 1;
		window.location.hash = num;
	});
	
	if (window.location.hash) {
  		anchor = window.location.hash.substr(1);
		anchor = anchor - 1
		$('.portfolio.main div:eq('+anchor+')').click();
	}*/
	
	
		if (window.location.hash) {
  		anchor = window.location.hash.substr(1);
		$('#right.portfolio .list div a.'+anchor).click();
	}
	

}); 

function update(){
	$('#zoom .port a').click(function(){
		$('#overlay').click();
		
		return false
	});
	$('#zoom .prev').click(function(){
		$('.list .active').prev().find('a').click();
		return false
	});
	$('#zoom .next').click(function(){
		$('.list .active').next().find('a').click();
		return false
	});
	$('#overlay').css('height','1%').height($(document).height());
	
}


function flash(fname,fwidth,fheight) {
	$('#zoom').html('<div id="close"><a href="#">Закрыть</a></div><object type="application/x-shockwave-flash" data="files/images/swf_banner/'+fname+'" width="'+fwidth+'" height="'+fheight+'"><param name="movie" value="files/images/swf_banner/'+fname+'" /></object>')
	$('#overlay').width($(window).width());
	$('#overlay').height($(document).height());		
	ofset = $(document).scrollTop() + ($(window).height()/2) - fheight/2;
	$('#overlay').fadeIn(500);
	$('#zoom').show().css('width',fwidth).css('height',fheight).css('margin-left',-fwidth/2).css('top',ofset);
	
	
	
	$('#close a').click(function(){
		$('#overlay').fadeOut(500);		
		$('#zoom').hide();
		$('#zoom object').remove();
		return false
	});
}
