
function historyCall(hash, sl) 
{
	if(hash) 
	{
		if (!sl) 
		{

			hash = hash.replace(/\:\:\:/gi, '=');
			hash = hash.replace(/\:\:/gi, '?');
			hash = hash.replace(/\:/gi, '/');

			TreviMain.navigate(hash, 1);

		}
	} else 
	{
		TreviMain.navigate('index.html', 1);

		if($.browser.msie)
		{
			document.getElementById("wmp").controls.play();
			$("#video").attr("class", "video_on");
		}
		else
		{
			$('#video').media({
				width:     448,
				height:    336,
				autoplay:  true,
				src:       'video/russian_art.wmv',
				attrs:     { id : "wmp", ShowControls: '0', ShowStatusBar: "false", uiMode :"none", ShowAudioControls:"0"},  // object/embed
																																// attrs
				params:    { id : "wmp", ShowControls: '0', ShowStatusBar: "false", uiMode :"none", ShowAudioControls:"0"}, // object
																															// params/embed
																															// attrs
				caption:   false // supress caption text
			});	
		}
	}

}


var TreviMain = {
	buttons: [
			["button2", "gallery.gif", "http://treviartgallery.com"],
			["button3", "museum.gif", "http://treviarmory.com"],
			["button1", "jewerly.gif", "http://trevijewelry.com"],
			["button5", "choco.jpg", "http://trevichocolate.com"],
			["button6", "ecards.jpg", "http://trevicards.com"],
			["button8", "trevisoft.jpg", "http://trevisoft.net"],
			["button4", "photo_video.gif", "http://trevistudio.com"],
			["button11", "nk.gif", "http://trevifun.com"],
			["button12", "nkw.gif", "http://trevitv.com"],
			["button9", "gourmet.jpg	", "http://trevigourmet.com"],
			["button10", "carriages.jpg", "http://trevicarriages.com"],
			["button7", "skype.jpg", "http://skype.com"]
		],

	buttonsCounter :0,

	indexOf : function(name)
	{
		for(i=0;i<this.buttons.length;i++)
		{
			if(name==this.buttons[i][0]){return i;}
		}
		return false;
	},

	start:function()
	{
		$.fn.media.defaults.flashVersion="8";
		$.fn.media.defaults.bgColor="";
		$.fn.media.defaults.flvPlayer="/i/flash/mediaplayer.swf";
		$('#logo').media({
			width:     285,
			height:    85,
			src:       '/i/flash/logo.swf',
			attrs:     { wmode: 'transparent', scale: "noborder", quality:"high", allowscriptaccess:"sameDomain"},  // object/embed
																													// attrs
			params:    { wmode: 'transparent', scale: "noborder", quality:"high", allowscriptaccess:"sameDomain"} // object
																													// params/embed
																													// attrs
		});
		run_writer();setInterval("run_writer();", 20000);
		if($('.container'))
			$('.container').jScrollPane();
		TreviMain.loadImages();
		$("a[class='inactive']").bind("click", function(){return false});
		$(".copy a").bind("click", function(){TreviMain.navigate(this);return false});

		
	},
	
	loadImages : function()
	{
		var img=[];
		for(var i=0;i<this.buttons.length;i++)
		{
			$("#"+TreviMain.buttons[i][0]+" img").css({cursor:"pointer"}).click(function(){document.location=TreviMain.buttons[TreviMain.indexOf($(this).parent().attr("id"))][2];});
			img[i] = new Image();
			img[i].src = "i/buttons/color/"+this.buttons[i][1]+"?"+Math.random();
			img[i].id = this.buttons[i][0]+"_i";
			img[i].onload = function()
			{
				var id=this.id.replace("_i", "");
				$("#"+id).createAppend(
					'div', {id:id+"_c", className:"btn",
						onmouseover : function()
						{
							if("button5_c button6_c button7_c button8_c".indexOf(this.id) == -1)
								this.style.top="-95px";
						},
						onmouseout : function()
						{
							this.style.top=0;
						},
						onclick : function()
						{
							document.location = TreviMain.buttons[TreviMain.indexOf(this.id.replace("_c", ""))][2];
						}
					},
					[
						'img', {src:this.src}
					]
					);
				$("#"+id+"_c").css({opacity:0});
				$("#"+id+"_c").animate({opacity:1}, 300);
				TreviMain.buttonsCounter++;
				if(document.location.pathname=="/")
					TreviMain.loadVideo();
			}
		}

		$("#globik_btn").click(function()
			{
				document.location = "http://trevisoft.net";
			}
		);
	},

	loadVideo : function()
	{
		if(this.buttonsCounter < this.buttons.length)
			return;
		for(i=5;i<9;i++)
		{
			$("#button"+i+"_c").unbind("mouseover");
		}
		$("#button5_c").css({width:"233px",height:"119px"});
		if($.browser.msie || true)
		{
			$('#video').media({
				width:     448,
				height:    336,
				autoplay:  true,
				src:       'video/russian_art.wmv',
				attrs:     { id : "wmp", ShowControls: '0', ShowStatusBar: "false", uiMode :"none", ShowAudioControls:"0"},  // object/embed
																																// attrs
				params:    { id : "wmp", ShowControls: '0', ShowStatusBar: "false", uiMode :"none", ShowAudioControls:"0"}, // object
																															// params/embed
																															// attrs
				caption:   false // supress caption text
			});
		}
		else
		{
			$('#video').media({
				width:     448,
				height:    336,
				src:       '/video/russian_art.flv',
				attrs:     {wmode: 'transparent', scale: "noborder"},  // object/embed
																		// attrs
				params:    {wmode: 'transparent', scale: "noborder"}	// object
																		// params/embed
																		// attrs
			});
		}
		this.loadFlashes();
	},

	loadFlashes : function()
	{
		this._loadPV();
		this._loadNKW();
		this._loadTreviSoft();
	},

	_loadPV : function()
	{
		$("#button4").createPrepend(
			'div', {id:"fl4", className:"fl4"}
			);
		$('#fl4').media({
			width:     150,
			height:    93,
			autoplay:  true,
			src:       'i/flash/pv_opt.swf',
			attrs:     { wmode: 'transparent', scale: "noborder"},  // object/embed
																	// attrs
			params:    { wmode: 'transparent', scale: "noborder"}, // object
																	// params/embed
																	// attrs
			caption:   false // supress caption text
		});
	},

	_loadNKW : function()
	{
		$("#button12").createPrepend(
			'div', {id:"fl12", className:"fl12"}
			);
		$('#fl12').media({
			width:     155,
			height:    72,
			autoplay:  true,
			src:       'i/flash/nkw.swf',
			attrs:     { wmode: 'transparent', scale: "noborder"},  // object/embed
																	// attrs
			params:    { wmode: 'transparent', scale: "noborder"}, // object
																	// params/embed
																	// attrs
			caption:   false // supress caption text
		});
	},

	_loadTreviSoft : function()
	{
		$('#globik').media({
			width:     130,
			height:    130,
			src:       '/i/flash/logo_opt.swf',
			attrs:     { wmode: 'transparent', scale: "noborder", quality:"high", allowscriptaccess:"sameDomain"},  // object/embed
																													// attrs
			params:    { wmode: 'transparent', scale: "noborder", quality:"high", allowscriptaccess:"sameDomain"} // object
																													// params/embed
																													// attrs
		});
	},

	historyAdd : function(url)
	{
		/*
		 * if (url != 'fc') { $.cookie('last_url', 'jew:' + url, {path: '/'}); }
		 */
		url = url.replace(/http\:\/\/[^/]+\// , '');
		url = url.replace(/\//gi, ':');
		url = url.replace(/\?/gi, '::');
		url = url.replace(/\=/gi, ':::');

		$.historyLoad(url, true);
	},


	navigate : function(obj, hist)
	{
		if($.browser.msie && document.getElementById("wmp"))
		{
			document.getElementById("wmp").controls.pause();
			$("#video").attr("class", "video_off");
		}
		else
		{
			$("#video").html("");
		}

		var href = hist ? obj : obj.pathname;
	
		if (!hist)
		{
			TreviMain.historyAdd(href);
		}

		$("#tvBg").animate({opacity:0}, 2000);
		pageTracker._trackPageview(href);
		$.ajax({
			url: "/html/" + href,
			cache: false,
			dataType: "text",
			success: function(html){
				if (href.match(/\/$/) || href=="")
				{
					if($.browser.msie)
					{
						document.getElementById("wmp").controls.play();
						$("#video").attr("class", "video_on");
					}
					else
					{
						$('#video').media({
							width:     448,
							height:    336,
							autoplay:  true,
							src:       '/video/russian_art.wmv',
							attrs:     { id : "wmp", ShowControls: '0', ShowStatusBar: "false", uiMode :"none", ShowAudioControls:"0"},  // object/embed
																																			// attrs
							params:    { id : "wmp", ShowControls: '0', ShowStatusBar: "false", uiMode :"none", ShowAudioControls:"0"}, // object
																																		// params/embed
																																		// attrs
							caption:   false // supress caption text
						});	
					}
				}
				$("#tvBg").html(html).stop().animate({opacity:1}, "slow");
				$('.container').jScrollPane(); 
			}
		});
	}
}

var prases = [
	[escape("Happy holiday season!!\nSave extra 5% on jewelry !!!")+"&sign_scale=0.65&offset_x=10&sign_color=0xFFFFFF&line_height=60&offset_y=10"],
	[escape("Buy Directly from Original Faberge Factory and Save!")+"&sign_scale=0.40&offset_x=40&sign_color=0xCCCCCC&line_height=60&offset_y=5"],
	[escape("Buy Directly from Moscow Kremlin Purveyor and Save!")+"&sign_scale=0.40&offset_x=40&sign_color=0xCCCCCC&line_height=60&offset_y=5"],
	[escape("Modern Technology and Royal Grandour for Less!!!")+"&sign_scale=0.40&offset_x=40&sign_color=0xCCCCCC&line_height=60&offset_y=5"]
];
var phrasesLastId=1;

function run_writer()
{
	do{
		var id = Math.floor(Math.random()*prases.length);
	}while(id == phrasesLastId);
	$('#writer').media({
		width:     600,
		height:    120,
		src:       "/i/flash/demo_trevimedia.swf?sign_text="+prases[phrasesLastId = id],
		attrs:     {id:'swfwriter',wmode: 'transparent', scale: "noborder", quality:"high", allowscriptaccess:"crossDomain"},  // object/embed
																																// attrs
		params:    {id:'swfwriter',wmode: 'transparent', scale: "noborder", quality:"high", allowscriptaccess:"crossDomain"} // object
																																// params/embed
																																// attrs
	});
};

