/**
 * @version  1.00
 * @updated  2010/04/01
 */



(function ($) {
	var server = {
		init: function() {
			server.load();
		},

		load: function () {
			$.ajax({
				url     : '/data/shared/xml/plans.xml',
				type    : 'GET',
				dataType: 'xml',
				cache   : false,
				success : function (r) {
					server.output($(r).children());
				}
			});
		},
		
		
		output: function (data) {
			
			$(data).children().each( function () {
			
				if ($(this).get(0).tagName == 'package') {
				
					$(this).children().each( function () {
						
						var kw            = $(this).attr('keyword');
						var url           = $(this).find('url').text();
						var icon          = $(this).find('img_icon').attr('src');
						var copy          = $(this).find('img_copy').attr('src');
						var copy_alt      = $(this).find('img_copy').attr('alt');
						var title         = $(this).find('title').text();
						var spec          = $(this).find('spec').text();
						var txt           = $(this).find('txt').text();
						if (txt.length > 76) {
							var str  = txt.substr(0,75);
							var txt  = str + '…';
						}
						
						if (kw.indexOf('kw2',0) != -1) {
							$('div#showcase div.in').append([
								'<div class="elm pack thumb">' + '\n',
								(($(this).find('badge').text() != '') ? '<p class="sh-badge"><img class="png" src="/data/shared/img/badge_' + $(this).find('badge').text() + '.png" alt="" width="60" height="64" /></p>' : '') + '\n',
								'<a href="' + url + '"></a>' + '\n',
								'<p class="sh-img"><em><img src="' + icon + '" alt="" width="60" height="50" /></em><img src="' + copy + '" alt="' + copy_alt + '" width="225" height="50" /></p>' + '\n',
								'<h3><em>' + title + '</em>' + spec + '</h3>' + '\n',
								'</div>' + '\n'
							].join(''));
						}

					});
				}
				
			});
			
			common.showcase();
			
		}
	}



	$(function () {
		server.init();
	});
	
})($);
