
	//Loading time  *************************************

//var loader = jQuery('<img style="z-index:100; position:absolute;  top:50%; left: 50%; margin-left:-177px;margin-top:-130px" src="http://msqrd.co/wp-content/themes/Msqrd1.0/images/msqrd_loader.png" ><img style="z-index:100; position:absolute;  top:50%; left: 50%; margin-left:-0px;margin-top:-90px" src="http://msqrd.co/wp-content/themes/Msqrd1.0/images/loader.gif" >');
 
jQuery(document).ready(function(){
        
//$('body').css('background-color','#fff');
//$('#outer-wrapper').hide();

 
//loader.prependTo('body');

});
 
jQuery(window).load(function(){

//loader.fadeOut(50);
//$('body').css('background-color','#efefef');
//$('#outer-wrapper').fadeIn(1500);

});

	
	var HTTP_PATH = 'http://msqrd.co/wp-content/themes/Msqrd1.0/' ; 
	var numberOfStories = 6 ; 
	var currentStory = 1 ; 
	var change_counter = 2 ; 
	
	function nextStory () {
		if (currentStory <4  ){
		
		currentStory++ ;
		$('#rest-featured').animate({ top:'-=142',opacity:0.25}, 450);
		$('#rest-featured').animate({ opacity:1}, 250);
		}
		return false;
		}	
		
	
	function prevStory () {
		
		if (currentStory > 1){
		currentStory-- ;
		$('#rest-featured').animate({ top:'+=142',opacity:0.25}, 450);
		$('#rest-featured').animate({opacity:1}, 250);
		
		}
		
		return false;
		
		}
		
	  function gcd (a, b) {
            return (b == 0) ? a : gcd (b, a%b);
      }	

	function fix_resize() {
	// fixing dimentions
	if ($('body').width()>=$('#outer-wrapper').width()){
	$real = ($('body').width()-$('#outer-wrapper').width())/2+10+'px' ;
	$('.post-right').css('right',$real);
	$('.img-viewer').css('right',$real);
	}
	else {
	$real = '490px';
	$('.post-right').css('left',$real);
	$('.img-viewer').css('left',$real);
		}
		
	
	$height = window.innerHeight - 120 - 45 -115 + 47 + 'px' ;  
	$height2 = window.innerHeight - 120 - 45 - 115 - 80+47 + 'px' ;
	$('.rest-featured-main2').css('height',$height2);
	$('.rest-featured').css('height',$height);
	//$('#inner-wrapper').css('height',window.innerHeight+'px');
	$('.img-viewer').css('height',window.innerHeight-120-45-40+'px');
	$('.gallery-viewer').css('height',window.innerHeight-120-45+10+'px');
	$('.gallery-viewer .thumbs').css('height',window.innerHeight-120-45-110+'px');
	$('.gallery-viewer .large').css('height',window.innerHeight-120-45-140+'px');
	$('.img-viewer .image').css('height',window.innerHeight-120-45-108+'px');
	$('.image-scroller').css('height',window.innerHeight-120-45+'px');
	// end of fixing dimentions
		}
	
	
	
	window.setInterval('autoChange()',3000);
	function autoChange () {
	var counter = change_counter ;
		
	$('.big-featured ul li').removeClass('activee') ; 
	$('.big-featured ul li[count|="'+counter+'"]').addClass('activee') ; 
	
	var count = counter ;
	var currentCount =  $('.big-featured .images img[class|="selected"]').attr('imgcount');

	$('.big-featured .images img[imgcount|="'+currentCount+'"]').removeClass('selected');
	$('.big-featured .images img[imgcount|="'+currentCount+'"]').addClass('hidden');
		$('.big-featured .images p[imgcount|="'+currentCount+'"]').removeClass('selected');
	$('.big-featured .images p[imgcount|="'+currentCount+'"]').addClass('hidden');
	
	$('.big-featured .images img[imgcount|="'+count+'"]').removeClass('hidden');
	$('.big-featured .images img[imgcount|="'+count+'"]').addClass('selected').animate({opacity:0.25}, 300).animate({opacity:1}, 300);;
		$('.big-featured .images p[imgcount|="'+count+'"]').removeClass('hidden');
	$('.big-featured .images p[imgcount|="'+count+'"]').addClass('selected').animate({opacity:0.25}, 300).animate({opacity:1}, 300);;	
	
	if (change_counter <= $('.big-featured ul li').last().attr('count') - 1 ) {change_counter++;}else {change_counter = 1 ;}

	}
	$(window).resize(function() {
	fix_resize();
	});	
		
	$(document).ready(function () {
								
	$('#outer_container').stop().animate({'bottom':'179px'},1000);	
	fix_resize();
	
	 
	$('#outer_container .close_button').bind("click",function(){
	if ($('#outer_container').css('bottom') == '179px') {
	$('#outer_container').stop().animate({'bottom':'10px'},1000);	
	$('#outer_container .close_button').html('<img src="'+HTTP_PATH+'/images/up_open.jpg" />');
	}
	else {
	$('#outer_container').stop().animate({'bottom':'179px'},1000);	
	$('#outer_container .close_button').html('<img src="'+HTTP_PATH+'/images/bottom_close.jpg" />');	
		
		}
	});
	
	jQuery('.post-content div.wp-caption a').attr('rel','example_group');
	
	$('#show-gallery').bind("click",function(){$('#gallery-container').css('visibility',' visible').fadeIn('slow');});
	
	var num_rows =  Math.round($('.gallery-viewer .thumbs .images img').length / 2 ); 
	var gallery_step = 0 ;
	
	$('#gallery_up').bind("click",function(){
	
	if (gallery_step < num_rows - 2 ) {
	gallery_step++ ;								   
	$('#gallery_images').animate({ top:'-=245'}, 450);
	}
	
	});
	
	$('#gallery_down').bind("click",function(){
	if (gallery_step >= 1 ) {
	gallery_step-- ;
	$('#gallery_images').animate({ top:'+=245'}, 450);
	}
	});
	


	$img_screen_height = window.innerHeight - 120 - 110 ;
	
	$('#close-viewer').bind("click",function(){$('#viewer-container').fadeOut('slow');});
	$('#close-gallery').bind("click",function(){$('#gallery-container').fadeOut('slow');});
	
	/*$('#thumbScroller img').bind("click",function(){
												 
	var newImg = new Image();
	newImg.src = $(this).attr('src');
	var curHeight = newImg.height;
	var curWidth = newImg.width;
	var h = null ; 
	var w = null ;
	if (curHeight > curWidth ) { if (curHeight < $img_screen_height ) {h =  curHeight} else  h =  $img_screen_height ;}
	else {w = 470 ;}

	$('#viewer-container').css('visibility',' visible').fadeIn('slow');
	
	$('#viewer-container .image').css ('text-align','center');	
	$('#viewer-container .image').css ('line-height', $img_screen_height+'px');	
	$('#viewer-container .image').html('<img src="'+HTTP_PATH+'images/loader.gif" />');
	
		var image_link3 = $(this).attr('src').split('src=');							
		image_link3 = image_link3[1];	
		image_link3 = image_link3.split('&h=');
		image_link3 = image_link3 [0];
	
	$('#viewer-container .image').html('<img src="'+HTTP_PATH+'scripts/timthumb.php?src='+image_link3+'&amp;h='+h+'&amp;w='+w+'&amp;zc=1" class="feature-image"/>');
	
	
	$('#viewer-caption').html($(this).attr('alt'));
	
	});
	
	*/
	
	$('#gallery_images img').bind("click",function(){
	var image_link = $(this).attr('src').split('src=');							
	image_link = image_link[1];

	$('#gallery-container .large .image-scroller').html('<img src="'+HTTP_PATH+'scripts/timthumb.php?src='+image_link+'&amp;h=705&amp;w=468&amp;zc=1" class="feature-image"/><div class="preview"></div>');
	
	$('#gallery-caption').html($(this).attr('title')+' - '+$(this).attr('alt'));
	$('div.image-scroller').imageScroller();
	
	
	});
	
	

	$('#top-arrow').bind("click",function(){prevStory();});
	$('#down-arrow').bind("click",function(){nextStory();});
	
	$('.rest').bind("mouseover",function(){
	$(this).children().first().css('display','block').animate({opacity:0.75}, 350);
	$(this).children().first().next().css('display','block').animate({opacity:1}, 350);
	});
	
	$('.rest').bind("mouseleave",function(){
	$(this).children().first().animate({opacity:0},350);
	$(this).children().first().next().animate({opacity:0}, 350);
	});
	
	
	$('.category-block').bind("mouseover",function(){
	$(this).children().first().css('display','block').animate({opacity:0.80}, 1000);
	
	});
	
	$('.category-block').bind("mouseleave",function(){
	$(this).children().first().animate({opacity:0},500);
	});
	
	
		
		
	$('.big-featured ul li').bind("click",function(){
	$('.big-featured ul li').removeClass('activee') ; 
	$(this).addClass('activee') ; 
	var count = $(this).attr('count') ;
	var currentCount =  $('.big-featured .images img[class|="selected"]').attr('imgcount');

	$('.big-featured .images img[imgcount|="'+currentCount+'"]').removeClass('selected');
	$('.big-featured .images img[imgcount|="'+currentCount+'"]').addClass('hidden');
		$('.big-featured .images p[imgcount|="'+currentCount+'"]').removeClass('selected');
	$('.big-featured .images p[imgcount|="'+currentCount+'"]').addClass('hidden');
	
	$('.big-featured .images img[imgcount|="'+count+'"]').removeClass('hidden');
	$('.big-featured .images img[imgcount|="'+count+'"]').addClass('selected').animate({opacity:0.25}, 300).animate({opacity:1}, 300);;
		$('.big-featured .images p[imgcount|="'+count+'"]').removeClass('hidden');
	$('.big-featured .images p[imgcount|="'+count+'"]').addClass('selected').animate({opacity:0.25}, 300).animate({opacity:1}, 300);;
	
											   
	});
				
							
			});
