var topImginit = function(){
	
	var positionFunc = function(){
		var windowW = $("html").width();
		var windowH = $("html").height() - 160;
		
		/* Recruit—p */
		if ( windowH < 530 ){
			windowH = 530;
		}
		
		
		var mainImgW = windowH * 1500 / 900;
		var mainImgH = windowW * 900 / 1500;
		
		if( windowW > mainImgW ){
			mainImgW = 100 + '%';
		}else{
			mainImgH = mainImgW * 900 / 1500;
		}
		$('#topImage').css({width:mainImgW, height:mainImgH});
		$('#topImageContents').css({height:windowH});
		
	};
	positionFunc();
	
	$(window).resize(function() {
		 positionFunc();
	 });
	
/*setting
*/
	var itemObj = [];
	var itemNumber = "";
	var itemCategory = "";
	var itemImg = "";
	
	/*XML
*/
	$.ajax({
		   url: 'newRelease.xml',
		   dataType: 'xml',
		   cache: false,
		   success: function(xml){
			   itemObjSet(xml);
			   itemImgSet();
		   }
	});
 
	var itemObjSet = function(xml){
		var count = 0;
		$('item',xml).each(function(){
			itemObj[count] = {
				dir : $("dir",this).text(),
				file : $("file",this).text(),
				name : $("name",this).text(),
				color : $("color",this).text(),
				size : $("size",this).text(),
				price : $("price",this).text(),
				delivery : $("delivery",this).text()
			};
			count++;
		});
	};
/*Thumb Set
*/
	var itemImgSet = function(){
		itemImg = '';
		for(var i = 0; i < itemObj.length; i++) {
			var itemAlt = "'" + itemObj[i].name + " [" + itemObj[i].color + "]'";
			itemImg = itemImg + "<li><img src="+itemObj[i].dir+"thumb/"+itemObj[i].file+" alt="+itemAlt+" width=64 height=96 /></li>";
		}
		
		$("#newReleaseItem").html(itemImg);
		carouselFunc();
		clickFunc();
	};

/*click
*/
/*popup
*/
	var clickFunc = function(){
		$('#newReleaseItem img').click(function(){
			$('#popImg').dialog('close');
			var i = $('#newReleaseItem img').index(this);
			var itemAlt = "'" + itemObj[i].name + " [" + itemObj[i].color + "]'";
			var popupTitle = $(this).attr('alt');
			var popImg = "<img src="+itemObj[i].dir+"photo/"+itemObj[i].file+" alt="+itemAlt+" width=350 height=525 >";
			var popupCap = "<p><span>NAME</span><br />"+itemObj[i].name+"<br /><span>COLOR</span><br />"+itemObj[i].color+"<br /><span>SIZE</span><br />"+itemObj[i].size+"<br /><span>PRICE</span><br />"+itemObj[i].price+"yen<br /><span>DELIVERY</span><br />"+itemObj[i].delivery+"</p>"
			$('#popImg').html(popImg+popupCap)
			.dialog('option', 'title', popupTitle)
			.dialog('open');
		});
	};
	
	
	$('#popImg').dialog({
		autoOpen: false,
		position: ["center", "center"],
		width: 710,
		resizable: false,
		show: 'fade',
		dialogClass: 'popDialog',
		bgiframe: true // for IE6
	});


/*jcarousel
*/
	var carouselFunc = function(){
		$('#newReleaseItem').jcarousel({
				scroll : 9
		});
	};
	
};

/*fadeEffect
*/
(function($) {
$.effects.fade = function(o) {
        return this.queue(function() {
                // Create element
                var el = $(this);

                // Set options
                var speed = o.options.speed || 200;
                var mode = o.options.mode || 'show'; // Set Mode

                // Animate
                if (mode == 'show') {
                        el.fadeIn(speed);
                } else {
                        el.fadeOut(speed);
                };
                el.queue('fx', function() { el.dequeue(); });
                el.dequeue();
        });
};
})(jQuery); 

$(function(){
		 topImginit();
});
