(function($){$.fn.extend({center:function(){return this.each(function(){var top=($(window).height()- $(this).outerHeight())/2+$(window).scrollTop();var left=($(window).width()- $(this).outerWidth())/2+$(window).scrollLeft();$(this).css({position:'absolute',margin:0,top:(top>0?top:0)+'px',left:(left>0?left:0)+'px'});});}});})(jQuery);function swapNodes(a,b)
{var aparent=a.parentNode;var asibling=a.nextSibling===b?a:a.nextSibling;if(jQuery(a).hasClass('initial'))
{jQuery(a).removeClass('initial');jQuery(b).before(a);asibling=a.nextSibling;}
b.parentNode.insertBefore(a,b);aparent.insertBefore(b,asibling);}
function setThumbBlocks(w,h,page)
{var thumbMarginLeft=9;var thumbMarginBottom=9;var paddingTopBottom=2;var thumbWidth=225+ thumbMarginLeft;var thumbHeight=302+ thumbMarginBottom;var thumbColumnCount=Math.floor((w- 2*27)/thumbWidth);$('.thumb-block .filter').click(function(){var filter=$(this).data('filter');$(this).parent().find('.filter').removeClass('active-text');$(this).addClass('active-text');$(this).parents('.thumb-block').find('input[name="filter"]').val(filter);});if(typeof page==='undefined'){page='default';}
$('.thumb-block ul').each(function(){var imageCount=$(this).find('li').length;var type=$(this).data('type');var maxRows=$(this).data('rows');var rows=Math.ceil(imageCount/thumbColumnCount);var calculatedWidth;if(type=='models'){thumbHeight=339+ thumbMarginBottom;}
switch(page){case'model':maxRows=1000;rows=Math.ceil((imageCount- 1+ 6)/thumbColumnCount);calculatedWidth=thumbColumnCount*thumbWidth+ thumbMarginLeft;$(this).parent().find('.header').width(calculatedWidth);$(this).width(calculatedWidth);$('.sites-container').width(calculatedWidth);$(this).parent().find('h1').width(calculatedWidth);$(this).height(Math.min(maxRows,rows)*thumbHeight- thumbMarginBottom-paddingTopBottom);break;case'scene':break;case'websites':thumbHeight=331;calculatedWidth=thumbColumnCount*thumbWidth- thumbMarginLeft;$(this).parent().find('.header').width(calculatedWidth);$(this).width(calculatedWidth);$('.sites-container').width(calculatedWidth);$(this).parent().find('h1').width(calculatedWidth);break;default:calculatedWidth=thumbColumnCount*thumbWidth- thumbMarginLeft;$(this).parent().find('.header').width(calculatedWidth);$(this).width(calculatedWidth);$('.sites-container').width(calculatedWidth);$(this).parent().find('h1').width(calculatedWidth);$(this).height(Math.min(maxRows,rows)*thumbHeight- thumbMarginBottom-paddingTopBottom);break;}
var promo1=$(this).find('.promo-1'),promo2=$(this).find('.promo-2');if((promo1.length>0)&&(promo2.length>0))
{var promo_replacement1=$(this).find('li:eq('+(2*thumbColumnCount- 1- 1)+')')[0];swapNodes(promo1[0],promo_replacement1);var promo_replacement2=$(this).find('li:eq('+((Math.min(maxRows,rows)- 2)*thumbColumnCount+ 1)+')')[0];swapNodes(promo2[0],promo_replacement2);}
$(this).find('li').removeClass('first');$(this).find('li').each(function(index)
{if(index%thumbColumnCount===0)
{$(this).addClass('first');}});});/*
	switch(page){

		case 'scenes':
			
			$('.thumb-block ul').each(function () {

				
				thumbWidth = 216 + thumbMarginLeft;
				thumbColumnCount = Math.floor((w - 2 * 27 -492 - 9) / thumbWidth);
				
				if (thumbColumnCount >= 2){
				
					$(this).parent().find('.infos').width(thumbColumnCount * thumbWidth - thumbMarginLeft);
					$(this).width(thumbColumnCount * thumbWidth - thumbMarginLeft);
					$(this).parent().width(thumbColumnCount * thumbWidth + thumbMarginLeft +492);

					//Set 'first' class to first column elements to fix margin
					$(this).find('li').removeClass('first');
					$(this).find('li').each(function (index) {

						if (index % thumbColumnCount === 0) {

							$(this).addClass('first');
						}
					});				
				}
			});	
	
		break;		
	
		case 'model':
			
			$('.thumb-block ul').each(function () {

				//var maxRows = $(this).data('rows');
				var maxRows = 1000;
				var imageCount = $(this).find('li').length;
				//The first big image takes up 6 thumb places
				var rows = Math.ceil( (imageCount - 1 + 6) / thumbColumnCount);
				

				$(this).parent().find('.header').width(thumbColumnCount * thumbWidth);
				$(this).width(thumbColumnCount * thumbWidth - thumbMarginLeft);
				$(this).parent().find('h1').width(thumbColumnCount * thumbWidth - thumbMarginLeft);
				$(this).height(Math.min(maxRows, rows) * thumbHeight - thumbMarginBottom -paddingTopBottom);

				//Set 'first' class to first column elements to fix margin
				$(this).find('li').removeClass('first');
				$(this).find('li').each(function (index) {

					if (index % thumbColumnCount === 0) {

						$(this).addClass('first');
					}
				});

			});	
	
		break;	
	
		default:
			
			$('.thumb-block ul').each(function () {

				var imageCount = $(this).find('li').length;
				var maxRows = $(this).data('rows');
				var rows = Math.ceil(imageCount / thumbColumnCount);
				var type = $(this).data('type');
				
				if (type == 'models'){
					thumbHeight = 339 + thumbMarginBottom;
				}

				$(this).parent().find('.header').width(thumbColumnCount * thumbWidth);
				$(this).width(thumbColumnCount * thumbWidth - thumbMarginLeft);
				$(this).parent().find('h1').width(thumbColumnCount * thumbWidth - thumbMarginLeft);
				$(this).height(Math.min(maxRows, rows) * thumbHeight - thumbMarginBottom -paddingTopBottom);

				//Set 'first' class to first column elements to fix margin
				$(this).find('li').removeClass('first');
				$(this).find('li').each(function (index) {

					if (index % thumbColumnCount === 0) {

						$(this).addClass('first');
					}
				});
				
				//Set promo positions
				if($(this).find('.blue-promo').length && $(this).find('.blue-promo').length){
					swapNodes($(this).find('.blue-promo')[0], $(this).find('li:eq(' + (2 * thumbColumnCount - 1 - 1) + ')')[0]);
					swapNodes($(this).find('.red-promo')[0], $(this).find('li:eq(' + ((Math.min(maxRows, rows) - 2) * thumbColumnCount + 1) + ')')[0]);
				}
			});	
	
		break;
	}
	
	*/}
$(document).ready(function()
{if(jQuery('#mainSlideShowWrapper .slides img').length>0)
{var refimage=$('#refimage').get(0);if(jQuery.isEmptyObject(refimage))
{jQuery('#mainSlideShowWrapper .slides img').first().clone().removeClass('active').attr('id','refimage').hide().appendTo('body');}
jQuery('#refimage').bind('load',function()
{$(window).trigger('resize');});}
$('#dialog .close').live('click',function(){$('#dialog .content').html('');$('#dialog').hide();});if(typeof(Cufon)!=='undefined'){Cufon.replace('.promo .text strong, .thumb-block .wrapper .header .title, .sites-container .title, .trailer-button .text, .sites-container h2');}
$('#thumbSlider .next').click(function()
{clearTimeout(window.thumbSliderTimeout);var first_image=$('#thumbSlider ul li').first();var thumbWidth=first_image.width()+ 30;$('#thumbSlider ul').css('left',0);$('#thumbSlider ul').animate({'left':0-thumbWidth},300,function()
{$(first_image).insertAfter($('#thumbSlider ul li').last()).show();$('#thumbSlider ul').css('left',0);$('#thumbSlider ul li').removeClass('first');$('#thumbSlider ul li').first().addClass('first');autoSlide();});$('#thumbSlider .prev').show();});$('#thumbSlider .prev').click(function()
{clearTimeout(window.thumbSliderTimeout);var last_image=$('#thumbSlider ul li').last().insertBefore($('#thumbSlider ul li').first()).hide();$('#thumbSlider ul').css('left',(0-last_image.width()));$(last_image).show();$('#thumbSlider ul').animate({'left':0},300,function()
{autoSlide();});$('#thumbSlider .next').show();});var natsCookie=$.cookie('nats');if(natsCookie)
{$("a.quickLoginLink").each(function(linkEntity)
{var baseUrl=$(this).attr('href');$(this).attr('href',baseUrl+'&affcode='+natsCookie);});}});function showDialog(content)
{if($('#dialog').length===0)
{var html='<div id="dialog">'+'<div class="wrapper">'+'<div class="header"><h2>Dialog</h2><span class="close"><a href="javascript:void(0)">Close</a></span></div>'+'<div class="content"></div>'+'</div>'+'</div>';$('body').append(html);}
$('#dialog .content').html(content);$('#dialog').center().show();}
function setSmallSlideShow()
{var thumbWidth=207+ 28;var thumbsLeft=$('#thumbSlider ul').data('left')||0;var correction=$('#thumbSlider .pager:eq(0)').width()*2;var w=$(window).width();var h=$(window).height();var left=parseInt($('#thumbSlider ul').css('left'),10);var width=Math.max(1007,w);var w=$(window).width();var computed_width=0;$('#thumbSlider .list-wrapper').css('width','auto');$('#thumbSlider .list-wrapper ul').css('width','auto');$('#thumbSlider .list-wrapper ul li').show().css({'width':'auto','opacity':1});$('#thumbSlider .list-wrapper ul li').each(function(index,el)
{computed_width=computed_width+ $(el).outerWidth()+ parseInt($(el).css('margin-left'))+ parseInt($(el).css('margin-right'));});var thumbslider_width=computed_width+ $('#thumbSlider .prev').outerWidth()+ $('#thumbSlider .next').outerWidth();if(w>thumbslider_width)
{$('#thumbSlider').addClass('noarrows');$('#thumbSlider .list-wrapper').width(thumbslider_width);}
else
{$('#thumbSlider').removeClass('noarrows');$('#thumbSlider .list-wrapper').width(w- $('#thumbSlider .prev').outerWidth()- $('#thumbSlider .next').outerWidth());}
$('#thumbSlider .list-wrapper ul').css({'width':''});$('#thumbSlider .next').show();$('#thumbSlider .prev').show();}
function nextSlide(){var count=$('#mainSlideShowWrapper img').length;var slide=($('#mainSlideShowWrapper').data('slide')+ 1)%count;$('#mainSlideShowWrapper img.active').removeClass('active').animate({opacity:0},500);$('#mainSlideShowWrapper img:eq('+ slide+')').addClass('active').animate({opacity:1},500);$('#mainSlideShowWrapper').data('slide',slide);$('#mainSlideShowWrapper .pager .page').removeClass('active-text');$('#mainSlideShowWrapper .pager .page:eq('+ slide+')').addClass('active-text');}
function prevSlide(){var count=$('#mainSlideShowWrapper img').length;var slide=($('#mainSlideShowWrapper').data('slide')- 1+ count)%count;$('#mainSlideShowWrapper img.active').removeClass('active').animate({opacity:0},500);$('#mainSlideShowWrapper img:eq('+ slide+')').addClass('active').animate({opacity:1},500);$('#mainSlideShowWrapper').data('slide',slide);$('#mainSlideShowWrapper .pager .page').removeClass('active-text');$('#mainSlideShowWrapper .pager .page:eq('+ slide+')').addClass('active-text');}
function animateSlides(time){if(typeof time=='undefined'){time=3000;}
mainGalleryTimeout=setTimeout(function(){nextSlide();animateSlides(time);},time);}
function showSlide(number){$('#mainSlideShowWrapper img.active').removeClass('active').animate({opacity:0},500);$('#mainSlideShowWrapper img:eq('+(number- 1)+')').addClass('active').animate({opacity:1},500);$('#mainSlideShowWrapper').data('slide',(number- 1));$('#mainSlideShowWrapper .pager .page').removeClass('active-text');$('#mainSlideShowWrapper .pager .page:eq('+(number- 1)+')').addClass('active-text');}
function startGallery(time){animateSlides(time);}
function stopGallery(){clearTimeout(mainGalleryTimeout);}
function autoSlide()
{var slideInterval=5000;window.thumbSliderTimeout=setTimeout(function()
{var left=parseInt($('#thumbSlider ul').css('left'),10);var thumbWidth=195+ 30;setSmallSlideShow();if($('#thumbSlider ul li').length*thumbWidth+ left- thumbWidth<=$('#thumbSlider .list-wrapper').width())
{$('#thumbSlider .next').hide();$('#thumbSlider .prev').hide();}
else
{$('#thumbSlider .next').show();$('#thumbSlider .prev').show();$('#thumbSlider li:eq(0)').animate({'opacity':0,'width':0},300,function()
{$(this).css({'width':'auto','opacity':1}).appendTo('#thumbSlider ul');});autoSlide();}},slideInterval);}
function setBigImages()
{var w=$(window).width();var h=$(window).height();$('#refimage').show();window.original_image_width=$('#refimage').width();window.original_image_height=$('#refimage').height();$('#refimage').hide();$('#mainSlideShowWrapper, #movie').width(w);$('#mainSlideShowWrapper, #movie').height(h);var slide_height=$('#mainSlideShowWrapper .slides img').first().height();var minimal_height=h-($('#thumbSlider').outerHeight()/2);if(w>window.original_image_width)
{$('#mainSlideShowWrapper .slides img').css({'left':0,'margin-left':0,'height':'auto','width':w});if(slide_height>minimal_height)
{$('#mainSlideShowWrapper, #movie').height(minimal_height);}
else
{$('#mainSlideShowWrapper, #movie').height(slide_height);}}
else
{var width_difference=0-(original_image_width- w);var width_diff=-1*(window.original_image_width/2);var small_slide=(h- $('#thumbSlider').outerHeight()/2);if(h>minimal_height)
{if(window.original_image_height<minimal_height)
{$('#mainSlideShowWrapper, #movie').height(window.original_image_height);}
else
{$('#mainSlideShowWrapper, #movie').height(minimal_height);}}
else
{$('#mainSlideShowWrapper, #movie').height(window.original_image_height);}
$('#mainSlideShowWrapper .slides img').css({'margin-left':width_diff,'left':'50%','width':window.original_image_width,'height':window.original_image_height});}
setThumbBlocks(w-2*9,h);$('#mainMenu .search-and-login input[type="text"]').width(Math.max(140,Math.min(270,w-1024+140)));}
