/*
* @version : 4.4
* @update : 2010-03-29
*/
// id:0, code:'P000061', type:'productcode', page:'promotion'
function swfAddCart( code, type ) {

	if ( $("a#btHomeLogout, a#Pizza_mnLogout, a#mnLogout").length > 0 ) {

		if ( $("div#modelSelectPizza").length > 0 ) {$("div#modelSelectPizza").remove();}

		if (type==undefined) type = 'productcode';
		var page = 'home';
		if (type=="combo") page = "promotion";


		$.ajax({
			url: "api/popup.php",
			data: "action=chk_add_cart&code="+code+"&type="+type,
			type: "get",
			cache: false,
			dataType: "html",
			complete: function (result) {
				//document.write ();
				//alert(result.responseText);
				if ( parseInt(result.responseText) == 1 ) {

					if (type == 'pizza') {
						bindPizzaCrustNormal(id);
					} else if (type=='combo') {
						//alert('COMBO');

						bindCombo(code, page);

					} else {
						//alert('test');
						addCartMenu( code);
					}

				} else if ( parseInt(result.responseText) == 2 ) {
					bindDisplayMessage("ขออภัยขณะนี้เป็นเวลาปิดให้บริการของร้านค่ะ", "");
					// action=add_cart_option&id=117
				} else if ( parseInt(result.responseText) == 3 ) {
					bindDisplayMessage("ขออภัยที่อยู่จัดส่งของท่านอยู่นอกพื้นที่ให้บริการ", "กรุณา เปลี่ยน/เพิ่ม ที่อยู่จัดส่งค่ะ");
					// action=add_cart_option&id=117
				}

			},
			error: function(result) {
				//alert(result.statusText);
			}
		});
	} else {
		bindLogin();
	}
}


$(function(){

	if ($("div#swfHome").length > 0 ) {
		$("div#swfHome").flash({
				src: "flash/home.swf",
				width: 880,
				height: 350,
				wmode: "transparent", menu: "false",
				flashvars: { xml: "xml/home_banner.xml" }
		});
	}

	if ($("div#swfIPod").length > 0 ) {
		$("div#swfIPod").flash({
				src: "flash/home-ipod_mini.swf",
				width: 205,
				height: 50,
				wmode: "transparent", menu: "false",
				flashvars: { xml: "xml/home_banner.xml" }
		});
	}


	/** footer tooltip **/
	/*$("div.HotValue").each(function(){
		var meta = $.metadata.get(this);
		//var style_name = ( $(this).hasClass("ItemRight") ? 'menu_right' : 'menu' );

		$(this).qtip({
			content: {
				url: 'api/tooltip-home.php',
				data: { type: 'menu', id: meta.id },
				method: 'get'
			},
			position: {
				corner: {
					target: 'topMiddle', // Position the tooltip above the link
					tooltip: 'bottomMiddle'
				},
				adjust: { x: meta.pos.left, y: meta.pos.top }
			},
			// Effects
			show: {
				delay: 100
			},
			hide: {
				delay: 0, fixed: true
			},
			style: 'home_hotvalue',
			api: {
				onRender: function() {
					//alert(meta.id)
					/*var meta = $.metadata.get(this);
					alert( $(this).attr('id'))
					var self = this;
					console.log(self);* /
				}
			}
		});
	});*/


	/*$.tools.addTipEffect("slidedown",

		// opening animation
		function() {
			var opacity = this.getConf().opacity;
			this.getTip().css({opacity:0}).animate({top: '+=15', opacity:opacity}, 300).show();
		},

		// closing animation
		function() {
			this.getTip().animate({top: '+=15', opacity:0}, 300,
				function() {
				$(this).hide().animate({top: '+=30'}, 0);
			});
		}

	);*/

	// function หรือตัวดำเนินการเรียก Script ของ jquery ออกมาใช้งาน ซึ่่งตัวนี้จะต้องถูกเรียกมาใช้เสมอ

	/*$("#Order1").tooltip({effect: 'slidedown'});
	$("#Order2").tooltip({effect: 'slidedown'});
	$("#Order3").tooltip({effect: 'slidedown'});
	$("#Order4").tooltip({effect: 'slidedown'});*/


	if ($("div.flash_detail").length > 0 ) {
		$("div.flash_detail").each(function() {
			wmode = ( $(this).metadata().flashvars.wmode != undefined ? $(this).metadata().flashvars.wmode :  "opaque" ); // opaque, transparent;
			$( this ).flash({
					src: $(this).metadata().flash,
					width: $(this).metadata().width,
					height: $(this).metadata().height,
					wmode: wmode, menu: "false",
					flashvars: { title_th: $(this).metadata().flashvars.title_th , title_en: $(this).metadata().flashvars.title_en }
				}, { version: 8 }
			);
		});
	}

	if ($("div.flash_price").length > 0 ) {
		$("div.flash_price").each(function() {
			wmode = ( $(this).metadata().flashvars.wmode != undefined ? $(this).metadata().flashvars.wmode :  "opaque" ); // opaque, transparent;
			$( this ).flash({
					src: $(this).metadata().flash,
					width: $(this).metadata().width,
					height: $(this).metadata().height,
					wmode: wmode, menu: "false",
					flashvars: { title: $(this).metadata().flashvars.title }
				}, { version: 8 }
			);
		});
	}


	//$(document).pngFix();
});