﻿/*************************************************


	Site Name   DEC
	File Name   page.js

	Create Date 2010/07/01
	Update Date 2010/12/24 [X'mas Eve]


*************************************************/

/**
 * jQuery Masonry
 */

$(function(){
	$.fn.loadBlocks = function(options){
		var $target = $(this);
		var setting = $.extend({
			json : '',
			childClass : 'child',
			callback : undefined
		}, options);
		$.ajax({
			dataType : 'json',
			url : setting.json,
			success : function(data){
				var html = '';
				var swfWidth;
				var swfHeight;
				for(var i = 0; i < data.blocks.length; i++){
					if(data.blocks[i].layoutType !== 'extraSmall' && data.blocks[i].layoutType !== 'extraSwf'){
						html += '<a href="' + data.blocks[i].url + '" class="' + setting.childClass + ' ' + data.blocks[i].layoutType + ' ' + data.blocks[i].soundType + '">';
						html += '<div class="mod_gridcontent_block_a_main">';
						if(data.blocks[i].fileType == 'img'){
							html += '<p><img src="' + data.blocks[i].fileSrc + '" alt="' + data.blocks[i].fileAlt + '" /></p>';
						}else if(data.blocks[i].fileType == 'swf'){
							html += '<p>';
							if(data.blocks[i].layoutType == 'small'){
								swfWidth = 130;
								swfHeight = 75;
							}else if(data.blocks[i].layoutType == 'midium'){
								swfWidth = 320;
								swfHeight = 75;
							}else if(data.blocks[i].layoutType == 'large'){
								swfWidth = 320;
								swfHeight = 206;
							};
							html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + swfWidth + '" height="' + swfHeight + '" id="mod_gridcontent_block_a_main_asset_' + i + '">';
							html += '<param name="movie" value="' + data.blocks[i].fileSrc + '" />';
							html += '<param name="bgcolor" value="#fff" />';
							html += '<param name="menu" value="false" />';
							html += '<param name="quality" value="high" />';
							html += '<param name="wmode" value="transparent" />';
							html += '<embed src="' + data.blocks[i].fileSrc + '" name="mod_gridcontent_block_a_main_asset_' + i + '" width="' + swfWidth + '" height="' + swfHeight + '" bgcolor="#fff" menu="false" quality="high" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
							html += '</object>';
							html += '</p>';
						};
						html += '<dl>';
						html += '<dt>' + data.blocks[i].categoryName + '</dt>';
						html += '<dd>' + data.blocks[i].categoryDesc + '</dd>';
						html += '</dl>';
						html += '</div>';
						html += '</a>';
					}else if(data.blocks[i].layoutType === 'extraSmall'){
						html += '<div class="' + setting.childClass + ' ' + data.blocks[i].layoutType + '">';
						html += '<p><img src="' + data.blocks[i].fileSrc + '" alt="' + data.blocks[i].fileAlt + '" class="js_pngfix" /></p>';
						html += '</div>';
					}else if(data.blocks[i].layoutType === 'extraSwf'){
						swfWidth = 180;
						swfHeight = 180;
						html += '<div class="' + setting.childClass + ' ' + data.blocks[i].layoutType + '">';
						html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + swfWidth + '" height="' + swfHeight + '" id="mod_gridcontent_block_a_main_asset_' + i + '">';
						html += '<param name="movie" value="' + data.blocks[i].fileSrc + '" />';
						html += '<param name="bgcolor" value="#fff" />';
						html += '<param name="menu" value="false" />';
						html += '<param name="quality" value="high" />';
						html += '<param name="wmode" value="transparent" />';
						html += '<embed src="' + data.blocks[i].fileSrc + '" name="mod_gridcontent_block_a_main_asset_' + i + '" width="' + swfWidth + '" height="' + swfHeight + '" bgcolor="#fff" menu="false" quality="high" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
						html += '</object>';
						html += '</div>';
					};
				};
				$target.html(html);
				$.commonFunc.pngfix('.js_pngfix');
				if($.browser.msie){
					$('.mod_gridcontent_block_a_main').click(function(){
						var lnk = $(this).parents('a').attr('href');
						location.href(lnk);
						return false;
					});
				};
				if(setting.callback) setting.callback();
			},
			error : function(){
				$target.html('<p>ニュース記事が見つかりません。</p>');
			}
		});
		return false;
	};
	$('div#mod_gridcontent').loadBlocks({
		json : SITE_ROOT_PATH + 'json/page.json',
		childClass : 'mod_gridcontent_block_a',
		callback : function(){
			var speed = 500;
			var columnWidth = 190;
			var minColCount = 5;
			var $container = $('div#mod_gridcontent');
			var $children = $('.mod_gridcontent_block_a');
			var $swf = $('#swf_se').get(0);
			
			// jQuery Masonry
			$container.masonry({
  				minColCount: 5,
				columnWidth : columnWidth,
				animate : true,
				animationOptions : {
					duration : speed,
					easing : 'easeInOutCirc',
					queue : false
				}
			},
				function(){
					var winWidth = $(window).width();
					var colCount = Math.max(Math.floor(winWidth/columnWidth), 1);
					if(colCount < minColCount) colCount = minColCount;
					$container.animate({
						width : colCount*columnWidth
					}, 500, 'easeInOutCirc',function(){
						if($children.css('display') != 'inline'){
							$children.fadeIn(speed);
						};
					});
				}
			);
			
			// Mouseenter Event
			$('.se_normal').mouseenter(function(){
				if($swf.callSe) $swf.callSe('over');
			});
			
			// Mouseenter Event
			$('.se_extra').mouseenter(function(){
				if($swf.callSe) $swf.callSe('click');
			});
			
			// Click Event
			$children.click(function(){
				if($swf.callSe) $swf.callSe('click');
			});
		}
	});
});
