/*
Description: HOME GRID
Author: wpworks.net
Author URI: http://wpworks.net
*/



WPW.HomeGrid = function($){
	var $ = jQuery;
	var main = this;
	
	var blocks = [];
	
	var main_node = $('#home-grid');
	var ratio = 0.86;
	
	var block_width = 0;
	var block_height = 0;

	var current_max_height = 0;

	var gridBlock = function(block){
		var w = block.attr('data-size').split("*")[0]; 
		var h = block.attr('data-size').split("*")[1];
		 
		var px = block.attr('data-position').split("*")[0]; 
		var py = block.attr('data-position').split("*")[1];
		
		this.resize = function(){
			block.css('width', w * block_width);
			block.css('height', h * block_width);
			
			block.css('top', py * block_width);
			block.css('left', px * block_width);
			
			if(h * block_width + py * block_width > current_max_height){
				current_max_height = h * block_width + py * block_width;
			} 
			
		}
		
		blocks.push(this);
	} 



	$('.home-grid-block', main_node).each(function(){
		var block = $(this);
		var block_object = new gridBlock(block);
	});

	$('.home-grid-block-sub-title', main_node).each(function(){
		if(!$(this).hasClass(WPW.site_language)){
			$(this).remove();
		}
	});



    var refreshSize = function(){
    	current_max_height = 0;
    	block_width = parseInt(WPW.cW/4);
    	block_height = parseInt(block_width * ratio);
    	
    	for(var i = 0; i < blocks.length; i++){
    		blocks[i].resize();
    	}
    	if($('#intro-page').length == 0){
	    	main_node.css('height', current_max_height);
	    	$('body').css('height', current_max_height);	
    	}
    }  
	
    WPW.body.bind('RefreshSize', function(){refreshSize();});
    refreshSize();


    
    
	var resizeMedium = function(mitem){
			WPW.ResizeImage({
				img:mitem, 
				t_w:function(){return gallery_content_width;},
				t_h:function(){return WPW.medium_gallery_height;},
				scale_mode:"fit_h",
				position_mode:"cc",
				force_fit: true,
				canvas_check: false
			}); 
		}    
}


WPW.Core.register("HomeGrid");

