package {

	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.geom.Rectangle;
	import flash.media.Sound;



	import flash.events.*;

	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;

	import flash.media.SoundChannel;
	import flash.media.SoundTransform;

	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.net.URLVariables;
	import flash.net.URLRequestMethod;


	import flash.system.Capabilities;
	import flash.utils.Timer;

	import flash.media.SoundChannel;
	import flash.media.SoundTransform;

	import caurina.transitions.Tweener;
	import caurina.transitions.properties.FilterShortcuts;

	import tm.com.*;
	import gs.easing.*;
	import gs.*;
	import caurina.transitions.Tweener;


	public class Main extends MovieClip {

		private var quality:Number = 1;

		//private var _root = root as MovieClip;
		//private var _parent = parent as MovieClip;

		public var logoPic1X:Number = 0;
		public var logoPic1Y:Number = 0;
		public var logoPic2X:Number = 0;
		public var logoPic2Y:Number = 0;
		
		private var pcent:Number;
		private var xmlURL:String = 'xml/main.xml';
		private var titleFormXML:String="xml/formConfiguration.xml";

		private var pcentXML:Number;
		public var websiteXML:XML;
		public var confXML:XML;
		public var xmlLoader:URLLoader;

		public var linkPage:Number = 100;
		public var numGallImages:Number = 0;
		public var k1:Number = 1;
		public var ACT:Number = 0;
		public var animDesc:Number = 1;
		

		private var rectangle:Rectangle;
		private var rectangle_X:Rectangle;
		private var clicked:DisplayObject;
		private var kk:Number;
		
		private var kk_X:Number;
		
		public var picURL:URLRequest;
		public var picLoader:Loader;
		
		public var xmlFormLoader:URLLoader;
		public var request:URLRequest;
		public var variables:URLVariables;
		public var formItems:Array = [];
		
		private var soundTitle:Boolean = true;
		private var closeSplash:Boolean = false;
		
		private var st:SoundTransform = new SoundTransform();
		public var animation:Boolean = true;
		public var openSpashPage:Boolean = false;
		
		public var _root:MovieClip;
		
		// -------------------  Slide Show vars --------------------------
		
		public var animationSh:Boolean = true;
		public var PlaySh:Number = 1;
		public var maskMov:Boolean = false;
		// -------------------  Slide Show vars --------------------------
		
		
		
		private var wellScroll:Boolean;
		private var once:Boolean = true;
		private var footerDown:Boolean = false;
		
		
		



		public function Main(param:MovieClip) {
			
			_root = param;
			//trace("BeginLoadXml")

			xmlLoader = new URLLoader();

			xmlLoader.addEventListener(Event.COMPLETE, showXML);
			xmlLoader.addEventListener(ProgressEvent.PROGRESS, traceLoaderXML);

			xmlLoader.load(new URLRequest(xmlURL));
			XML.ignoreWhitespace = true;

			function traceLoaderXML(eventXML:ProgressEvent) {
				pcentXML = int(eventXML.bytesLoaded / eventXML.bytesTotal * 100);
				MovieClip(root).xml_load.thisText.text = 'Loading XML';
				MovieClip(root).xml_load.thisText.autoSize = TextFieldAutoSize.CENTER;
				//trace(pcentXML);
			}
			function showXML(e:Event):void {
				websiteXML = new XML(e.target.data);
				MovieClip(root).gotoAndPlay(3);
				//trace(websiteXML);
				popupFunction();
			}
		}
		
		

		public function ShowContr(namePanel:MovieClip){
			
				namePanel.buttonMode = false;
				namePanel.addEventListener(MouseEvent.ROLL_OVER, mouseOverButton);
				namePanel.addEventListener(MouseEvent.ROLL_OUT, mouseOutButton);
				namePanel.addEventListener(MouseEvent.CLICK, clicButton);
				
				
		
				function mouseOverButton(e:MouseEvent) {
					if (linkPage == 0) {
						MovieClip(namePanel.parent).b2.startDrag(true);
	                    MovieClip(namePanel.parent).b2.gotoAndPlay("s1");
					}
				}
				
				function mouseOutButton(e:MouseEvent) {
					if (linkPage == 0) {
						MovieClip(namePanel.parent).b2.stopDrag();
	                    MovieClip(namePanel.parent).b2.gotoAndPlay("s2");
					}
				}
				
				function clicButton(e:MouseEvent) {
					
					if (linkPage == 0) {
					MovieClip(namePanel.parent).b2.startDrag(true);
						
					if(PlaySh == 1){
					animationSh = false;
					MovieClip(namePanel.parent).b2.txt_b.b1.gotoAndStop(2);
					}
					
					if(PlaySh == 0){
					animationSh = true;
					MovieClip(namePanel.parent).bigImages.play();
					MovieClip(namePanel.parent).b2.txt_b.b1.gotoAndStop(1);
					}
					
					}
					
				
				}
		
		
			}
		
		// Buttons control
		
		
		
		
		
		public function settingsText(textField:TextField, nameText:String) {

			textField.htmlText = websiteXML.settings.item.(@name == nameText);
			textField.addEventListener( TextEvent.LINK, textLinkClick );

		}
		
		
		
		public function MouseMooveFunc(mc:MovieClip) {

			stage.addEventListener(MouseEvent.MOUSE_MOVE,gotoXY);
			function gotoXY(e:MouseEvent):void {
				TweenLite.to(mc, 1, { x: int(MovieClip(root).mouseX)-148, y: int(MovieClip(root).mouseY)-122, ease:Expo.easeOut } );
			}

		}
	
			
		
		
		public function popupFunction() {

			addEventListener( 'switchPage', onSwitchPage);
			addEventListener( 'switchPopup', onSwitchPopup);
			addEventListener( 'privacy', onSwitchPrivacy);
			addEventListener( 'fullScren', fullScrenButton);
			

			function onSwitchPage(event:TemplateEvent):void {
				var targetPage:Number = event.info[0];				
				_root.allContent.subMenu['itemButton_' + linkPage].gotoAndPlay('s2');
				linkPage = targetPage;
				_root.allContent.subMenu['itemButton_' + linkPage].gotoAndPlay('s1');
				_root.allContent.play();
			}
			
			function onSwitchPopup(event:TemplateEvent):void {
				var targetPage:Number = event.info[0];
				
				_root.popapPage.popapTitle = websiteXML.pages.titlePage[linkPage].pagePopup.popup[targetPage].item.(@name == "title");
				_root.popapPage.popapInfo = websiteXML.pages.titlePage[linkPage].pagePopup.popup[targetPage].item.(@name == "linkText");
				
				_root.popapPage.gotoAndPlay('open');	
			}
			
			function onSwitchPrivacy(event:TemplateEvent):void {
				var targetPage:Number = event.info[0];
				
				_root.popapPage.popapTitle = websiteXML.section.(@name == "privacyPolicy").item.(@name == "pageTitle");
				_root.popapPage.popapInfo = websiteXML.section.(@name == "privacyPolicy").item.(@name == "pageText");
				
				_root.popapPage.gotoAndPlay('open');

				if (_root.program.animationSh == true) {
					_root.program.animationSh = false;
				}
			}
			
			function fullScrenButton(event:TemplateEvent):void {		
				
				if (stage.displayState==StageDisplayState.NORMAL) {
					stage.displayState=StageDisplayState.FULL_SCREEN;
				} else {
					stage.displayState=StageDisplayState.NORMAL;
				}
		
			}
			
		}
		
		
		
		
			public function openImagesPopap(numOpenPopu:Number) {
			
				_root.popapPage.popapTitle = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numOpenPopu].item.(@name == "title");
				_root.popapPage.popapInfo = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numOpenPopu].item.(@name == "linkText");
				
				_root.popapPage.gotoAndPlay('open');

			}
		
		
		
		
		
		public function textLinkClick( event:TextEvent ):void {
			var tEvent:TemplateEvent=TemplateUtils.getTEventFromString(event.text,true);
			if (tEvent) {
				dispatchEvent( tEvent );
			}
		}
		
		public function buttonNameSplash(textField:TextField, numButton:Number, numTextField:Number) {
			textField.htmlText = websiteXML.menuSplash.button[numButton].titleButton[numTextField].text();
		}
		

		public function buttonNameGall(textField:TextField, numButton:Number) {
			textField.htmlText = websiteXML.menu_gallery.button[numButton].text();
		}
		
		public function buttonNameGallOver(textField:TextField, numButton:Number) {
			textField.htmlText = websiteXML.menu_gallery_over.button[numButton].text();
		}
		
		public function buttonName(textField:TextField, numButton:Number) {
			textField.htmlText = websiteXML.menu.button[numButton].text();
		}
		
		public function buttonName_footer(textField:TextField, numButton:Number) {
			textField.htmlText = websiteXML.menu_footer.button[numButton].text();
		}
		
		
		public function buttonName_over(textField:TextField, numButton:Number) {

			textField.htmlText = websiteXML.menu_over.button[numButton].text();

		}
		
		// Buttons control
		
		
		
		public function movButton(nameButton:MovieClip , xPoz:Number, yPoz:Number, t:Number, delt:Number):void {
			
			
			Tweener.addTween(nameButton, { x:xPoz, y:yPoz, time:t, delay:delt, transition:"easeOutElastic" } );
			

		}
		
		
		
		
		
		
		public function ch_pageMouseButton(namePanelMouse:MovieClip, startPlay:String, endPlay:String,numButton:Number){


			namePanelMouse.buttonMode = true;
		    namePanelMouse.addEventListener(MouseEvent.ROLL_OVER, mouseOverButton);
			namePanelMouse.addEventListener(MouseEvent.ROLL_OUT, mouseOutButton);

			namePanelMouse.addEventListener(MouseEvent.CLICK, clicButton);

			function mouseOverButton(e:MouseEvent) {
			
			
					if (linkPage !== numButton){
						MovieClip(namePanelMouse.parent).gotoAndPlay("s1");
					}
				}

				function mouseOutButton(e:MouseEvent) {
					if (linkPage !== numButton){
						MovieClip(namePanelMouse.parent).gotoAndPlay("s2");
					}
				}

			function clicButton(e:MouseEvent) {	
				if (linkPage !== numButton && animation) {
					
					//MovieClip(namePanelMouse.parent)['itemButton_' + linkPage].gotoAndPlay("s2");
					//linkPage = numButton;
				   // MovieClip(root).chPages.gotoAndPlay("s1");
				   _root.num_img = 0;
					   
						if (linkPage == 0) {
							//MovieClip(root).chPages.gotoAndPlay("s1");  
							MovieClip(root).chPages.play();  
	                    }
						
						if (linkPage !== 100) {
							MovieClip(namePanelMouse.parent.parent)['itemButton_' + linkPage].gotoAndPlay("s2");
							//MovieClip(root).chPages.gotoAndPlay("s2");  
							MovieClip(root).chPages.play();  
	                    }
						
						linkPage = numButton;
					
				
				}

			}
		}
		
		
		
		
		
		
		
		
		public function pageMouseButtonSpash(namePanel:MovieClip, startPlay:String, endPlay:String,numButton:Number){
			
				namePanel.buttonMode = true;
				namePanel.addEventListener(MouseEvent.ROLL_OVER, mouseOverButton);
				namePanel.addEventListener(MouseEvent.ROLL_OUT, mouseOutButton);

				namePanel.addEventListener(MouseEvent.CLICK, clicButton);
		

				function mouseOverButton(e:MouseEvent) {
					if (linkPage !== numButton){
						MovieClip(namePanel.parent).gotoAndPlay(startPlay);
					}
				}

				function mouseOutButton(e:MouseEvent) {
					if (linkPage !== numButton){
						MovieClip(namePanel.parent).gotoAndPlay(endPlay);
					}
				}

				function clicButton(e:MouseEvent) {
					if (linkPage !== numButton && animation==true) {						
							MovieClip(root).subMenu['itemButton_' + linkPage].gotoAndPlay("s2");
							MovieClip(root).MainScroll.dynamic_page_content.all.allContentMovie.footer.subMenu['itemButton_' + linkPage].gotoAndPlay("s2");
							
							//MovieClip(namePanel.parent.parent)['itemButton_' + linkPage].gotoAndPlay("s2");
							numGallImages = 0;
							linkPage = numButton;
							if(MovieClip(root).subMenu['itemButton_' + linkPage].over_flag==0) {
								MovieClip(root).subMenu['itemButton_' + linkPage].gotoAndPlay("s1");
							}
							MovieClip(root).MainScroll.dynamic_page_content.all.allContentMovie.footer.subMenu['itemButton_' + linkPage].gotoAndPlay("s1");
							_root.MainScroll.dynamic_page_content.all.play();						
						}
						
					}
				}
				
				
				
				
				
				
				
				public function pageMouseButtonGallery(namePanel:MovieClip, startPlay:String, endPlay:String,numButton:Number){
			
				namePanel.buttonMode = true;
				namePanel.addEventListener(MouseEvent.ROLL_OVER, mouseOverButton);
				namePanel.addEventListener(MouseEvent.ROLL_OUT, mouseOutButton);

				namePanel.addEventListener(MouseEvent.CLICK, clicButton);
		

				function mouseOverButton(e:MouseEvent) {
					//if (MovieClip(root).gallery_category_num !== numButton){
						MovieClip(namePanel.parent).gotoAndPlay(startPlay);
					//}
				}

				function mouseOutButton(e:MouseEvent) {
					//if (MovieClip(root).gallery_category_num !== numButton){
						MovieClip(namePanel.parent).gotoAndPlay(endPlay);
					//}
				}

				function clicButton(e:MouseEvent) {
					//if (MovieClip(root).gallery_category_num !== numButton && _root.gallery_flag_animation==true) {						
						//MovieClip(namePanel.parent.parent)['itemButton_' + MovieClip(root).gallery_category_num].gotoAndPlay("s2");
						MovieClip(root).gallery_category_num = numButton;		
						//_root.all_gallery.all_pics.small_pics.gotoAndPlay("s1");
						//_root.all_gallery.gotoAndPlay("s1");
						MovieClip(root).gallery_num_pic_in_category_num=0;
						MovieClip(root).program.numGallImages=0;
						//MovieClip(root).all_gallery.all_pics.gallery.gall_spl.gotoAndPlay("start");
						}
					//}
				}
		
		
		
		
		
		
		
		
		
			
		
		public function textContent(nameText:TextField, numText:Number) {
			nameText.htmlText = websiteXML.pages.titlePage[linkPage].texts.pageText[numText].text();
			nameText.addEventListener( TextEvent.LINK, textLinkClick );
			nameText.condenseWhite = true;

		}
		
		
		public function textContentSplash(nameText:TextField, numText:Number) {
			nameText.htmlText = websiteXML.pages.titlePage[1].texts.pageText[numText].text();
			nameText.addEventListener( TextEvent.LINK, textLinkClick );
			nameText.condenseWhite = true;

		}
		
		
		public function textContentGall_descr(nameText:TextField, numText:Number) {
			nameText.htmlText = websiteXML.settings.imagesPage.imagesGallery[MovieClip(root).gallery_category_num].pageText[numText].text();
			nameText.addEventListener( TextEvent.LINK, textLinkClick );
			nameText.condenseWhite = true;

		}
		
		public function textContentGallSplash2(nameText:TextField) {
				nameText.htmlText = websiteXML.settings.imagesPage.imagesGallery[MovieClip(root).gallery_category_num].pageText[MovieClip(root).gallery_num_pic_in_category_num].text();
				nameText.addEventListener( TextEvent.LINK, textLinkClick );
				nameText.condenseWhite = true;
			}
			
		
	
		
		



		
		
		public function contentScroll2(nameScrollMovie_scroll2:MovieClip, nameContent_scroll2:MovieClip,nameLine_scroll2:MovieClip,stepContentHeight_scroll2) {

			function deact() {
				var par:MovieClip = parent as MovieClip;
				nameScrollMovie_scroll2.visible = false;
				nameLine_scroll2.visible = false;
				Tweener.removeTweens(nameContent_scroll2);
				par.removeEventListener(MouseEvent.MOUSE_WHEEL, mouse_well);
			}

			deact();

			var d_C_scroll2=nameContent_scroll2.height+stepContentHeight_scroll2;

			nameScrollMovie_scroll2.y=nameScrollMovie_scroll2.y;
			nameContent_scroll2.y = nameContent_scroll2.y;

			if (nameContent_scroll2.height>nameLine_scroll2.height) {
				kk=d_C_scroll2/Math.round(nameLine_scroll2.height-nameScrollMovie_scroll2.height);
				rectangle = new Rectangle(nameLine_scroll2.x+1, 0, 0, Math.round(nameLine_scroll2.height - nameScrollMovie_scroll2.height));
				nameScrollMovie_scroll2.addEventListener(MouseEvent.MOUSE_DOWN, scroll_drag);
				nameScrollMovie_scroll2.buttonMode=true;
				var par:MovieClip = parent as MovieClip;
				par.addEventListener(MouseEvent.MOUSE_WHEEL, mouse_well);
				stage.addEventListener(MouseEvent.MOUSE_UP, scroll_drag_stop);
				stage.addEventListener(MouseEvent.MOUSE_UP, captureMouseUp, true);
				nameScrollMovie_scroll2.visible = true;
				nameLine_scroll2.visible = true;
			} else {
				nameScrollMovie_scroll2.visible = false;
				nameLine_scroll2.visible = false;
			}



			function scroll_drag(event:MouseEvent):void {
				nameScrollMovie_scroll2.addEventListener(Event.ENTER_FRAME, scroll_move);
				nameScrollMovie_scroll2.startDrag(false, rectangle);
			}
			function scroll_drag_stop(event:MouseEvent):void {
				nameScrollMovie_scroll2.removeEventListener(Event.ENTER_FRAME, scroll_move);
				nameScrollMovie_scroll2.stopDrag();
			}
			function scroll_move(e:Event=null):void {
				var d_scroll:int = Math.round((nameScrollMovie_scroll2.y)*kk);
				Tweener.removeTweens(nameContent_scroll2);
				Tweener.addTween(nameContent_scroll2,{y:(d_scroll*-1), time:1, transition:"easeOutQuart"});
			}
			function mouse_well(e:MouseEvent) {
				if (nameContent_scroll2.hitTestPoint(mouseX,mouseY,false)){
					var a:Number=nameScrollMovie_scroll2.y;
					a-=e.delta*4;
					if (a<rectangle.y) {
						a=rectangle.y;
					}
					if (a>rectangle.y+rectangle.height) {
						a=rectangle.y+rectangle.height;
					}
					nameScrollMovie_scroll2.y=a;
					scroll_move();
				}
			}
			function captureMouseUp(evt:MouseEvent):void {
				if (evt.eventPhase==EventPhase.BUBBLING_PHASE) {
					return;
				}
				if (clicked==nameScrollMovie_scroll2) {
					clicked=null;
					var target:Sprite=evt.target as Sprite;
					if (target==nameScrollMovie_scroll2) {
						scroll_drag_stop(evt);
					} else {
						scroll_drag_stop(evt);
					}
				}
			}
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		//---------------------------------------------------------------------------------------------------------------------------------
				public function contentScroll_X(nameScrollMovie_X:MovieClip, nameContent_X:MovieClip,nameLine_X:MovieClip,stepContentWidth) {

			function deact_X() {
				nameScrollMovie_X.visible = false;
				nameLine_X.visible = false;
				Tweener.removeTweens(nameContent_X);
				removeEventListener(MouseEvent.MOUSE_WHEEL, mouse_well);
			}

			deact_X();

			var d_C_X=nameContent_X.width+stepContentWidth;

			nameScrollMovie_X.x=nameScrollMovie_X.x;
			nameContent_X.x = nameContent_X.x;

			if (nameContent_X.width>nameLine_X.width) {
				kk_X = d_C_X / Math.round(nameLine_X.width - nameScrollMovie_X.width);
				//trace(kk_X );
				rectangle_X = new Rectangle(nameLine_X.x+0, 0, Math.round(nameLine_X.width - nameScrollMovie_X.width), 0);
				nameScrollMovie_X.addEventListener(MouseEvent.MOUSE_DOWN, scroll_drag_X);
				nameScrollMovie_X.buttonMode=true;
				addEventListener(MouseEvent.MOUSE_WHEEL, mouse_well);
				stage.addEventListener(MouseEvent.MOUSE_UP, scroll_drag_X_stop);
				stage.addEventListener(MouseEvent.MOUSE_UP, captureMouseUp, true);
				nameScrollMovie_X.visible = true;
				nameLine_X.visible = true;
			} else {
				nameScrollMovie_X.visible = false;
				nameLine_X.visible = false;
			}



			function scroll_drag_X(event:MouseEvent):void {
				nameScrollMovie_X.addEventListener(Event.ENTER_FRAME, scroll_move);
				nameScrollMovie_X.startDrag(false, rectangle_X);
			}
			function scroll_drag_X_stop(event:MouseEvent):void {
				nameScrollMovie_X.removeEventListener(Event.ENTER_FRAME, scroll_move);
				nameScrollMovie_X.stopDrag();
			}
			function scroll_move(e:Event=null):void {
				var d_scroll_X:int = Math.round((nameScrollMovie_X.x)*kk_X);
				Tweener.removeTweens(nameContent_X);
				Tweener.addTween(nameContent_X,{x:(d_scroll_X*-1), time:1, transition:"easeOutQuart"});
			}
			function mouse_well(e:MouseEvent) {
				if (nameContent_X.hitTestPoint(mouseX,mouseY,true)){
					var a_X:Number=nameScrollMovie_X.x;
					a_X-=e.delta;
					if (a_X<rectangle_X.x) {
						a_X=rectangle_X.x;
					}
					if (a_X>rectangle_X.x+rectangle_X.width) {
						a_X=rectangle_X.x+rectangle_X.width;
					}
					nameScrollMovie_X.x=a_X;
					scroll_move();
				}
			}
			function captureMouseUp(evt:MouseEvent):void {
				if (evt.eventPhase==EventPhase.BUBBLING_PHASE) {
					return;
				}
				if (clicked==nameScrollMovie_X) {
					clicked=null;
					var target:Sprite=evt.target as Sprite;
					if (target==nameScrollMovie_X) {
						scroll_drag_X_stop(evt);
					} else {
						scroll_drag_X_stop(evt);
					}
				}
			}
		}
		
		
		
		
		
		
		
		
public function contactFormAction(form:MovieClip,clearButton:MovieClip,sendButton:MovieClip,maxTitleText:Number):void {

			var iForm:Number = 0;
			clearButton.thisText.htmlText = websiteXML.pages.titlePage[5].texts.contatcForm.button.text[0].text();
			sendButton.thisText.htmlText = websiteXML.pages.titlePage[5].texts.contatcForm.button.text[1].text();
			
			clearButton.thisText.autoSize = TextFieldAutoSize.CENTER;
			sendButton.thisText.autoSize = TextFieldAutoSize.CENTER;
			clearButton.addEventListener( MouseEvent.CLICK, clearClick );
			


			while (iForm <= maxTitleText) {
				//form['NameformItem_' + iForm].htmlText = websiteXML.pages.titlePage[5].texts.contatcForm.titleTextForm.textForm[iForm].text();

			//	form['NameformItem_' + iForm].restrict = '^a-z';
			//	form['NameformItem_' + iForm].autoSize = TextFieldAutoSize.LEFT;
				form['formItem_' + iForm].addEventListener( FocusEvent.FOCUS_IN, onFormItemFocusIn);
				form['formItem_' + iForm].addEventListener( FocusEvent.FOCUS_OUT, onFormItemFocusOut);
				form['formItem_' + iForm].htmlText = websiteXML.pages.titlePage[5].texts.contatcForm.titleTextForm.textForm[iForm].text();
				
				formItems[ iForm ] = websiteXML.pages.titlePage[5].texts.contatcForm.titleTextForm.textForm[iForm].text();
				//trace(formItems);
				iForm++;
			}
			
			xmlFormLoader= new URLLoader();
			xmlFormLoader.addEventListener(Event.COMPLETE, showformXML);
			xmlFormLoader.load(new URLRequest(titleFormXML));
			XML.ignoreWhitespace = true;
			
			function showformXML(e:Event) {
			confXML = new XML(xmlFormLoader.data);
			sendButton.addEventListener( MouseEvent.CLICK, sendClick );
		
			}
			
/////////////////////////////SENDCLICK/////////////////////////////////////////////			
		function sendClick( event:MouseEvent ):Boolean	{			
			
			form.formMessage.text = "";

			if (stage.displayState==StageDisplayState.FULL_SCREEN) {
					
					//stage.displayState=StageDisplayState.NORMAL;
					form.formMessage.text = confXML.exitFullScreenMsg;
			} 
			
			
			var iForm:uint = 0;
			var notValidated:Boolean = false;
			while (iForm <= maxTitleText) {
				
				var error:String = validateFields(iForm);
				if (error != ""){
						form.formMessage.text = error;
						notValidated = true;
						break;
					}
				iForm++;
			}
			
			
			if ( confXML && !notValidated ) {
				form.formMessage.text=confXML.formProcessingText;
						var formData:Array = new Array();

						formData.push( { key: "Full Name", value: form['formItem_' + 0].text, id : 0 } );
						formData.push( { key: "Mail", value: form['formItem_' + 1].text, id : 1 } );
						formData.push( { key: "Phone", value: form['formItem_' + 2].text, id : 2 } );
						formData.push( { key: "Message", value: form['formItem_' + 3].text, id : 2 } );
						
						var variables:URLVariables = new URLVariables();
				var loader:URLLoader = new URLLoader();
				loader.addEventListener( Event.COMPLETE, onServerResponse );
				loader.addEventListener(IOErrorEvent.IO_ERROR, onServerError);

				var mailFromId : Number = Number( confXML.emailFromSource );
				if( mailFromId && mailFromId > 0 ) {
					variables['mail_from'] = formData[ mailFromId ]['value'];
				} else {
					variables['mail_from'] = confXML.emailFromSource;
				}
				var mailSubjectId : Number = Number( confXML.subjectSource );
				if(mailSubjectId && mailSubjectId > 0) {
					variables['mail_subject'] = formData[ mailSubjectId ]['value'];
				} else {
					variables['mail_subject'] = confXML.subjectSource;
				}
				var mailToId : Number = Number( confXML.emailTo.valueOf().toString() );
				if(mailToId && mailToId > 0) {
					variables['mail_to'] = formData[mailToId]['value'];
				} else {
					variables['mail_to'] = confXML.emailTo;
				}
				variables['plain_text'] = confXML.plainText;
				variables['smtp_server'] = confXML.smtpServer;
				variables['smtp_port'] = confXML.smtpPort;


				for( var j:Number=formData.length-1; j>=0; j-- ) {
					variables[ formData[j]['key'] ] = formData[j]['value'];
				}

				var handlerFilePath:String = confXML.serverProcessorFileName.valueOf().toString() + '.' + confXML.serverProcessorType.valueOf().toString();
				var request:URLRequest = new URLRequest( handlerFilePath );
				request.method = URLRequestMethod.POST;
				request.data = variables;

				try
				{
				    loader.load(request);
				}
				catch (error:Error)
				{
				    trace( 'Unable to load URL' );
				}
			}
			
			return true;
			
		}
		
	function validateFields(formItem:Number):String{
		
		var iFormClear:Number = 0;
		var oPatterns:Object = {"text":"^[ !@#$%^&*()+=/\a-z0-9_-]+$", "e-mail":"^([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([a-z\.]{2,6})$", "digits":"^[0-9_-]+$"};
		var oErrorMessages:Object = {"empty":confXML.validationMessages.empty, "text":confXML.validationMessages.ntext, "e-mail":confXML.validationMessages.email, "digits":confXML.validationMessages.digits};
		//trace("ok");
		var isRequired:String = websiteXML.pages.titlePage[5].texts.contatcForm.fieldsValidationTypes.validationType[formItem].@required;
			
		
			if((isRequired == "true") && (form['formItem_' + formItem].text == "")) {return oErrorMessages["empty"];}
			else if (form['formItem_' + formItem].text != "") {
				
				if (websiteXML.pages.titlePage[5].texts.contatcForm.fieldsValidationTypes.validationType[formItem].text() != "no")
				{
					var pattern:RegExp = new RegExp(oPatterns[websiteXML.pages.titlePage[5].texts.contatcForm.fieldsValidationTypes.validationType[formItem].text()], "i");
					
					var txt:String = form['formItem_' + formItem].text;
				
					var ar:Array = txt.match(pattern);
	
					if (ar == null){
					
						return oErrorMessages[websiteXML.pages.titlePage[5].texts.contatcForm.fieldsValidationTypes.validationType[formItem].text()];
					
					}
				}
			}
			return "";
		}
////////////////////////////////RESET///////////////////////////////////
	function clearClick():void {
				var iFormClear:Number=0;
				while (iFormClear<=maxTitleText) {
					form['formItem_' + iFormClear].htmlText = '';
					form['formItem_'+iFormClear].htmlText = websiteXML.pages.titlePage[5].texts.contatcForm.titleTextForm.textForm[iFormClear].text();
					form.formMessage.text='';
					iFormClear++;
				}
			}
/////////////////////////////////////////////////////////////////
	function onServerResponse( event:Event ):void	{
			var loader:URLLoader = URLLoader( event.target );
		
			try {
				if ( Number( XML( loader.data ).mail ) == 1 || XML( loader.data ).mail == "1" ) {
					form.formMessage.text = confXML.messageSentText;
				} else {
					form.formMessage.text = confXML.messageSentFailedText;
				}
			} catch( error:Error ) {
				form.formMessage.text = confXML.messageSentFailedText;
			}
		}

	function onServerError(event:Event):void	{
			form.formMessage.text = confXML.messageSentFailedText;
		}
	
function onFormItemFocusIn( event:FocusEvent ):void {
				var formItem:TextField=event.target as TextField;
				var formItemID:uint = uint(formItem.name.slice(formItem.name.lastIndexOf('_') + 1, formItem.name.length));
		
				if (formItem.text==formItems[formItemID]) {
					formItem.text='';
				}
				if (stage.displayState==StageDisplayState.FULL_SCREEN) {
					
					form.formMessage.text = confXML.exitFullScreenMsg;
				} 

				
				
			}
			
	function onFormItemFocusOut( event:FocusEvent ):void {
			
				var sError:String = validateFields(formItemID);
	
					var formItem:TextField=event.target as TextField;
				var formItemID:uint=uint(formItem.name.slice(formItem.name.lastIndexOf('_')+1,formItem.name.length));
				if (formItem.text=='') {
					formItem.text=formItems[formItemID];
				}	
				
				if (sError != ""){
					
						form.formMessage.text = sError;
						
					} else {form.formMessage.text = ""};
					
			}	
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		public function soundControll(nameButton:MovieClip) {
			
			nameButton.buttonMode = true;
			
			nameButton.addEventListener(MouseEvent.CLICK, clicButton);
			
			
			
			function clicButton(e:MouseEvent) {		
				
				if (soundTitle) {				
									
					MovieClip(nameButton.parent).gotoAndStop('off');
					soundTitle = false;
					Tweener.addTween(st, {
						volume:0,
						time:2,
						onUpdate: updateSoundVolume } );
						
				}else {
					
					MovieClip(nameButton.parent).gotoAndStop('on');
					soundTitle = true;
					Tweener.addTween(st, {
						volume:1,
						time:2, onUpdate: 
						updateSoundVolume} );
					
				}
			
			}			
			
			function updateSoundVolume():void {
				MovieClip(root).soundTransform=st;
			}
			
			
		}
		
		
		
		
		
		
		
		
		
		
		
		
		public function loopMouse(movieClip:MovieClip,stepMouse:Number){
		
			
			addEventListener(Event.ENTER_FRAME, mouseWell);
		
			function mouseWell(e:Event){			
			
				var homeX:Number = mouseX/stepMouse;
				var diffX:Number = homeX-movieClip.x;
				var moveX:Number = diffX/stepMouse;
			
				Tweener.addTween(movieClip, {x:moveX, time:1, transition:"easeOutQuart"});
			}
			
		
		}
		
		
		
		public function logoLink(nameMovieClic:MovieClip, closeLink:String):void {
			
			nameMovieClic.buttonMode = false;
			
			nameMovieClic.addEventListener(MouseEvent.CLICK, clicButtonLogo);
			
			function clicButtonLogo(e:MouseEvent) {
				if(linkPage != 1 && animation == true) {
					_root.subMenu['itemButton_' + linkPage].gotoAndPlay('s2');
					MovieClip(root).MainScroll.dynamic_page_content.all.allContentMovie.footer.subMenu['itemButton_' + linkPage].gotoAndPlay("s2");
					linkPage = 1;
					_root.subMenu['itemButton_' + linkPage].gotoAndPlay('s1');
					MovieClip(root).MainScroll.dynamic_page_content.all.allContentMovie.footer.subMenu['itemButton_' + linkPage].gotoAndPlay("s1");
					animation= false;
					//_root.allContent.play();
					_root.MainScroll.dynamic_page_content.all.play();
				}
				
			}
		}
		
		
		
		
		
		
public function onSwitchPopupSite(num_popup:Number):void {
			_root.popapPage.popapTitle = websiteXML.pages.titlePage[linkPage].pagePopup.popup[num_popup].item.(@name == "title");
			_root.popapPage.popapInfo = websiteXML.pages.titlePage[linkPage].pagePopup.popup[num_popup].item.(@name == "linkText");
			_root.popapPage.gotoAndPlay('open');	
		}
		
public function onSwitchPopupMapSite(num_popup:Number):void {
		_root.popapMap.popapTitle = websiteXML.section.(@name == "popupMap").item.(@name == "pageTitle");
		_root.popapMap.gotoAndPlay('open');
	}		
		
		
public function textRMContent (nameText:TextField, numText:Number) {

			nameText.htmlText = websiteXML.pages.titlePage[linkPage].texts.readMoreText[numText].text();
			nameText.addEventListener( TextEvent.LINK, textLinkClick );
			nameText.mouseWheelEnabled = false;
			nameText.condenseWhite = true;

		}		
		
		
public function readMoreButton(namePanel:MovieClip, startPlay:String, endPlay:String, numButton:Number) {
	var url_RM:String=websiteXML.pages.titlePage[linkPage].texts.readMoreText[numButton].@link;
	var urlPage:Number=Number(websiteXML.pages.titlePage[linkPage].texts.readMoreText[numButton].@linkPage);
	var request:URLRequest;

	namePanel.buttonMode = true;
	namePanel.addEventListener(MouseEvent.ROLL_OVER, mouseOverButton);
	namePanel.addEventListener(MouseEvent.ROLL_OUT, mouseOutButton);
	namePanel.addEventListener(MouseEvent.CLICK, clicButton);

	function mouseOverButton(e:MouseEvent) {
			MovieClip(namePanel.parent).gotoAndPlay(startPlay);
	}

	function mouseOutButton(e:MouseEvent) {
			MovieClip(namePanel.parent).gotoAndPlay(endPlay);
	}

	function clicButton(e:MouseEvent) {
		if (url_RM) {
			request = new URLRequest(url_RM);
			navigateToURL(request);
		}else {
			onSwitchPopupSite(urlPage)
		}
	}
}







/*
public function moreClick(numButton:Number) {

	if(MovieClip(root).program.gallery.isPaper){
		if (!isPopup && !animation && !MovieClip(root).program.gallery.animation_pic) {

			isPopup = true;
			animation = true;
			MovieClip(root).coverMovie.gotoAndStop('hide');

			MovieClip(root).popapTitle = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numButton].item.(@name == "title");
			MovieClip(root).popapInfo = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numButton].item.(@name == "linkText");

			if (linkPage !== 7) {
				MovieClip(root).MainScroll.dynamic_page_content.MenuItems['itemButton_' + linkPage].gotoAndPlay("s2");
			}
			var valuePopup:String = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numButton].URLPopupInfo.@popupUrl;
			SWFAddress.setValue(valuePopup);
			
			var statusStr:String = SWFAddress.getValue();
			var nameSite:String = websiteXML.settings.item.(@name == 'nameSite');
			SWFAddress.setTitle("Welcome to " + nameSite + " - " + statusStr.slice(1));

			linkPage_prev = linkPage;
			linkPage = 7;
			numMore = numButton;
			
			if ( !inFirstTimeClosedPaper ) {
					if ( !MovieClip(root).program.gallery.isClosed ) {
					setTimeout(tweenPageFunc, 1800);
					MovieClip(root).program.gallery.closePaper();
				}else {
					tweenPageFunc();
				}
			}else {
				tweenPageFunc();
			}
		}
	}else {
		if (!isPopup && !animation ) {
			isPopup = true;
			animation = true;
			MovieClip(root).coverMovie.gotoAndStop('hide');

			MovieClip(root).popapTitle = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numButton].item.(@name == "title");
			MovieClip(root).popapInfo = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numButton].item.(@name == "linkText");

			if (linkPage !== 7) {
				MovieClip(root).MainScroll.dynamic_page_content.MenuItems['itemButton_' + linkPage].gotoAndPlay("s2");
			}
			var valuePopup_:String = websiteXML.pages.titlePage[linkPage].pagePopup.popup[numButton].URLPopupInfo.@popupUrl;
			SWFAddress.setValue(valuePopup_);
			
			var statusStr_:String = SWFAddress.getValue();
			var nameSite_:String = websiteXML.settings.item.(@name == 'nameSite');
			SWFAddress.setTitle("Welcome to " + nameSite_ + " - " + statusStr_.slice(1));

			linkPage_prev = linkPage;
			linkPage = 7;
			numMore = numButton;
			
			tweenPageFunc();
		}
	}

}
*/







		

		
		public function soundFunction(nameSound:Object, volumeSound:Number) {		
			
			var channel:SoundChannel = nameSound.play();
			var vol:SoundTransform = channel.soundTransform;
			vol.volume = volumeSound;
			channel.soundTransform = vol;
			
			
		}
		
		
		
		
		
		
		public function fullScreenFunction(nameMovieClip:MovieClip, typeMovie:String=null) {
			
			
			var startPageWidth:Number = stage.stageWidth;
			var startPageHeight:Number = stage.stageHeight;
			
			var xPoz:Number = Math.round(stage.stageWidth - nameMovieClip.x);
			var yPoz:Number = Math.round(stage.stageHeight - nameMovieClip.y);
			
			stage.addEventListener(Event.RESIZE, appResizeHandler);


				function appResizeHandler(event:Event):void {

					if (typeMovie == 'center') {
				
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth/2), time:0.7, delay:0.1 } );
						Tweener.addTween(nameMovieClip,{y:Math.round(stage.stageHeight/2), time:0.7, delay:0.1});				
					}
			
					if (typeMovie == 'down') {
				
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth), time:0.7, delay:0.1 } );
						Tweener.addTween(nameMovieClip,{y:Math.round(stage.stageHeight), time:0.7, delay:0.1});				
				
					}
						if (typeMovie == 'downCnter') {
						
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth/2), time:0.7, delay:0.1 } );
						Tweener.addTween(nameMovieClip,{y:Math.round(stage.stageHeight), time:0.7, delay:0.1});		
						
					}
					if (typeMovie == 'upCenter') {
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth/2), time:0.7, delay:0.1 } );						
					}
			
					if (!typeMovie) {
						
						Tweener.addTween(nameMovieClip, { x:(stage.stageWidth - xPoz), time:0.7, delay:0.1 } );						
						Tweener.addTween(nameMovieClip, { y:(stage.stageHeight - yPoz), time:0.7, delay:0.1 } );
						
				
					}
				}
				
				
				
				
				if (typeMovie == 'center') {
				
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth/2), time:0.7, delay:0.1 } );
						Tweener.addTween(nameMovieClip,{y:Math.round(stage.stageHeight/2), time:0.7, delay:0.1});				
					}
			
					if (typeMovie == 'down') {
				
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth), time:0.7, delay:0.1 } );
						Tweener.addTween(nameMovieClip,{y:Math.round(stage.stageHeight), time:0.7, delay:0.1});				
				
					}
						if (typeMovie == 'downCnter') {
						
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth/2), time:0.7, delay:0.1 } );
						Tweener.addTween(nameMovieClip,{y:Math.round(stage.stageHeight), time:0.7, delay:0.1});		
						
					}
					if (typeMovie == 'upCenter') {
						Tweener.addTween(nameMovieClip, { x:Math.round(stage.stageWidth/2), time:0.7, delay:0.1 } );						
					}
			
					if (!typeMovie) {
						
						Tweener.addTween(nameMovieClip, { x:(stage.stageWidth - xPoz), time:0.7, delay:0.1 } );						
						Tweener.addTween(nameMovieClip, { y:(stage.stageHeight - yPoz), time:0.7, delay:0.1 } );
						
				
					}
		}
		
		
	}
}