$(document).ready(function(){
	$('#container').masonry({ //Call masonry plugin once loaded
		itemSelector : '.item',
		columnWidth : 240,
		isAnimated: !Modernizr.csstransitions 
    }); 
 });

$(window).load(function(){ /*** Fix IE Stuff ***/
	$(".largeport").css('visibility','visible').hide().fadeIn('slow', function () {   
		$(".videocontainer").delay(700).css("background", "none");
	});
});

 

var switcher = 'a0'; // Set a variable to say that no boxes are open

function changer(letter, postid){
	document.getElementById(switcher).height ='145'; //change height of open image (before masonry)
	document.getElementById(switcher).width ='220';//change width of open image (before masonry)
	document.getElementById('itemdiv'+switcher).style.width ='220px'; //Change width of open container (before masonry)
	$('#arrow' + switcher).fadeOut('fast', function(){ //fade out open content container
		document.getElementById('itemdiv'+letter).style.width ='460px'; //Change width of clicked on container after fade out
		document.getElementById('arrow'+letter).style.display ='inline'; //flash the clicked-on div width and hieght for masonry
		$('#arrow' + letter).height(310);
		$('#container').masonry({ itemSelector : '.item', columnWidth : 240, isAnimated: !Modernizr.csstransitions}); //run masonry
		document.getElementById('arrow'+letter).style.display ='none'; //display none
		$('#arrow' + letter).delay(600).fadeIn('slow')  // fade in new div after .6 seconds
	});
	switcher = letter;  //Let the function know a box is open
	window.setTimeout(function() {$('html,body').animate({scrollTop: $(postid).offset().top}, 1000, 'easeOutCubic');}, 1000); //Scroll window to the div box
}
			
function xout(letter, postid) {
	changer('a0','#itemdiva0', '310');
}

$(document).ready(function() {
	onComplete = function() {
		alert('doing it');
	}         
	$('.xout a').click(function(){changer('a0','#itemdiva0', '310'); return false;});
	var boxCount = $('#container').find('.item').size(), //find out what this is
	
	counter = 0,
	onComplete1 = function() {
		alert(boxCount);
	    if (counter < boxCount) { 
			counter++;
		} else {
	    	window.setTimeout(function() {$('html,body').animate({scrollTop: $(postid).offset().top}, 1000, 'easeOutCubic');}, 500);
	        alert("Finished?");
	        counter = 0;
		}
	}
	$(window).scroll(function () {					   
	 	var y_scroll_pos = window.pageYOffset;
	    var scroll_pos_test = 50;             // set to whatever you want it to be
	    if(y_scroll_pos > scroll_pos_test) {
	        $('.top').fadeIn(1000);
	        $('.iphone').children('.top').css('display', 'none !important');
		} else {
			$('.top').fadeOut(500);
		}
	});
	$('.top').click(function(){
		$('html, body').animate({scrollTop:0}, 500, 'easeOutCubic');
		return false;
	});

	$('.postphoto img, .hover img, .lightboxhover img').hover( function() {
		$(this).stop().animate({opacity : 0.2}, 500);
	}, function() {
		$(this).stop().animate({opacity : 1}, 500);
	});
	
	$('a.mail').each(function(i) {
        var text = $(this).text();
        var address = text.replace(" [zavinac] ", "@");
        $(this).attr('href', 'mailto:' + address);
        $(this).text(address);
    });
    
    $('a.lightbox').lightBox({
		imageBlank: '/templates/miumedia_v3/data/images/lightbox-blank.gif',
		imageLoading: '/templates/miumedia_v3/data/images/lightbox-ico-loading.gif',
		imageBtnClose: '/templates/miumedia_v3/data/images/lightbox-btn-close.gif',
		imageBtnPrev: '/templates/miumedia_v3/data/images/lightbox-btn-prev.gif',
		imageBtnNext: '/templates/miumedia_v3/data/images/lightbox-btn-next.gif',
		txtImage: 'Fotografie',
		txtOf: 'z'
   });
});       
