/**
	____________________RIMSKY / Main
	
 *  @author     Nahuel Scotti <nahuel.scotti@gmail.com>
 *  @version    1.0.0 (last revision: Enero 1, 2008)
 *  @copyright  (c) 2008 Nahuel Scotti
 *  @package    es.rimsky
	_____________________________________________
*/

$(document).ready
(
	function()
	{
		
		var browser = new Browser();
		var browserName = browser.getName();

		var pathName = location.pathname;		
		var pageName = pathName.slice(pathName.lastIndexOf("/")+1);
		
		var pageColorHex;
		
		swfobject.embedSWF ('swf/logo_animation.swf', 	"logo",   "478", "103", "9.0.0", "swf/expressInstall.swf", false, {}, {});
//		swfobject.embedSWF ('swf/NavBar.swf',			"navBar", "520", "103", "9.0.0", "swf/expressInstall.swf", false, {wmode:"transparent"}, {wmode:"transparent"});


		//FIND PAGE's COLOR
		var findPageColor = function(result)
		{
			$(result).find('button').each
			(
				function()
				{
					var itemUrl = $(this).find("url").text();
					if(pageName == "") pageName = "index.php";
					if(itemUrl == pageName)
					{
						var _pColor = $(this).attr("color");
						pageColorHex = _pColor;
						pageColorHTML = "#" + String(_pColor).substring(2);
						//console.log("COLOR: " + pageColor);
					}
				}
			);
		}

		$.ajax({url:'xml/navigationData.xml', type:"GET", async: false, dataType: 'xml', success: findPageColor});


		switch(browserName)
		{
			case Browser.FIREFOX:
				$('#categoryButtonListContainer').css({ position : "fixed" });
			case Browser.SAFARI:
				$('#fondoPattern').css ({	top :"-2px"		});
			break;
			case Browser.MSIE:
				$('#fondoPattern').css({	top : "0px", marginLeft : "547px"	});
				swfobject.embedSWF( 'swf/cuadradoGrande.swf', "cuadradoGrandeFlash", "290", "570", "9.0.0", "swf/expressInstall.swf", false, {wmode:"transparent"}, {wmode:"transparent"});
				swfobject.embedSWF( 'swf/cuadrado.swf', 	  "cuadradoFlash", 		 "175", "380", "9.0.0", "swf/expressInstall.swf", {pageColor:pageColorHex}, {wmode:"transparent"}, {wmode:"transparent"});
			break;
		}
		
		if(pageName == "index2.php" || pageName == "index.php" || pageName == "")
			swfobject.embedSWF ("swf/CategoryList.swf", "categoryButtonList", "145", "400", "9.0.0", "swf/expressInstall.swf", false, {wmode:"transparent"}, {wmode:"transparent"});

		if(browser.isIE6() == false)
		{
			setTimeout
			(
				function()
				{
					swfobject.embedSWF ("swf/cuadradoLeft.swf", "cuadradoFlashLeft", "195", "450", "9.0.0", "swf/expressInstall.swf", {pageColor: pageColorHex}, {wmode:"transparent"}, {wmode:"transparent"});
				}, 2000
			);
		}

		var textsData = {};
		
		switch(pageName)
		{
			case "":
			case "index.php":
			case "works.php":
				$.ajax({url:'src/es/rimsky/sections/Works.js', type:"GET", async: false, dataType: 'script'});
				textsData.sectionID = "work";
				setTimeout(function(){Works.changeCategory(-1)}, 1500);
			break;
			case "philo.php":
				textsData.sectionID = "philo";
			break;
			case "fun.php":
				$.ajax({url:'src/es/rimsky/sections/Works.js', type:"GET", async: false, dataType: 'script'});
				textsData.sectionID = "fun";
				setTimeout(function(){Works.changeCategory(17)}, 1500);
			break;
			case "contact.php":
				textsData.sectionID = "contact";
			break;
		}
		
		//LOAD INTRO's TEXTS
		$.ajax
		(
			{
				url: 'src/es/rimsky/texts/Texts.php',
				dataType: "xml",
				data: textsData,
				cache: false,
				type: "GET",
				success: onLoadTexts
			}
		);

	}
);

function onLoadTexts(XMLHttpRequest)
{
	$(XMLHttpRequest).find('intro').each
	(
		function()
		{
			$(".intro").html('<span style="font-style:italic">'+$(this).text()+'</span>');
		}
	);
}