/*
 * Ana Cargo General js
 *   @require Gnavi.js
 *   @require jquery 1.2.6 -
 *   Copyright All Nippon Airways Co., LTD. All rights reserved
 */

var AnaCargo = {
	pflag: false,
	// pull down initialize
	pdinit: function(){
		
		for(var i in Gnavi){
			var pdmenu = '<ul style="display:none;">';
			for(var j = 0; j < Gnavi[i].length; j++){
				pdmenu += (j+1 != Gnavi[i].length) ? '<li>' : '<li class="last">';
				pdmenu += '<a href="'+Gnavi[i][j].url+'" >'+Gnavi[i][j].title+'</a>'
				pdmenu += '</li>';
			}
			pdmenu += '</ul>';
			$('#gnav02 li.'+i+' a').after(pdmenu);
		}
		
		$('ul.gnav02 li').hover(function(){
			$(this).find('ul').show();
			if($(this).attr('id') != 'current'){
				var img = $('img', $(this)).attr('src');
				if(img && !img.match(/_on/)){
					$('img', $(this)).attr('src', $('img', $(this)).attr('src').replace(/\.(gif|png|jpg)$/i, '_on.$1'));
				}
			}
		}, function(){
			$(this).find('ul').hide();
			if($(this).attr('id') != 'current'){
				var img = $('img', $(this)).attr('src');
				if(img && img.match(/_on/)){
					$('img', $(this)).attr('src', $('img', $(this)).attr('src').replace(/_on\.(gif|png|jpg)$/i, '.$1'));
				}
			}
		});
	},
	rollover: {
		init: function(r){
			if(!r.size()) return;
			$('img.imgover', r).hover(function(){
				var img = $(this).attr('src');
				if(img && !img.match(/_on/)){
					$(this).attr('src', img.replace(/\.(gif|png|jpg)$/, '_on.$1'));
				}
			}, 
			function(){
				var img = $(this).attr('src');
				if(img && img.match(/_on/)){
					$(this).attr('src', img.replace(/_on\.(gif|png|jpg)$/, '.$1'));
				}
			});
		}
	},
	/*
	 * table span layout for service category 
	 * 
	 */
	servicetable: function(){
		
		 //top padding size setting
		 var stpadsize = 5;
		 
		 $('#main table .pos').each(function(){
			var picheight = $(this).height();
			var picpt = $(this).css('paddingTop');
			var picpb = $(this).css('paddingBottom');
			
			picheight += Number(picpt.replace('px', ''));
			picheight += Number(picpb.replace('px', ''));
			
			var sizeheight = $(this).find('p').height();
			var sizetop = (-1)*((picheight - sizeheight)/2 - stpadsize + 2);
			$(this).find('span').css('top', sizetop);
		});
	},
	init: function(){
		$(function(){
			AnaCargo.pdinit();
			AnaCargo.rollover.init($('body'));
			if($('.pos').size() > 0) AnaCargo.servicetable();
		});
	}
};

AnaCargo.init();






/*
* Service Tab
* 
*/
$(function() {
	
	$('.tab02 a').click(function(){
		var parenttab = $(this).parent().parent();
		var id = parenttab.attr('id');
		$('.'+id+'.tbl01').hide();
		$('.'+id+'.tbl02').show();
		
		//switch rollover
		$('img', $(this)).unbind();
		var img = $('.tab01 a img', parenttab).attr('src');
		if(img.match(/_on/)){
			img = img.replace(/([^_]+)_on.(gif|jpg|png)/, '$1.$2');
		}
		$('.tab01 a img', parenttab).attr('src', img);
		AnaCargo.rollover.init($('.tab01 a', parenttab));
		
		return false;
	});
	$('.tab01 a').click(function(){
		var parenttab = $(this).parent().parent();
		var id = parenttab.attr('id');
		$('.'+id+'.tbl02').hide();
		$('.'+id+'.tbl01').show();
		
		//switch rollover
		$('img', $(this)).unbind();
		var img = $('.tab02 a img', parenttab).attr('src');
		if(img.match(/_on/)){
			img = img.replace(/([^_]+)_on.(gif|jpg|png)/, '$1.$2');
		}
		$('.tab02 a img', parenttab).attr('src', img);
		AnaCargo.rollover.init($('.tab02 a', parenttab));
	
	return false;
	});
	
	//tab01 
	if($('.tab01 a').size() > 0){
		var img = $('.tab01 a img').attr('src');
		if(!img.match(/_on/)){
			img = img.replace(/([^\.]+).(gif|jpg|png)/, '$1_on.$2');
		}
		$('.tab01 a img').unbind().attr('src', img);
	}
	
});


/*
* tab for service category 
* 
*/




//************* popup *************

function openWindow(theURL, width, height, features, winName) { //v2.0
	if(typeof(width) == "undefined" || width == 0){
		width = 500;
	}
	
	if(typeof(height) == "undefined" || height == 0){
		height = 500;
	}
	
	if(typeof(features) == "undefined" || features == ""){
		features = "status=yes,menubar=no,scrollbars=yes,resizable=yes";
	}
	
	features = features + ', width = ' + width + ', height = ' + height;
	
  window.open(theURL,winName,features);
}









