var debug = 0;//parseInt(document.location.href.indexOf('1') > 0);
var _img = 'http://i.fast.trevicards.com/i/';
var _mp3 = 'http://i.fast.trevicards.com/i/mp3/';
if (document.location.host == "trevicards" + ".klik") {
	debug = 1;
} else if (document.location.host == "fast." + "trevicards" + ".wlad") {
	debug = 1;
	_img = 'http://i.trevicards.wlad/i/';
} else if (document.location.host == "tc" + ".com") {
	debug = 1;
}
fc = 0;
(new Image()).src=_img +"i/suka.gif";
$(document).ready(function() {
	if (debug) {
		$("#potatoCont").css( {
			display : "none"
		});
		$("#body").css( {
			top : "32px"
		});
	}

	Main.init();
	$.historyInit(historyCall);

	$("#logo").click(function() {
		document.location = "http://trevimedia.net";
	});

	$(document).keypress(function(e) {
		if (e.keyCode == 27 && !$(".vk_overlay").hasClass('vk_h')) {
			VK_container = null;
			VK_hide();
			return false;
		}
	}).mousedown(function() {
		if ($("#colorpicker").length && !$("#colorpicker").hasClass('vk_h'))
			tm_colorPicker = setTimeout(colorPicker_hide, 200);
	});
	$("#cover").dropdown( {
		onchange : function(val, el) {
			$("#cover").find("dt a").css( {
				backgroundImage : el.style.backgroundImage
			});
			Card.Cover.Set(el.style.backgroundImage.replace(/.+_([a-z]+)\.gif.+/, "$1"));
		}
	});

	$("#rcat").dropdown( {
		onchange : function(val) {
		$('#rcat2 dt span').html('Select Category');
		Ribbon.chcategory(val);
		/*
			if (fc)
			{
				Ribbon.chcategory(val);
			}
			else
			{
				fc = 1;
			}
			*/
		}
	});
	
	$("#rcat2").dropdown( {
		onchange : function(val) {
		$("#text").removeClass('calendar');
			$('#rcat dt span').html('Select Category');
				if(parseInt($('#menu').attr('rel')) !=9)
					Menu.init(9);
                	Ribbon.chcategory(val);
			}
	});
	
	$("#y_year, #m_year").dropdown( {
		onchange : function(val) {
			Calendar.y = val;
			Calendar.UpdateImage();
		}
	});
	$("#m_month").dropdown( {
		onchange : function(val) {
			Calendar.m = val;
			Calendar.UpdateImage();
		}
	}).removeAttr("style");
	$("#c_layout").dropdown( {
		onchange : function(val) {
			Calendar.layout = val;
			Calendar.UpdateImage();
		}
	});
	$("#c_color").dropdown( {
		onchange : function(val) {
			Calendar.color = val;
			Calendar.UpdateImage();
		}
	});
	$("#dd_music").dropdown( {
		onchange : function(val) {
			if(Card.flag==true)
			return;
			if (val) {
				$id("swfsnd").playSound(_mp3 + val);
			} else {
				$id("swfsnd").stopSound();
			}
			Card.SetMusic(val);
		}
	});
	$("#text_block_cont").jScrollPane( {
		showArrows : true
	});
});

function getCookie(name)
    {
      //  alert(document.cookie);
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
        
	return(setStr);
    }

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

checkCard = function() {

	if ($id('swfpageflip') && typeof ($id('swfpageflip').getCardInfo) == "function") {
		if (!Card.fl_cardInit) {
			loadSWF("puppet", "man_small.swf?" + Math.random(), 189, 930, "swfpuppet");
			Card.fl_cardInit = true;
			Card.Init();
			Ribbon.init();
			TextControls.Init();
			setTimeout("rotate()", 10000);
			setInterval("rotate();", 25000);
			$("#mli89").click();
		}
		var state = $id('swfpageflip').getCardInfo().toString();
		Card.flipping = state.substr(0, 1);
		Card.page = state.substr(1, 1);
		Card.Update();
	}
};

function historyCall(hash, sl) {
	if (hash) {
		if (!sl) {
			var data = Main.historyStock[hash.replace('cat', '')];

			if (data[0] == 'sub') {
				Menu.init(0);
			} else {
				Ribbon.chcategory(data[0], data[1], data[2], 1);
			}
		}

		return false;

	} else {
		// Fp
		Menu.init(0);
	}
};

var Main = {

	fcsid : null,

	historyStock : [],
	historyStockI : 0,

	set_sid : function(sid) {
		if ($.cookie("OWN_SID")) {
			OrderCard.sid = $.cookie("OWN_SID");
		} else {
			var date = new Date();
			date.setTime(date.getTime() + (2 * 60 * 60 * 1000));
			$.cookie("OWN_SID", OrderCard.sid = sid, {
				path : '/',
				expires : date
			});
		}
	},

	restoreSession : function() {
		$.pget("/proc/render/restore_session", {
			sid : $.cookie("FCSID") && $.cookie("FCSID").length == 32 ? $.cookie("FCSID") : "12345678901234567890123456789012"
		}, function(d) {
			try {
				eval(d);
			} catch (e) {
				return;
			}
			if (typeof (Card.Last) == "object") {

				Main.fcsid = Card.Last["fcsid"];

				Main.loadAuthBlock();
				$("#btnPreview").attr("href", "/preview/" + Main.fcsid);

				$.fn.media.defaults.flashVersion = "10";
				$.fn.media.defaults.bgColor = "";
				loadSWF("pageflip", "pageflip_loader.swf?fcsid=" + Main.fcsid + "&_r=" + Math.random(), 671, 533);
			}
		});
	},

	loadAuthBlock : function() {
		// Load Auth Block
		$.pget('/proc/login/load_form?fcsid=' + Main.fcsid, null, function(data) {

			if (data) {
				$('#authCont').html(data);
				Registration.init();
			}
		});
	},

	historyAdd : function(cid, id, item_id) {
		Main.historyStock[Main.historyStockI] = [
				cid,
				id,
				item_id
		];
		hurl = 'cat' + Main.historyStockI;

		$.historyLoad(hurl, true);

		Main.historyStockI++;
	},

	init : function() {
		Main.restoreSession();
		$.fn.media.defaults.flashVersion = "10";
		$.fn.media.defaults.bgColor = "";
		
		Menu.init(0);

		loadSWF("logo", "logo.swf?" + Math.random(), 300, 97);
		loadSWF("snd", "snd.swf?" + Math.random(), 64, 25);

		if (debug) {
			loadSWF("card", "card_vector.swf", 510, 480, "swfcard");
			Interface.bodyWentBottom = 1;
			tm_checkCard = setInterval("checkCard()", 50);
		}

		$("#drag").draggable( {
			helper : "clone",
			start : function(event) {

			}
		});

	}
};

var Ribbon = 
{
	blocked : false,
	thWidth : 86,
	thHeight : 126,
	ids : [],
	otimer : null,

	scrollOn : 3,
	leftIndex : 1,
	rightIndex : 8,
	cid : 89,

	init : function() 
	{

		Ribbon.makeDraggable();
		$("#rArrLeft, #rArrRight").mouseover(function() {
			$(this).addClass("hover");
		}).mouseout(function() {
			$(this).removeClass("hover");
		});
		$("#rArrRight").click(function() {
			Ribbon.left();
		});
		$("#rArrLeft").click(function() {
			Ribbon.right();
		});

		Ribbon.cid = $.cookie("ribbon_cid");
	},

	chcategory : function(cid, id, this_id, nohis) {
//		debugger;
		if (id) {
			$item = $("item[id=" + this_id + "]", Menu.xml);

			// --
			cid = cid ? cid : $item.attr('tid');

			//debugger;
			
			cid != 308 ? Interface.movePuppet(id, this_id) : false;
			
			

			name = $item.attr('name');
			if((parseInt($item.attr('pid')) == 9) || ($item.attr('tid') == 89))
			{
				$("#text").removeClass('calendar');
				$('#rcat dt span').html('Select Category');
				$('#rcat2 dt span').html(name);
			} else {
				$('#rcat dt span').html(name);
				$('#rcat2 dt span').html('Select Category');
			}
			
			// --
		} else {

			$item = $("item[tid=" + cid + "]", Menu.xml);
			this_id = $item.attr('id');

			id = $item.attr('m');

			Interface.movePuppet(id, this_id);
		}
		
		if($item.length >1)
			$item = $($item[1]);
		var name = $item.attr('name');
		var alias_path = $item.attr('alias_path');
		
		
		var pid = $item.attr('pid');
		
		if(cid == 89)
			Menu.init(0);
		else {
		
		if((pid == undefined) && parseInt($('#menu').attr('rel')) != -1) {
			Menu.init(0);
		}
		
		if((pid == 1) && (parseInt($('#menu').attr('rel')) !=1) ) {
			Menu.init(1);
		}
		}
		/*
		if(pid == 1 && parseInt($('#menu').attr('rel')) !=1 ) {
			Menu.init(1);
		} else 
		*/
		
		/*
		else {
			if (this_id > 100) {
				Menu.menuid == 0 ? Menu.init(1) : false;
			} else {
				Menu.menuid == 1 ? Menu.init(0) : false;
			}
		}
		*/
		if(pid)
			$('#menu').attr('rel', pid);
		else
			$('#menu').attr('rel', -1);
	

		if (!nohis) {
			Main.historyAdd(cid, id, this_id);
		}

		Ribbon.cid = cid;
		$.cookie("ribbon_cid", cid, {
			path : '/',
			expires : 20
		});

		Ribbon.leftIndex = 1;
		Ribbon.rightIndex = 8;
		Ribbon.thWidth = 86;
		Ribbon.ids = [];
		Ribbon.otimer = null;
	
		$("#ribbon #mask ul").css( {
			left : 0
		});

		if (!debug) {
			try {
				pageTracker._trackPageview("/" + alias_path + ".html");
			} catch (e) {
			}
		}

		$.pget("/proc/ribbon/load_list", {
			cid : Ribbon.cid
		}, function(d) {
			// alert(d);
				$("#ribbon #mask ul").html(d);
				Ribbon.init();
			});

		$.pget("/proc/render/get_content", {
			cid : "c" + Ribbon.cid
		}, function(d) {
			$("#text_block_cont").html(d).jScrollPane( {
				showArrows : true
			});
		});

	},

	left : function() {

		if (Ribbon.blocked)
			return;
		Ribbon.blocked = true;
		var start = $("#ribbon #mask li").length;
		if (start == Ribbon.rightIndex) {
			$.pget("/proc/ribbon/load_list", {
				cid : Ribbon.cid,
				start : start
			}, function(d) {
				if (/<li/.test(d)) {

					$("#mask").css( {
						overflow : "hidden"
					});

					var left = parseInt($("#ribbon #mask ul").css("left"));
					var items = d.match(/<li/gi).length;
					if (items > Ribbon.scrollOn) {
						var arr = d.split("<li");
						delete arr[Ribbon.scrollOn + 1];
						d = arr.join("<li").replace(/<li$/, '');
						items--;
					} else {

					}

					Ribbon.rightIndex = start + items;
					$("#ribbon #mask ul").append(d).animate( {
						left : -(Ribbon.rightIndex - 8) * 89 - 1
					}, "slow", "swing", function() {
						Ribbon.makeDraggable();
						$("#ribbon #mask li:lt(" + (Ribbon.rightIndex - 8) + ")").css( {
							display : "none"
						});
						$("#mask").css( {
							overflow : "visible"
						});
						Ribbon.blocked = false;
					});
				} else {
					Ribbon.blocked = false;
				}
			});
		} else {
			$("#mask").css( {
				overflow : "hidden"
			});
			var left = parseInt($("#ribbon #mask ul").css("left"));
			Ribbon.rightIndex += Ribbon.scrollOn;
			if (Ribbon.rightIndex > $("#ribbon #mask li").length)
				Ribbon.rightIndex = $("#ribbon #mask li").length;
			$("#ribbon #mask li:lt(" + (Ribbon.rightIndex) + ")").css( {
				display : "block"
			});
			$("#ribbon #mask ul").animate( {
				left : -(Ribbon.rightIndex - 8) * 89 - 1
			}, "slow", "swing", function() {

				$("#ribbon #mask li:lt(" + (Ribbon.rightIndex - 8) + ")").css( {
					display : "none"
				});
				$("#mask").css( {
					overflow : "visible"
				});
				Ribbon.blocked = false;
			});
		}
	},
	right : function() {
		if (Ribbon.blocked)
			return;
		Ribbon.blocked = true;
		$("#mask").css( {
			overflow : "hidden"
		});
		var left = parseInt($("#ribbon #mask ul").css("left"));
		left = left + 89 * Ribbon.scrollOn + 1;
		if (left > 1)
			left = 1;
		Ribbon.rightIndex -= Ribbon.scrollOn;
		if (Ribbon.rightIndex < 8)
			Ribbon.rightIndex = 8;
		$("#ribbon #mask li:lt(" + (Ribbon.rightIndex) + ")").css( {
			display : "block"
		});
		$("#ribbon #mask ul").animate( {
			left : left
		}, "slow", "swing", function() {

			$("#ribbon #mask li:gt(" + (Ribbon.rightIndex - 1) + ")").css( {
				display : "none"
			});
			$("#ribbon #mask li:lt(" + (Ribbon.rightIndex - 8) + ")").css( {
				display : "none"
			});
			$("#mask").css( {
				overflow : "visible"
			});
			Ribbon.blocked = false;
		});

	},
	removeOpacity : function() {
		if (Card.TitleImage.ID) {
			$("#p1_titleImage").animate( {
				opacity : 0
			}, "fast");
		} else {
			if(!Card.Video.Name) {
				$("#p1_titleImage").animate( {
					opacity : 1
				}, "fast");
			}
		}
		$("#ribbon #mask li img[class!=img_dragging]").css( {
			opacity : 1
		});
	},
	makeDraggable : function() 
	{
		$img = $('#mask li img').not(".ui-draggable");

		if (true || this.cid != 89)
		{
			$img.draggable( {
				helper : "clone",
				start : function() {
					$(this).addClass("img_dragging");
				},
				stop : function() {
					$(this).removeClass("img_dragging").mouseout();
				}
			})
		}

		$img.click(function () {
			$("#p1_titleImage").animate( {
				opacity : 0
			}, "fast");
			if (this.src.indexOf('animate') !== -1) {
				$id('swfpageflip').stop_video();
				flvname = this.src.match(/\/([^/]+)\.(jpg|gif|png)/)[1] + '.flv';
				flvname = flvname.replace(/[ ']+/g, '_').replace(/\%20/g, '_').replace(/\%27/g, '_');
				Card.Video.Set(flvname);
			} else if($("#text:first").hasClass('calendar')){
				Calendar.SetImage(this.id.replace("img", ""));

			} else {
				if(parseInt(Card.page) == 0) {
					Card.TitleImage.ID = this.id.replace("img", "");
					Card.Video.Name = null;
					Card.flag=false;
					$.pget('/proc/render/set_title_image', {
						id : Card.TitleImage.ID
					}, function(d) {
						$id('swfpageflip').render_title_image();
							
					});
					

				} else {
					alert("Please, drag`n`drop image\nto card");
					return false;
				}
			}
			Card.SetCost();
		}).mouseover(function() {
			clearTimeout(Ribbon.otimer);
			$("#p1_titleImage").stop().animate( {
				opacity : 0.5
			}, "fast");
			Ribbon.ids[$(this).parent().attr("id")] = null;
			if (!$.browser.msie) {
				$("#ribbon #mask li img").css( {
					opacity : 0.8
				});
				$(this).css( {
					opacity : 1
				});
			}
			$(this).parent().css( {
				zIndex : 2
			});
			$(this).stop().css( {
				zIndex : 2
			}).animate( {
				left : -10,
				width : Ribbon.thWidth + 20,
				top : -10,
				height : Ribbon.thHeight + 20
			}, "fast", function() {
				clearTimeout(Ribbon.otimer);
			}).mouseout(function() {
				if ($(this).hasClass("img_dragging"))
					return;
				$(this).parent().css( {
					zIndex : 1
				});
				$(this).stop().animate( {
					left : 0,
					width : Ribbon.thWidth,
					top : 0,
					height : Ribbon.thHeight
				}, "fast", function() {
					delete Ribbon.ids[$(this).parent().attr("id")];
					if (Ribbon.ids.length == 0) {
						clearTimeout(Ribbon.otimer);
						Ribbon.otimer = setTimeout(Ribbon.removeOpacity, 300);
					}
				});
			});
		}).mouseout(function(){
			$("#p1_titleImage").stop().animate( {
				opacity : 0
			}, "fast");
		});
	}
};

var Interface = {

	paths : [
			"one",
			"1-2",
			"2-4",
			"4-3",
			"3-5",
			"5-3",
			"3-4",
			"4-1",
			"1-5"
	],
	menuPoints : [
			-334,
			-289,
			-250,
			-230,
			-184,
			-137,
			-125,
			-80,
			-38,
			-33,
			12
	],
	currStep : 1,
	useColor : "textTitleColor",
	bgCat : [],
	titleCat : [],
	selected : false,
	tid : 0,
	checkPotatoTimer : null,
	bodyWentBottom : 0,
	imageFlowData : "",
	isJavaVMChecked : false,

	checkPotato : function() {
		
		
		if (typeof ($id('swfpotato').getOffset) == "function") {
			var n = $id('swfpotato').getOffset();
			
			if (n == 0) {
				$("#body").stop();
				$("#lace").html("").createAppend('img', {
					src : _img + 'nitka.gif',
					width : 10,
					height : 80
				});
			}
			if (!Interface.bodyWentBottom)
				
				$id("body").style.top = (-662 + n) + "px";

			if (n == 470 && (Interface.bodyWentBottom == 0)) {
					
				setTimeout("Interface.moveBodyBottom()", 6000);
				Interface.bodyWentBottom = 1;
			}
			if (n == -1) {
				clearInterval(Interface.checkPotatoTimer);
				Interface.truncatePotato();
			}
		}
	},

	initPuppet : function() {
		$("#puppet").animate( {
			top : Interface.menuPoints[0]
		}, 300);
	},

	movePuppet : function(id, menuid) {
		id = parseInt(id);
		var from = Interface.currStep;
		var way = "1-5";
		switch (true) {
		case id <= 2:
			way = "one";
			break;
		case id <= 5:
			way = "1-2";
			break;
		case id <= 8:
			way = "2-3";
			break;
		case id <= 11:
			way = "1-5";
			break;
		default:
			break;
		}
		try {
			if(typeof($id("swfpuppet").movehand) == "function")
				$id("swfpuppet").movehand(way);
		} catch (e) {

		}

		$("#puppet").animate( {
			top : Interface.menuPoints[id]
		}, 300, function() {
			return false;
		});
		Interface.currStep = id;
	},

	movePuppetDown : function() {
		$id("swfpuppet").movehand("1-5");
		$("#puppet").animate( {
			top : -25
		}, "slow", function(){Interface.bodyWentBottom = 1;});
	},

	shakePuppet : function() {
		var top = -Math.floor(Math.random() * 280);
		var uptime = 300 + Math.floor(Math.random() * 500);
		$("#puppet").animate( {
			top : top
		}, uptime);
	},

	moveBodyBottom : function() {
		$(".body").animate( {
			top : 0
		}, 300);
		$("#lace").remove();
	},

	deleteFirstPotato : function() {
		$("#potato").css( {
			left : "1128px",
			width : "135px",
			top : "832px",
			height : "160px"
		});
		$("#potato").html("").createAppend('img', {
			src : _img + "potato_small.gif",
			width : 90,
			height : 116
		}).show();
	},

	truncatePotato : function() {
		Menu.check=true;
		Interface.checkPotato = function(){};
		$("#potatoCont").attr("class", "truncated");
		tm_checkCard = setInterval("checkCard()", 50);
	}
};

var tm_TitleText = null;
var Card = {
	page : null,
	flag:false,
	flipping : null,
	fl_cardInit : null,
	_prevState : {
		page : 0,
		flipping : 0
	},
	Init : function() {
		setTimeout("Card.Restore()", 2000);
	},
	Restore : function() {
		if ((typeof ($id("swfpageflip").render_title_text) == "function") && (typeof ($id("swfpageflip").render_inner_text_left) == "function") && (typeof ($id("swfpageflip").render_inner_text_right) == "function") && (typeof ($id("swfpageflip").render_bg_p1) == "function")
				&& (typeof ($id("swfpageflip").render_bg_p2) == "function") && (typeof ($id("swfpageflip").render_bg_p3) == "function") && (typeof ($id("swfpageflip").render_bg_p4) == "function")) {
			if (Card.TitleText.Text = Card.Last.title_text) {
				Card.TitleText.Align = Card.Last.title_text_alignment;
				Card.TitleText.Color = Card.Last.title_text_color;
				Card.TitleText.Font = Card.Last.title_text_font;
				$id("swfpageflip").render_title_text();
			}
			if (Card.InnerTextLeft.Text = Card.Last.inner_text_left) {
				Card.InnerTextLeft.Align = Card.Last.inner_text_left_alignment;
				Card.InnerTextLeft.Font = Card.Last.inner_text_left_font;
				Card.InnerTextLeft.Color = Card.Last.inner_text_left_color;
				$id("swfpageflip").render_inner_text_left();
			}
			if (Card.InnerTextLeft.Image = Card.Last.inner_text_left_image) {
				$id("swfpageflip").render_inner_text_left();
			}
			if (Card.InnerTextRight.Image = Card.Last.inner_text_right_image) {
				$id("swfpageflip").render_inner_text_right();
			}
			if (Card.InnerTextRight.Text = Card.Last.inner_text_right) {
				Card.InnerTextRight.Align = Card.Last.inner_text_right_alignment;
				Card.InnerTextRight.Font = Card.Last.inner_text_right_font;
				Card.InnerTextRight.Color = Card.Last.inner_text_right_color;
				$id("swfpageflip").render_inner_text_right();
			}
			if (Card.TitleImage.ID = Card.Last.title_image_id) {
				$id('swfpageflip').render_title_image();
			}
			if (Card.Video.Name = Card.Last.video) {
				$id('swfpageflip').render_video();
			}
			Card.TitleImage.Container.Create();
			Card.TitleText.Container.Create();
			if (Card.Cover.Name = Card.Last.background) {
				$id("swfpageflip").render_bg_p1();
				$id("swfpageflip").render_bg_p2();
				$id("swfpageflip").render_bg_p3();
				$id("swfpageflip").render_bg_p4();
			}
			if (Card.Music = Card.Last.mp3) {
				$("#dd_music dd a[rel*='" + Card.Music + "']").click();
			}
			Card.SetCost();
		} else {
			//deb("Card.Restore()");
			setTimeout("Card.Restore()", 2000);
		}
	},
	Update : function() {
		if ((Card.flipping == 1) && (Card._prevState.flipping == 0)) {
			TextControls.Hide();
			if (Card.page == 0) {
				Card.TitleImage.Container.Remove();
				Card.TitleText.Container.Remove();
				Card.InnerTextLeft.Container.Remove();
				Card.InnerTextRight.Container.Remove();
				$("#text").removeClass("card_p2").removeClass("card_p3").removeClass("card_p1");
			} else if (Card.page == 2) {
				Card.InnerTextLeft.Container.Remove();
				Card.InnerTextRight.Container.Remove();
				$("#text").removeClass("card_p2").removeClass("card_p3");
			}
			Card.Cover.Hide();
		} else if ((Card.flipping == 0) && (Card._prevState.flipping == 1)) {
			TextControls.Update();
			Card.Cover.Show();
			if (Card.page == 0) {
				$("#text").addClass("card_p1");
				if(!Card.Video.Name) {
					Card.TitleImage.Container.Create();
					Card.TitleText.Container.Create();
				}
			} else if (Card.page == 2) {
				$("#text").addClass("card_p2");
				Card.InnerTextLeft.Container.Create();
				Card.InnerTextRight.Container.Create();
			}
		}
		Card._prevState.flipping = Card.flipping;
		Card._prevState.page = Card.page;
	},

	Cover : {
		Set : function(name) {
			$.pget("/proc/render/set_background", {
				image : name
			}, function(d) {
				if (d == "OK") {
					Card.Cover.Update();
				}
			});
		},

		Update : function() {
			$id("swfpageflip").render_bg_p1();
			$id("swfpageflip").render_bg_p2();
			$id("swfpageflip").render_bg_p3();
			$id("swfpageflip").render_bg_p4();
		},

		Hide : function() {
			$.browser.msie ? $("#cover").css( {
				display : "none"
			}) : $("#cover").animate( {
				opacity : 0
			}, "fast");
		},

		Show : function() {
			$.browser.msie ? $("#cover").css( {
				display : "block"
			}) : $("#cover").animate( {
				opacity : 1
			}, "fast");
		},
		Name : null
	},

	Translate : function() {
		if ($("#txt").val().length) {
			$.fn.colorbox( {
				href : "/proc/card_processor/translate?txt=" + escape($("#txt").val()) + "&from=" + $("#tlfrom").val() + "&to=" + $("#tlto").val(),
				open : true
			});
		} else {
			alert("Please, enter a text");
		}
	},
	Video: {
		Name : null,
		Set : function(name) {
			$id("swfsnd").stopSound();
			$.pget("/proc/render/set_video", {
				video : name
			}, function(d) {
				Card.flag=true;
				if (d == "OK") {
					Card.Video.Name = name;
					Card.TitleImage.Container.Hide();
					Card.TitleText.Container.Hide();
					$id('swfpageflip').render_video();
					$("#p1_titleImage").removeClass("vk_h");
				}
			});
		},
		Update : function() {
			$id('swfpageflip').render_video();
		}
	},
	TitleImage : {
		Container : {
			text : "<br/><br/><br/><br/><b>Drag & Drop</b><br/> image here<br/> from carousel below",
			Create : function() {
				if ($("#p1_titleImage").length == 0) {
					$("#card_cont").createAppend('div', {
						id : "p1_titleImage"
					}).css( {
						opacity : Card.TitleImage.ID || Card.Video.Name? 0 : 1
					});
					$("#p1_titleImage").droppable( {
						drop : function(event, ui) {
							$id('swfpageflip').stop_video();
							$("#p1_titleImage").animate( {
								opacity : 0
							}, "fast");
							var src= ui.helper.attr("src");
							if (src.indexOf('animate') !== -1) {
								flvname = src.match(/\/([^/]+)\.(jpg|gif|png)/)[1] + '.flv';
								flvname = flvname.replace(/[ ']+/g, '_').replace(/\%20/g, '_').replace(/\%27/g, '_');
								Card.Video.Set(flvname);
							} else {
								Card.TitleImage.ID = ui.helper.attr("id").replace("img", "");
								Card.Video.Name = null;
								Card.flag=false;
								$id('swfpageflip').stop_video();
								$.pget('/proc/render/set_title_image', {
									id : Card.TitleImage.ID
								}, function(d) {
									$id('swfpageflip').render_title_image();
									
								});
								
							}
							Card.SetCost();
						}
					}).css( {
						opacity : Card.TitleImage.ID || Card.Video.Name? 0 : 1
					});
				} else {
					$("#p1_titleImage").removeClass("vk_h");
				}
			},
			Remove : function() {
				$("#p1_titleImage").addClass("vk_h");
			},
			Hide : function() {
				$("#p1_titleImage").stop().animate( {
					opacity : 0
				});
			}
		},
		ID : null
	},

	SetCost : function(id) {
		id = id ? id : Card.TitleImage.ID;
		$disc = $('#i-discount');
		discount = $disc.length ? parseInt($disc.html()) / 100 : 0;
		$freecards = $('#i-freecards');
		freecount = $freecards.length ? parseInt($freecards.html()) : 0;
		$freeallow = $('#f-a' + id);
		freeallow = $freeallow.length && freecount ? parseInt($freeallow.html()) : 0;
		$cost = $("#cost" + id);
		cost = $cost.length ? parseFloat($cost.html()) : 1.99; // First
		// Category Bug
		cost = Math.round(cost * (1 - discount) * 100) / 100; // with discount

		// Set for card
		if (cost && !freeallow) {
			$(".btnSend").css( {
				backgroundPosition : "0 -58px"
			}).html('$' + cost);
		} else {
			$(".btnSend").css( {
				backgroundPosition : "0 0"
			}).html('');
		}

		// Set for calendar
		$('#btnSendCalendar').html('$' + (cost ? cost : 1.99));
	},

	TitleText : {
		Container : {
			Create : function() {
				if ($("#p1_titleTextLayer").length == 0) {
					$("#card_cont").createAppend('div', {
						id : 'p1_titleTextLayer',
						onmouseover : function() {
							Card.TitleText.Container.Show();
						},
						onmouseout : function() {
							Card.TitleText.Container.Hide();
						},
						onclick : function() {
							Card.TitleText.Container.Hide();
							Card.TitleText.Container.LoadVK();
						}
					});
					$("#p1_titleTextLayer").css( {
						opacity : Card.TitleText.Text || Card.Video.Name ? 0.3 : 1
					});
				} else {
					$("#p1_titleTextLayer").removeClass("vk_h");
				}
			},
			Remove : function() {
				$("#p1_titleTextLayer").addClass("vk_h");
			},
			Hide : function() {
				if (Card.TitleText.Text || Card.Video.Name) {
					$("#p1_titleTextLayer").stop().animate( {
						opacity : 0
					}, function() {
						if (Card.TitleText.Text)
							$id('swfpageflip').show_title_text();
					});

				}
			},
			Show : function() {
				$id('swfpageflip').hide_title_text();
				$("#p1_titleTextLayer").stop().animate( {
					opacity : 0.6
				}, "fast");
			},
			LoadVK : function() {
				VK_load("p1_textTitle");
			}
		},
		Text : "",
		Align : "center",
		Color : "red",
		Font : "",
		FontSize : 20,
		Image : false
	},

	InnerTextLeft : {
		Container : {
			Create : function() {
				if ($("#p2_textLayerLeft").length == 0) {
					$("#card_cont").createAppend('div', {
						id : 'p2_textLayerLeft',
						onclick : function() {
							$("#text").addClass('card_p2').removeClass("card_p3");
							Card.InnerTextLeft.Container.Hide();
							$.fn.colorbox( {
								href : "/proc/boxes/choose_content_type",
								open : true
							});
						},
						onmouseover : function() {
							if (Card.InnerTextLeft.Text || Card.InnerTextLeft.Image) {
								$id("swfpageflip").hide_inner_text_left();
								Card.InnerTextLeft.Container.Show(0.3);
							}
						},
						onmouseout : function() {
							if (Card.InnerTextLeft.Text || Card.InnerTextLeft.Image) {
								$id("swfpageflip").show_inner_text_left();
								Card.InnerTextLeft.Container.Hide();
							}
						}
					}).css( {
						opacity : Card.InnerTextLeft.Text || Card.InnerTextLeft.Image ? 0 : 0.7
					});
					$("#p2_textLayerLeft").droppable( {
						drop : function(event, ui) {
							$("#p2_textLayerLeft").animate( {
								opacity : 0
							}, "fast");
							Card.InnerTextLeft.ID = ui.helper.attr("id").replace("img", "");
							$.pget('/proc/render/set_inner_text_left_image_id', {
								id : Card.InnerTextLeft.ID
							}, function(d) {
								$id("swfpageflip").render_inner_text_left();
							});
						}
					});
				} else {
					$("#p2_textLayerLeft").removeClass("vk_h");
				}
			},

			Remove : function() {
				$("#p2_textLayerLeft").addClass("vk_h");
			},

			Hide : function() {
				if (Card.InnerTextLeft.Text || Card.InnerTextLeft.Image) {
					$("#p2_textLayerLeft").stop().animate( {
						opacity : 0
					}, "fast", function() {
						if (Card.InnerTextLeft.Text) {

						}
					});
				}
			},

			Show : function(o) {
				$("#p2_textLayerLeft").stop().animate( {
					opacity : o ? o : 0.7
				}, "fast");
			},

			LoadVK : function() {
				VK_load("p2_textInnerLeft");
			}
		},
		Text : "",
		Align : "center",
		Color : "red",
		Font : "",
		FontSize : 20,
		Image : false,
		ID : null
	},

	InnerTextRight : {
		Container : {
			Create : function() {
				if (!$("#p3_textLayerRight").length) {
					$("#card_cont").createAppend('div', {
						id : 'p3_textLayerRight',
						onclick : function() {
							$("#text").removeClass("card_p2").addClass("card_p3");
							Card.InnerTextRight.Container.Hide();
							$.fn.colorbox( {
								href : "/proc/boxes/choose_content_type",
								open : true
							});
						},
						onmouseover : function() {
							if (Card.InnerTextRight.Text || Card.InnerTextRight.Image) {
								$id("swfpageflip").hide_inner_text_right();
								Card.InnerTextRight.Container.Show(0.3);
							}
						},
						onmouseout : function() {
							if (Card.InnerTextRight.Text || Card.InnerTextRight.Image) {
								$id("swfpageflip").show_inner_text_right();
								Card.InnerTextRight.Container.Hide();
							}
						}
					}).css( {
						opacity : Card.InnerTextRight.Text || Card.InnerTextRight.Image ? 0 : 0.7
					});
					$("#p3_textLayerRight").droppable( {
						drop : function(event, ui) {
							$("#p3_textLayerRight").animate( {
								opacity : 0
							}, "fast");
							Card.InnerTextRight.ID = ui.helper.attr("id").replace("img", "");
							$.pget('/proc/render/set_inner_text_right_image_id', {
								id : Card.InnerTextRight.ID
							}, function(d) {
								$id("swfpageflip").render_inner_text_right();
							});
						}
					});
				} else {
					$("#p3_textLayerRight").removeClass("vk_h");
				}
			},

			Remove : function() {
				$("#p3_textLayerRight").addClass("vk_h");
			},

			Hide : function() {
				if (Card.InnerTextRight.Text || Card.InnerTextRight.Image) {
					$("#p3_textLayerRight").stop().animate( {
						opacity : 0
					}, "fast");
				}
			},

			Show : function(o) {
				$("#p3_textLayerRight").stop().animate( {
					opacity : o ? o : 0.7
				}, "fast");
			},

			LoadVK : function() {
				VK_load("p3_textLayerRight");
			}
		},

		Text : "",
		Align : "center",
		Color : "red",
		Font : "",
		FontSize : 20,
		ID : null
	},
	SetMusic : function(mp3) {
		
		$.pget("/proc/render/set_music", {
			mp3 : mp3
		});
		Card.Music = mp3;
	},
	Music : null
};

VK_container = null;
VK_unload_tm = null;
VK_hiding = false;
tm_VKLoading = null;
VK_load = function(className) {
	VK_container = className;
	if ($(".vk_overlay").length == 0) {
		$(".ribbonCont").css( {
			zIndex : 1
		});
		// Adding Overlay
		$("#text").createAppend('div', {
			onmouseover : function() {
				clearTimeout(VK_unload_tm);
			}
		}).addClass("vk_overlay").css( {
			opacity : 0.6
		}).addClass(className);

		// Adding Controls Container
		$("#text").createAppend('div').addClass("vk_container").createAppend('textarea', {
			id : 'txt',
			onchange : function() {
				// alert(1);
			}
		}).focus().val();

		// buttons
		$(".vk_container").createAppend('div').addClass('bt_ok').click(function() {
			VK_hide();
		});
		$(".vk_container").createAppend('div').addClass('bt_clear').click(function() {
			$("#txt").val('');
		});
		$(".vk_container").createAppend('div').addClass('bt_cancel').click(function() {
			VK_container = null;
			VK_hide();
		});

		// quotes

		$(".vk_container").createAppend('div', {
			id : 'vk'
		}).css( {
			zIndex : 13
		}).addClass("vk_cont");
		$("#text").createAppend('div', {
			onmouseover : function() {
				//VK_unload_tm = setTimeout(VK_hide, 2000);
			},
			onclick : function() {
				clearTimeout(VK_unload_tm);
				VK_hide();
			}
		}).addClass("vk_unloader");
		tm_VKLoading = setInterval(function() {
			if ($id('virtualKeyboard')) {
				clearInterval(tm_VKLoading);
				return;
			}
			VirtualKeyboard.toggle('txt', 'vk');
		}, 1500);
		$(".vk_container").createAppend('div', {
			id : "tl"
		}).load("/proc/boxes/get_translate_form");
	} else {
		clearTimeout(VK_unload_tm);
		$(".vk_overlay, .vk_container, .vk_unloader").removeClass("vk_h");
	}
	switch (VK_container) {
	case "p1_textTitle":
		$('#txt').val(Card.TitleText.Text);
		break;
	case "p2_textInnerLeft":
		$('#txt').val(Card.InnerTextLeft.Text);
		break;
	case "p3_textLayerRight":
		$('#txt').val(Card.InnerTextRight.Text);
		break;
	}
	if ((className != "p1_textTitle") && ($(".vk_quotes").length == 0)) {
		Quotes.init();
	}

};

VK_hide = function() {
	if (!VK_hiding) {
		VK_hiding = true;
		switch (VK_container) {
		case "p1_textTitle":
			// Card.TitleText.Container.Show();
			$.ppost('/proc/render/set_title_text', {
				text : $('#txt').val()
			}, function(d) {
				if (d == "OK") {
					Card.TitleText.Text = $('#txt').val();
					$id('swfpageflip').render_title_text();
					Card.TitleText.Container.Hide();
					TextControls.Update();
				} else {
					Card.TitleText.Text = null;
				}
			});
			break;
		case "p2_textInnerLeft":
			$.ppost('/proc/render/set_inner_text_left', {
				text : $('#txt').val()
			}, function(d) {
				if (d == "OK") {
					Card.InnerTextLeft.Text = $('#txt').val();
					$id('swfpageflip').render_inner_text_left();
					Card.InnerTextLeft.Container.Hide();
					Card.InnerTextLeft.Image = false;
					TextControls.Update();
				} else {
					Card.InnerTextLeft.Text = null;
					Card.InnerTextLeft.Container.Show();
				}
			});
			break;
		case "p3_textLayerRight":
			$.ppost('/proc/render/set_inner_text_right', {
				text : $('#txt').val()
			}, function(d) {
				if (d == "OK") {
					Card.InnerTextRight.Text = $('#txt').val();
					$id('swfpageflip').render_inner_text_right();
					Card.InnerTextRight.Container.Hide();
					Card.InnerTextRight.Image = false;
					TextControls.Update();
				} else {
					Card.InnerTextRight.Text = null;
					Card.InnerTextRight.Container.Show();
				}
			});
			break;
		default:
			VK_hide_internal();
		}
		VK_hide_internal();
		VK_hiding = false;
	}
};

VK_hide_internal = function() {
	if ($(".vk_overlay").length == 1) {
		$(".vk_overlay, .vk_container, .vk_unloader").addClass("vk_h");
		$(".ribbonCont").css( {
			zIndex : 12
		});
		$("#text").focus();
	}
};

var TextControls = {
	Init : function() {
		$(".font").click(function() {
			if ($(this).parent().hasClass('right')) {
				$(".flist").addClass('flist_right').removeClass('flist_left');
			} else if ($(this).parent().hasClass('left')) {
				$(".flist").addClass('flist_left').removeClass('flist_right');
			}
			$(".flist").toggle();
			return false;
		});
		$(".fontsize").click(function() {
			if ($(this).parent().hasClass('right')) {
				$(".flistsize").addClass('flistsize_right').removeClass('flistsize_left');
			} else if ($(this).parent().hasClass('left')) {
				$(".flistsize").addClass('flistsize_left').removeClass('flistsize_right');
			}
			$(".flistsize").toggle();
			return false;
		});
		$(".flist a").click(function() {
			var val = $(this).find('span').html();
			if (Card.page == 0) {
				Card.TitleText.Font = val;
				$("#p_control .right .font").html($(this).html());
				var txt = "titleText";
			} else if (Card.page == 2) {
				if ($(".flist").hasClass('flist_left')) {
					Card.InnerTextLeft.Font = val;
					$("#p_control .left .font").html($(this).html());
					var txt = "innerTextLeft";
				} else {
					Card.InnerTextRight.Font = val;
					$("#p_control .right .font").html($(this).html());
					var txt = "innerTextRight";
				}
			}
			$(".flist").hide();
			TextControls.SetTextFont(txt, val);
			return false;
		});
		$(".flistsize a").click(function() {
			var val = $(this).find('span').html();
			if (Card.page == 0) {
				Card.TitleText.FontSize = val;
				$("#p_control .right .fontsize").html($(this).html());
				var txt = "titleText";
			} else if (Card.page == 2) {
				if ($(".flistsize").hasClass('flistsize_left')) {
					Card.InnerTextLeft.FontSize = val;
					$("#p_control .left .fontsize").html($(this).html());
					var txt = "innerTextLeft";
				} else {
					Card.InnerTextRight.FontSize = val;
					$("#p_control .right .fontsize").html($(this).html());
					var txt = "innerTextRight";
				}
			}
			$(".flistsize").hide();
			TextControls.SetTextFontSize(txt, val);
			return false;
		});
		$("#p_control .txt_left").click(function() {
			if (!$(this).hasClass('txt_left_sel')) {
				$(this).parent().find('div').removeClass('txt_center_sel').removeClass('txt_right_sel');
				$(this).addClass('txt_left_sel');
				var txt = "titleText";
				if (Card.page == 2) {
					txt = $(this).parent().hasClass('left') ? "innerTextLeft" : "innerTextRight";
				}
				TextControls.SetTextAlignment(txt, "northwest");
			}
		});
		$("#p_control .txt_center").click(function() {
			if (!$(this).hasClass('txt_center_sel')) {
				$(this).parent().find('div').removeClass('txt_left_sel').removeClass('txt_right_sel');
				$(this).addClass('txt_center_sel');
				var txt = "titleText";
				if (Card.page == 2) {
					txt = $(this).parent().hasClass('left') ? "innerTextLeft" : "innerTextRight";
				}
				TextControls.SetTextAlignment(txt, "north");
			}
		});
		$("#p_control .txt_right").click(function() {
			if (!$(this).hasClass('txt_right_sel')) {
				$(this).parent().find('div').removeClass('txt_center_sel').removeClass('txt_left_sel');
				$(this).addClass('txt_right_sel');
				var txt = "titleText";
				if (Card.page == 2) {
					txt = $(this).parent().hasClass('left') ? "innerTextLeft" : "innerTextRight";
				}
				TextControls.SetTextAlignment(txt, "northeast");
			}
		});
		$("#p_control .txt_color").click(function() {

		});
		$("#p_control .left, #p_control .right").css( {
			opacity : 0
		});
		$(".txt_color").click(function() {
			colorPicker_show($(this).parents('.left').length ? "left" : "right");
		});
		TextControls.Update();
	},

	Update : function() {
		$("#p_control").find('div.b').removeClass('txt_center_sel').removeClass('txt_left_sel').removeClass('txt_right_sel');
		if (Card.page == 0) {
			if (Card.TitleText.Text) {
				$("#p_control .right").css( {
					display : "block"
				}).animate( {
					opacity : 1
				}, "fast").find('.txt_' + Card.TitleText.Align).addClass('txt_' + Card.TitleText.Align + '_sel');
			}
		} else if (Card.page == 2) {
			if (Card.InnerTextLeft.Text && !Card.InnerTextLeft.Image) {
				$("#p_control .left").css( {
					display : "block"
				}).animate( {
					opacity : 1
				}, "fast").find('.txt_' + Card.InnerTextLeft.Align).addClass('txt_' + Card.InnerTextLeft.Align + '_sel');
			}
			if (Card.InnerTextRight.Text && !Card.InnerTextRight.Image) {
				$("#p_control .right").css( {
					display : "block"
				}).animate( {
					opacity : 1
				}, "fast").find('.txt_' + Card.InnerTextRight.Align).addClass('txt_' + Card.InnerTextRight.Align + '_sel');
			}
		}
	},

	Hide : function() {
		$("#p_control .left, #p_control .right").animate( {
			opacity : 0
		}, function() {
			$("#p_control .left, #p_control .right").css( {
				display : "none"
			});
		});
	},

	SetTextAlignment : function(txt, mode) {
		var m = mode == "north" ? "center" : (mode == "northeast" ? "right" : "left");
		$.pget("/proc/render/set_text_alignment", {
			txt : txt,
			mode : mode
		}, function(d) {
			if (d == "OK") {
				if (txt == "titleText") {
					Card.TitleText.Align = m;
					$id("swfpageflip").render_title_text();
				} else if (txt == "innerTextLeft") {
					Card.InnerTextLeft.Align = m;
					$id("swfpageflip").render_inner_text_left();
				} else if (txt == "innerTextRight") {
					Card.InnerTextRight.Align = m;
					$id("swfpageflip").render_inner_text_right();
				}
			}
		});
	},

	SetTextFont : function(txt, font) {
		$.pget("/proc/render/set_text_font", {
			txt : txt,
			font : font
		}, function(d) {
			if (d == "OK") {
				if (txt == "titleText") {
					Card.TitleText.Font = font;
					$id("swfpageflip").render_title_text();
				} else if (txt == "innerTextLeft") {
					Card.InnerTextLeft.Font = font;
					$id("swfpageflip").render_inner_text_left();
				} else if (txt == "innerTextRight") {
					Card.InnerTextRight.Font = font;
					$id("swfpageflip").render_inner_text_right();
				}
			}
		});
	},
	

	SetTextColor : function(txt, color) {
		$.pget("/proc/render/set_text_color", {
			txt : txt,
			color : color
		}, function(d) {
			if (d == "OK") {
				if (txt == "titleText") {
					Card.TitleText.Color = color;
					$id("swfpageflip").render_title_text();
				} else if (txt == "innerTextLeft") {
					Card.InnerTextLeft.Color = color;
					$id("swfpageflip").render_inner_text_left();
				} else if (txt == "innerTextRight") {
					Card.InnerTextRight.Color = color;
					$id("swfpageflip").render_inner_text_right();
				}
			}
		});
	},

	SetTextFontSize : function(txt, size) {
		$.pget("/proc/render/set_text_font_size", {
			txt : txt,
			size : size
		}, function(d) {
			if (d == "OK") {
				if (txt == "titleText") {
					Card.TitleText.FontSize = size;
					$id("swfpageflip").render_title_text();
				} else if (txt == "innerTextLeft") {
					Card.InnerTextLeft.FontSize = size;
					$id("swfpageflip").render_inner_text_left();
				} else if (txt == "innerTextRight") {
					Card.InnerTextRight.FontSize = size;
					$id("swfpageflip").render_inner_text_right();
				}
			}
		});
	}
};

var Quotes = {
	init : function() {
		$(".vk_container").createAppend('div').addClass('vk_quotes');
		$.pget("/proc/quotes/load_list", function(d) {
			$('.vk_quotes').html(d);
			$('#quote_cat').dropdown( {
				onchange : function(v, el) {
					$.pget("/proc/quotes/load_quotes", {
						cid : v
					}, function(d) {
						$("#q_block").html(d);
						$("#quote_list").jScrollPane( {
							showArrows : true
						});
					});
				}
			});
			$('#quote_list').jScrollPane( {
				showArrows : true
			});
			$(".quote").mouseover(function() {
				$(this).addClass("here");
			}).mouseout(function() {
				$(this).removeClass("here");
			});
		});
	},

	loadQuotes : function(id, pageNo) {
		$.pget("/proc/quotes/load_quotes", {
			cid : id,
			pageNo : pageNo
		}, function(d) {
			$("#q_block").html(d);
			$("#quote_list").jScrollPane( {
				showArrows : true
			});
		});
		return false;
	},

	paste : function(txt) {
		$("#txt").val(txt.replace(/\<br[^\>]*>/gi, "\n"));
	}
};

var Sender = {

	loadSendDialod : function() {
		$.ppost('/proc/card_processor/check', {}, function(d) {

			
			if(d!=0)
			{	
				$.fn.colorbox( {
					html :d,
					open : true
				});
			}
			else
			{
				$.fn.colorbox( {
			href : '/proc/boxes/send_card?fcsid=' + Main.fcsid,
			open : true
			}, function(){
			//debugger;
			$("#sender_name").val(Planner.formData.sname);
			$("#sender_email").val(Planner.formData.smail);
			$("#reciever_email").val(Planner.formData.rmail);
			$("#reciever_name").val(Planner.formData.rname);
			Planner.formData.chkcopy?$("#send_copy").attr('checked', true):$("#send_copy").removeAttr('checked');
			Planner.formData.chknotify?$("#know").attr('checked', true):$("#know").removeAttr('checked');
			$("#time").val(Planner.date);
			});
			}		
			
			});
		
					
		
	},

	send : function(authed) {
		

		$sender_email = '';
		$sender_name = '';

		if (!authed) {
			$sender_name = $("input[name=sender_name]");
			if (!$sender_name.val()) {
				eForm.setError($sender_name, 'field is required', 'sender');
				return false;
			}
			$sender_email = $("input[name=sender_email]");
			if (!$sender_email.val()) {
				eForm.setError($sender_email, 'field is required', 'sender');
				return false;
			}
		}

		$reciever_name = $("input[name=reciever_name]");
		if (!$reciever_name.val()) {
			eForm.setError($reciever_name, 'field is required', authed ? null : 'reciever');
			return false;
		}
		$reciever_email = $("input[name=reciever_email]");
		if (!$reciever_email.val()) {
			eForm.setError($reciever_email, 'field is required', authed ? null : 'reciever');
			return false;
		}

		$.ppost("/proc/card_processor/store", {
			sender_email : $sender_email ? $sender_email.val() : '',
			sender_name : $sender_name ? $sender_name.val() : '',
			reciever_email : $reciever_email.val(),
			reciever_name : $reciever_name.val(),
			send_copy : $("#send_copy:checked").length,
			know : $("#know:checked").length,
			sdate: $("#time").val()

		}, function(d) {
			
			
			if (d.indexOf('<error') != -1) {
				eForm.setError(d);
			} else {
				$.fn.colorbox( {
					html : d,
					open : true
				}, function() {
					$ISform = $('#add-to-card');
					if ($ISform.length) {
						$('#add-to-card').submit();
					} else {
						Main.loadAuthBlock();
					}
				});
			}
		});
		 $.fn.colorbox.close(); 
	}
};

String.prototype.hasHighUTFCode = function() {
	for ( var i = 0; i < this.length; i++) {
		if (this.charCodeAt(i) > 223)
			return true;
	}
	return false;
};

loadSWF = function(cont_id, fname, w, h, id) {
	if (!id)
		id = "swf" + cont_id;

	$('#' + cont_id).media( {
		width : w,
		height : h,
		src : '/i/swf/' + fname,
		attrs : {
			id : id,
			wmode : 'transparent',
			scale : "default",
			quality : "high",
			allowscriptaccess : "always"
		},
		params : {
			id : id,
			wmode : 'transparent',
			scale : "default",
			quality : "high",
			allowscriptaccess : "always"
		}
	});
};

var tm_colorPicker = null;
function colorPicker_show(cl) {
	clearTimeout(tm_colorPicker);
	colorPicker_hide();
	if ($("#colorpicker").length == 0) {
		$("#text").createAppend('div', {
			id : "colorpicker"
		}).addClass("cp_" + cl);
		for ( var i = 0; i < palette.length; i += 2) {
			$("#colorpicker").createAppend('div').addClass('c').attr('title', palette[i + 1]).css( {
				backgroundColor : palette[i]
			}).click(function() {
				if (Card.page == 0)
					var txt = "titleText";
				else if (Card.page == 2)
					var txt = cl == "left" ? "innerTextLeft" : "innerTextRight";
				TextControls.SetTextColor(txt, $(this).attr('title'));
				colorPicker_hide();
			});
		}
	} else {
		$("#colorpicker").removeClass('vk_h').addClass('cp_' + cl);
	}
};

function colorPicker_hide() {
	clearTimeout(tm_colorPicker);
	$("#colorpicker").remove();
}

function colorPicker_remove() {
	$(".colorpicker").empty().css( {
		display : "none"
	});
}

function obj2url(obj) {
	var url = "";
	for ( var key in obj) {
		url += key + "=" + escape(obj[key]) + "&";
	}
	return url;
}

jQuery.extend( {
	pget : function(url, params, callback) {
		var p = typeof (params) == "object" ? params : null;
		var cb = typeof (params) == "function" ? params : (typeof (callback) == "function" ? callback : null);
		if (Main.fcsid) {
			if (!p)
				p = {};
			p['fcsid'] = Main.fcsid;
		}
		$.get(url, p, function(data) {
			// TODO :data = _global_message_process(data);
				if (typeof (cb) == "function")
					cb(data);
			});
	},
	ppost : function(url, params, callback) {
		var p = typeof (params) == "object" ? params : null;
		var cb = typeof (params) == "function" ? params : (typeof (callback) == "function" ? callback : null);
		if (Main.fcsid) {
			if (!p)
				p = {};
			p['fcsid'] = Main.fcsid;
		}
		$.post(url, p, function(data) {
			// TODO :data = _global_message_process(data);
				if (typeof (cb) == "function")
					cb(data);
			});
	}
});

function $id(id) {
	return document.getElementById(id);
}

function deb(s) {
	if (debug) {
		$("#dbg").html($("#dbg").html() + s + "<br/>").css( {
			display : "block"
		});
	}
}

var palette = new Array('#F0F8FF', 'aliceblue', '#FAEBD7', 'antiquewhite', '#00FFFF', 'aqua', '#7FFFD4', 'aquamarine', '#F0FFFF', 'azure', '#F5F5DC', 'beige', '#FFE4C4', 'bisque', '#191970', 'MidnightBlue', '#FFEBCD', 'blanchedalmond', '#0000FF', 'blue', '#8A2BE2', 'blueviolet', '#A52A2A', 'brown',
		'#DEB887', 'burlywood', '#5F9EA0', 'cadetblue', '#7FFF00', 'chartreuse', '#D2691E', 'chocolate', '#FF7F50', 'coral', '#6495ED', 'cornflowerblue', '#FFF8DC', 'cornsilk', '#DC143C', 'crimson', '#00FFFF', 'cyan', '#00008B', 'darkblue', '#008B8B', 'darkcyan', '#B8860B', 'darkgoldenrod',
		'#A9A9A9', 'darkgray', '#006400', 'darkgreen', '#BDB76B', 'darkkhaki', '#8B008B', 'darkmagenta', '#556B2F', 'darkolivegreen', '#FF8C00', 'darkorange', '#9932CC', 'darkorchid', '#8B0000', 'darkred', '#E9967A', 'darksalmon', '#8FBC8F', 'darkseagreen', '#483D8B', 'darkslateblue', '#2F4F4F',
		'darkslategray', '#00CED1', 'darkturquoise', '#9400D3', 'darkviolet', '#FF1493', 'deeppink', '#00BFBF', 'deepskyblue', '#696969', 'dimgray', '#1E90FF', 'dodgerblue', '#B22222', 'firebrick', '#FFFAF0', 'floralwhite', '#228B22', 'forestgreen', '#FF00FF', 'fuchsia', '#DCDCDC', 'gainsboro',
		'#F8F8FF', 'ghostwhite', '#FFD700', 'gold', '#DAA520', 'goldenrod', '#808080', 'gray', '#008000', 'green', '#ADFF2F', 'greenyellow', '#F0FFF0', 'honeydew', '#FF69B4', 'hotpink', '#CD5C5C', 'indianred', '#4B0082', 'indigo', '#FFFFF0', 'ivory', '#F0E68C', 'khaki', '#E6E6FA', 'lavender',
		'#FFF0F5', 'lavenderblush', '#7CFC00', 'lawngreen', '#FFFACD', 'lemonchiffon', '#ADD8E6', 'lightblue', '#F08080', 'lightcoral', '#E0FFFF', 'lightcyan', '#FAFAD2', 'lightgoldenrodyellow', '#90EE90', 'lightgreen', '#D3D3D3', 'lightgrey', '#FFB6C1', 'lightpink', '#FFA07A', 'lightsalmon',
		'#20B2AA', 'lightseagreen', '#87CEFA', 'lightskyblue', '#778899', 'lightslategrey', '#B0C4DE', 'lightsteelblue', '#FFFFE0', 'lightyellow', '#00FF00', 'lime', '#32CD32', 'limegreen', '#FAF0E6', 'linen', '#FF00FF', 'magenta', '#800000', 'maroon', '#66CDAA', 'mediumaquamarine', '#0000CD',
		'mediumblue', '#BA55D3', 'mediumorchid', '#9370DB', 'mediumpurple', '#3CB371', 'mediumseagreen', '#7B68EE', 'mediumslateblue', '#00FA9A', 'mediumspringgreen', '#48D1CC', 'mediumturquoise', '#C71585', 'mediumvioletred', '#191970', 'midnightblue', '#F5FFFA', 'mintcream', '#FFE4E1',
		'mistyrose', '#FFE4B5', 'moccasin', '#FFDEAD', 'navajowhite', '#000080', 'navy', '#FDF5E6', 'oldlace', '#808000', 'olive', '#6B8E23', 'olivedrab', '#FFA500', 'orange', '#FF4500', 'orangered', '#DA70D6', 'orchid', '#EEE8AA', 'palegoldenrod', '#98FB98', 'palegreen', '#AFEEEE',
		'paleturquoise', '#DB7093', 'palevioletred', '#FFEFD5', 'papayawhip', '#FFDAB9', 'peachpuff', '#CD853F', 'peru', '#FFC0CB', 'pink', '#DDA0DD', 'plum', '#B0E0E6', 'powderblue', '#800080', 'purple', '#FF0000', 'red', '#BC8F8F', 'rosybrown', '#4169E1', 'royalblue', '#8B4513', 'saddlebrown',
		'#FA8072', 'salmon', '#F4A460', 'sandybrown', '#2E8B57', 'seagreen', '#FFF5EE', 'seashell', '#A0522D', 'sienna', '#C0C0C0', 'silver', '#87CEEB', 'skyblue', '#6A5ACD', 'slateblue', '#708090', 'slategray', '#FFFAFA', 'snow', '#00FF7F', 'springgreen', '#4682B4', 'steelblue', '#D2B48C', 'tan',
		'#008080', 'teal', '#D8BFD8', 'thistle', '#FF6347', 'tomato', '#40E0D0', 'turquoise', '#EE82EE', 'violet', '#F5DEB3', 'wheat', '#FFFFFF', 'white', '#F5F5F5', 'whitesmoke', '#FFFF00', 'yellow', '#9ACD32', 'yellowgreen');

var eForm = {

	setError : function(data, text, boxissue) {

		if (typeof (data) == 'object' && text) {
			// --
			this.markBlock(text, boxissue);
			this.markField(data);
		} else if (error = data.match(/\<error f\=.([^>'"]+).*\>(.*)\<.error\>/)) {
			f = error[1];
			text = error[2];
			boxissue = data.match(/\<error.*is\=.([^>'"]+).*\>/)
			boxissue = boxissue ? boxissue[1] : null;

			this.markBlock(text, boxissue);

			items = f.split(/\|/);

			for (i = 0; i < items.length; i++) {
				$f = $('#' + items[i]);

				if ($f.length) {
					this.markField($f);
				}
			}
		}

		return false;
	},

	markBlock : function(text, boxissue) {

		// reset several rest
		boxissue ? this.reset(boxissue) : false;

		$block = $('#box-block' + (boxissue ? ('-' + boxissue) : ''));
		$block.addClass('error');
		$h1 = $block.find('h1');
		$h1.attr('title', $h1.html()).html('Error: ' + text);
	},

	reset : function(boxissue) {

		$.each($('div.error'), function() {

			$this = $(this);
			$this.removeClass('error');

			$h1 = $this.find('h1');
			$h1.attr('title') ? $h1.html($h1.attr('title')) : false;

		});

	},

	markField : function($f) {

		$f.addClass('error').bind('focus', function() {
			$(this).removeClass('error');
		});
	}

};

var Registration = {

	init : function() {

		$("#btnMembers").click(function() {
			$.fn.colorbox( {
				href : "/proc/boxes/login",
				open : true
			});
		});
		$(".addBalance").colorbox();

		Card.SetCost();
	},
	new_reg:function(){
	/*	$.fn.colorbox( {
				href : "/proc/boxes/new_reg",
				open : true
			});*/
	$.ppost('/proc/boxes/new_reg', {}, function(d) {
			if(d!=0)
			{	
				$.fn.colorbox( {
					html :d,
					width:800,
					height:900,
					open : true
				});
			}
		});
	},
	auth : function() {

		login = email = $('#auth_login').val();
		if (!login) {
			eForm.setError($('#auth_login'), 'field is required');
			return false;
		}

		pass = $('#auth_pass').val();
		if (!pass) {
			eForm.setError($('#auth_pass'), 'field is required');
			return false;
		}

		$.pget("/proc/login/auth", {
			login : login,
			pass : pass

		}, function(data) {

			if (data.indexOf('<') == -1) {
				// error
				alert(data);

			} else if (data.indexOf('<error') != -1) {
				eForm.setError(data);

			} else {

				if ($('#issingin_frame').length) {
					// Sign into ShoppingCart
				jQuery('#EMail').val(email);
				jQuery('#Password').val(pass);
				$('#issingin_form').submit();
			}

			if ($('#gallery_frame').length) {
				// Sign into artgallery
				jQuery('#AGemail').val(email);
				$('#gallery_form').submit();
			}

			// Balance data
			$('#authCont').html(data);
			$.fn.colorbox.close();
			/*$.pget('/proc/login/login_form', {}, function(d) {
						alert(d);
					});*/
			
			$.ppost('/proc/login/login_form', {login : login,
			pass : pass}, function(d) {
			if(d!=0)
			{	
				$.fn.colorbox( {
					html :d,
					open : true
				});
			}
		});

			Registration.init();

		}

	}	);
	},

	logout : function() {
		$.fn.colorbox( {
			href : '/proc/boxes/logout',
			open : true
		});

		$.pget("/proc/login/logout", null, function(data) {

			if (data.indexOf('<') != -1) {
				$('#authCont').html(data);
				Registration.init();
			}

			$.fn.colorbox.close();

		});
	},

	setAddBalanceProductId : function(id) {
		$('#ProductID').val(id);
		$('#AddToCart').attr('name', 'AddToCart_' + id);
	},

	addBalanceTransaction : function() {
		
		var id = $('#ProductID').val();

		$('#membership-table').css( {
			display : 'none'
		});
		$('#order').css( {
			display : 'none'
		});

		$('#redirect-message').css( {
			display : 'block',
			textDecoration : 'blink'
		});
		
		$.pget("/proc/login/addbalance", {
			is_id : id
		}, function(data) {
			
			$('#form_m').submit();
			

		});

	},

	addBalanceDialog : function() {

		$.fn.colorbox( {
			href : '/proc/boxes/addbalance?fcsid=' + Main.fcsid,
			open : true
		});
	},

	checkAutoLogin : function() {
		$.pget("/proc/login/check_autologin", null, function(data) {

			if (data == '1') {
				$.pget("/proc/login/load_form", null, function(data) {

					if (data) {
						$('#authCont').html(data);
					}
				});
			} else {
				window.setTimeout('Registration.checkAutoLogin()', 5000);
			}

		});

	}

};

var Calendar = {
	m : (new Date()).getMonth() + 1,
	y : (new Date()).getFullYear(),
	period : $("#t_r1:checked").length ? "m" : "y",
	layout : 1,
	color : 1,

	SetImage : function(id) {

		Card.SetCost();

		$.pget("/proc/render/set_calendar_image", {
			id : id
		}, function(d) {
			if (d == "OK") {
				Calendar.UpdateImage();
			}
		});
	},

	UpdateImage : function() {
		$("#cal_loader").stop().css( {
			opacity : 0,
			display : "block"
		}).animate( {
			opacity : 1
		}, "fast");
		$.pget("/proc/render/set_calendar_mode", {
			m : Calendar.m,
			y : Calendar.y,
			period : Calendar.period,
			layout : Calendar.layout,
			color : Calendar.color
		}, function(d) {
			if (d == "OK") {
				Calendar.LoadImage();
			}
		});
	},

	LoadImage : function() {
		var img = new Image();
		img.onload = function() {
			$("#cal_img").attr("src", this.src);
			$("#cal_loader").stop().animate( {
				opacity : 0
			}, "fast");
		};
		img.src = "/proc/render/get_calendar_image?fcsid=" + Main.fcsid + "&_r=" + Math.random();
	},

	SetMode : function(m) {
		switch (m) {
		case "y":
			$("#calendar_control").addClass('yearly').removeClass('monthly');
			this.period = "y";
			break;
		case "m":
			$("#calendar_control").removeClass('yearly').addClass('monthly');
			this.period = "m";
			break;
		}
		Calendar.UpdateImage();
	},

	GetInfo : function() {
		$.fn.colorbox( {
			href : '/proc/boxes/calendar?fcsid=' + Main.fcsid,
			open : true
		});
	},

	Buy : function() {

		$name = $("#cname");
		if ($name.length && !$name.val()) {
			eForm.setError($name, 'field is required');
			return false;
		}

		$email = $("#cemail");
		if ($email.length && !$email.val()) {
			eForm.setError($email, 'field is required');
			return false;
		}

		$.ppost("/proc/calendar_processor/store", {
			name : $name.val(),
			email : $email.val()
		}, function(data) {

			if (data.indexOf('<error') != -1) {
				eForm.setError(data);

			} else {
				$.fn.colorbox( {
					html : data,
					open : true
				}, function() {

					$ISform = $('#add-to-card');

					if ($ISform.length) {
						$('#add-to-card').submit();
					} else {
						Main.loadAuthBlock();
					}
				});
			}
		});
	}
};

var Planner = {
		m : null,
		y : null,
		type: null,
		date: null,
		formData: {smail:null, sname:null, rmail:null, rname:null, chkcopy:null, chknotify:null},
		open : function(m, y, type) {
			this.formData = {smail:null, sname:null, rmail:null, rname:null, chkcopy:null, chknotify:null};
			this.m = m; this.y = y;
			if(this.m==undefined || this.y == undefined) {
				this.m = (new Date()).getMonth()+1;
				this.y = (new Date()).getFullYear();
			}
			this.date="";
			if(type == undefined) {
				this.type = 'event';
			} else {
				this.type = 'card';
				with(this.formData) {
					sname= $("#sender_name").val();
					smail= $("#sender_email").val();
					rmail= $("#reciever_email").val();
					rname= $("#reciever_name").val();
					chkcopy= $("#send_copy:checked").length;
					chknotify= $("#know:checked").length;
				}
			}
			
			$.fn.colorbox( {
				href : "/proc/planner/reminder?month="+this.m+"&year="+this.y+"&fcsid=" + Main.fcsid+"&_r"+Math.random(),
				open : true
			}, function() {
				$('.rem_day')
				.mouseover(function(){
					if($(this).find('.e').length == 0) {
						this.style.background="url("+_img+"/add.gif) no-repeat";
					}
				})
				.mouseout(function(){this.style.background="none"});
				
				$('.rem_day:has(.e)').find('.addSmall').click(function(){
					if(Planner.type == 'card') {
						Planner.date = $(this).parents('.rem_day').find('.d').attr('rel');
						Sender.loadSendDialod();
					} else {
						$.fn.colorbox( {
							href : "/proc/planner/rm_add?date="+$(this).parents('.rem_day').find('.d').attr('rel')+'&fcsid='+Main.fcsid+"&type="+this.type+"&_r"+Math.random(),
							open : true
						});
					}
				});
				$('.rem_day:not(:has(.e))').click(function(){
					if(Planner.type == 'card') {
						Planner.date = $(this).find('.d').attr('rel');
						Sender.loadSendDialod();
					} else {
						$.fn.colorbox( {
							href : "/proc/planner/rm_add?date="+$(this).find('.d').attr('rel')+'&fcsid='+Main.fcsid+"&type="+this.type+"&_r"+Math.random(),
							open : true
						});
					}
				});
				$('.rem_day:not(:has(.e))').find('.addSmall').remove();
			});
			return false;
		},
		
		save : function(id) {
			$.post("/proc/planner/rm_save", {
				'id' : id == undefined ? 0 : id,
				'rem_title': $('#rem_title').val(),
				'rem_type': $('#rem_type').val(),
				'rem_notes':$('#rem_notes').val(),
				'rem_alarmDays':$('#rem_alarmDays').val(),
				'rem_rec':$('#rem_rec').val(),
				'rem_calendar': $('#rem_calendar').val(),
				'fcsid' : Main.fcsid,
				'_r':Math.random()
			}, function(){
				Planner.open(Planner.m, Planner.y);
			});
		},
		edit : function(id) {
			$.fn.colorbox( {
				href : "/proc/planner/rm_edit?id="+id+"&fcsid="+Main.fcsid+"&_r"+Math.random(),
				open : true
			}, function() {
				
			});
		},
		
		del : function(id) {
			$.get("/proc/planner/rm_del", {id:id, fcsid:Main.fcsid, _r:Math.random()}, function(){
				Planner.open(Planner.m, Planner.y);
			});
		}
}

var Menu = {

	xml : $("#menuxml"),
	menuid : 0,
	menuImage : _img + "menu.gif",

	niImg : '',
	niBg : '',

	crc : "",
	sid : null,
	check:false,

	historyStock : [],
	historyStockI : 0,

	init : function(id) {
		if(Menu.check==true)
			{
			Interface.bodyWentBottom = 1;
			return;
			}
		var mid = 0;
		Menu.xml = $("#menuxml");
		if (id == 0) {
			var items = $("root > item", Menu.xml);
		} else {
			var items = $("item[pid=" + id + "]", Menu.xml);
		}
		// debugger;
		Menu.menuid = id;
		$("#menu").html("");
		Menu.menuShowBackButton(id != 0);
		for (i = 0; i < items.length; i++) {
			$("#menu").createAppend('div', {
				className : "m",
				id : "m" + i
			}, [
					'img',
					{
						src : Menu.menuImage
					}
			]);
			if ($(items[i]).attr("bgid")) {
				Interface.bgCat[$(items[i]).attr("id")] = $(items[i]).attr("bgid");
				$("#bgCont").css( {
					display : "block"
				});
			} else {
				$("#bgCont").css( {
					display : "none"
				});
			}

			Interface.titleCat[$(items[i]).attr("id")] = $(items[i]).attr("tid");
			var mid = $(items[i]).attr("id");
			$("#m" + i).createAppend('div', {
				className : "mcont"
			}, [
					'a',
					{
						href : "/" + $(items[i]).attr("alias_path") + ".html",
						id : "a_" + mid,
						onclick : function() {
							if(Interface.bodyWentBottom == 0)
								return false;
							var href = this.href;
							var id = $(this).parent().parent().attr("id").replace("m", "");
							var this_id = this.id.replace("a_", "");

							Menu.changeCategory(href, id, this_id, true);

							return false;
						}
					},
					$(items[i]).attr("name")
			]);
			if (debug)
				{
				
				Menu.menuItemShow(i);
				}
			else
				{
			
			
				setTimeout("Menu.menuItemShow(" + i + ");", i * 300);
				}

			if (i == items.length - 1 && $("#puppet > *").length == 0 && (id==0)) {
				// setTimeout('loadSWF("puppet", "man_small.swf?' +
				// Math.random() + '", 189, 930, "swfpuppet");', i * 700);
				
			
				if(getCookie('id_session'))
				{
				Interface.checkPotatoTimer = setInterval("Interface.checkPotato()", 100);
				$("#body").css( {top : "0px"});
				Interface.truncatePotato();
				setTimeout("Interface.moveBodyBottom()", 6000);
				Interface.bodyWentBottom = 1;
				$("#lace").hide();
								
				}
				else{
				setTimeout(function() {
					if (!debug && (id==0)) {
						$("#body").animate( {
							top : -650
						}, 3000, function() {
							$('#selSound').css( {
								display : "none"
							});
							$("#body").animate( {
								top : -800
							}, 15000);
							loadSWF("potato", "potato_small2.swf?" + Math.random(), 870, 670);
							Interface.checkPotatoTimer = setInterval("Interface.checkPotato()", 100);
							setCookie('id_session',true);
						});
					}
				}, i * 600);
					}
			}
		}

	},

	changeCategory : function(href, id, this_id, his) {
		/*
		 * if (his) { Main.historyAdd(href, id, this_id); }
		 * if(Interface.bodyWentBottom != 1) return false;
		 */

		if (this_id == "10") {
			$("#mli295").click();
			swap_cal();
		} else {
			$("#text").removeClass('calendar');
			if ($("item[id=" + this_id + "] > *", Menu.xml).length) {
				Menu.init(this_id);
				Main.historyAdd('sub', false, false);
				if($("#a_202").length)
					$("#a_202").click();
				else
					$("#menu .m:first a").click();
			} else {

				Ribbon.chcategory(0, id, this_id);
			}
		}
	},

	menuShowBackButton : function(isShow) // true, false
	{
		isShow ? $("#menu").createAppend('div', {
			className : "btnBack",
			id : "btnBack"
		}, [
				'img',
				{
					src : _img + "back1.gif",
					onclick : function() {
						Menu.menuBack();
					},
					onload : function() {
						this.style.width = "94px";
						this.style.height = "32px";
					}
				}
		]) : $("#btnBack").remove();
	},

	menuBack : function() {
		Menu.menuid = $("item[id=" + Menu.menuid + "]", Menu.xml).parent().attr("id");
		Menu.init(Menu.menuid);
	},

	menuItemShow : function(id) {
		$("#m" + id).css( {
			top : id * 44 + 100,
			opacity : 0
		}).animate( {
			top : (id * 44 + 260),
			opacity : 1
		}, 350, function() {
			
			if (id == 9 && $(this).find('a').text() == 'Calendars') {
				$("#menu").createPrepend("img", {
					src : _img + "2010.gif",
					width : 79,
					height : 49,
					style : "position:absolute;left:140px;top:649px;cursor:pointer;z-index:12",
					onclick : function() {
						$("#a_10").click();
					}
				});
			}
		});
	}

};

swap_cc = function() {
	if ($("#btnCC").toggleClass('btnCC').hasClass('btnCC')) {
		$("#text").addClass('calendar');
		if (Card.TitleImage.ID)
			Calendar.SetImage(Card.TitleImage.ID);
		else
			Calendar.SetImage($("#ribbon #mask li:first img").attr('id').replace('img', ''));
		$("#calendar_cont #layer").droppable( {
			drop : function(event, ui) {
				Calendar.SetImage(ui.helper.attr("id").replace("img", ""));
			}
		});
	}  else {
		$("#text").removeClass('calendar');
	}
};


swap_cal = function() {
	if(!$("#text").hasClass('calendar')) {
		if ($("#btnCC").toggleClass('btnCC').hasClass('btnCC')) {
			$("#text").addClass('calendar');
			if (Card.TitleImage.ID)
				Calendar.SetImage(Card.TitleImage.ID);
			else
				Calendar.SetImage($("#ribbon #mask li:first img").attr('id').replace('img', ''));
			$("#calendar_cont #layer").droppable( {
				drop : function(event, ui) {
					Calendar.SetImage(ui.helper.attr("id").replace("img", ""));
				}
			});
		}
	}
}

function obj2url(obj) {
	var url = "";
	for ( var key in obj) {
		url += key + "=" + escape(obj[key]) + "&";
	}
}

var bnid = 0;
function rotate() {
	banners = [
			'/i/bnet/jewel01.swf?clickTAG=http://trevijewelry.com&clickTARGET=_blank',
			'/i/bnet/armory01.swf?clickTAG=http://treviarmory.com&clickTARGET=_blank'
	];

	$("#bn").media( {
		width : 320,
		height : 140,
		src : banners[(bnid++) % banners.length],
		attrs : {
			id : "bnswf",
			wmode : 'transparent',
			scale : "noborder",
			quality : "high",
			allowscriptaccess : "sameDomain"
		},
		params : {
			id : "bnswf",
			wmode : 'transparent',
			scale : "noborder",
			quality : "high",
			allowscriptaccess : "sameDomain"
		}
	});
};

_global_loaded_modules = new Array();
function _global_load_module(name, params) {
	if (typeof (_global_loaded_modules[name]) == "undefined") {
		var head = document.getElementsByTagName("head")[0];
		script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = name + "?" + params + "&_r" + Math.random();
		head.appendChild(script);
		_global_loaded_modules.push(name);
	}
};
(function($) {
	jQuery.fn.dropdown = function(options) {
		$.fn.dropdown.defaults = {
			onchange : new Function()
		};
		var opts = $.extend( {}, $.fn.dropdown.defaults, options);

		$(document).click(function(e) {
			if (!$(e.target).parents().hasClass("__dd-dt-list"))
				$(".dropdown dd ul").hide();
		});

		return this.each(function() {
			if ($(this).hasClass("__dd-dt-list"))
				return;
			($this = $(this)).addClass("__dd-dt-list").show();

			var a = $this.find("dt a").append('<div class="dd_arrow"><!-- --></div>').click(function() {
				$(this).parents('dl.dropdown').find("dd ul").toggle();
				return false;
			});

			$this.find("dd ul li a").click(function() {
				var o = $.meta ? $.extend( {}, opts, $this.data()) : opts;
				$(this).parents('dl.dropdown').find("dt a span").html(this.innerHTML);
				o.onchange($(this).find("span:last").html(), this);
				$(this).parents('dl.dropdown').find("dd ul").hide();
				return false;
			});
		});
	};
})(jQuery);


function fun2()
{
	$.pget('/proc/render/get_title_image',{},function(data){
		
	});
		


	

}
