﻿var winW;
var winH;					
var menuItemHeightLast;							//Menünün son yüksekliği.
var menuItemHeightFirst = 25; 					//Menünün ilk yüksekliği.
var menuItemWidthLast;			 				//Menünün son genişliği.
var winPadd = 20;								//Pencerenin sağından uygulanacak padding değeri.
var interval = 0;								//Animasyon interval.
var slideSpeed = 5000;				    	    //Animasyon loop süresi.
var activeBg = 0;								//Animasyondaki görünür olan bg index'i.
var activeDiv = 1;								//Animasyondaki görünür olan div.
var isEventAdded = false;						//Mouse eventlarının aktif olma durumu //Default false, ancak sayfa  yüklendiğinde event'lar aktif edilip true değerini alıyor.
var activeMenuIndex = -1;						//Aktif menünün index no'su. Varsayılan -1 yani aktif menü yok. Bu durumda imgArray[son] içerisindeki görseller geçerli olur.
var isStoryOpen = false;						//Story modal'ının açık olma durumu.
var isNewsOpen = false;							//Newsletter modal'ının açık olma durumu.
var isOffersOpen = true;						//Offers kutucuğunun görünür olma durumu.
var menuArray = new Array();					//Menü elemanlarının index numaralarının tutulduğu Array.
var hrefArray = new Array();					//Menünün Hash değerlerinin tutulduğu Array.
var fistWidhtArray = new Array();				//Menünün ilk genişlik değerlerinin tutulduğu Array.
var imgArray = new Array ();					//Menülere atanan imajların tutulduğu Array.
var imgW;
var imgH;
var imgRat = 1.77;
var setBgWorkedOnce = false;
var osFix = 0;
var isFirstOpened = false;
var inde;
//var flashObj = null;


var videoHTML = '<script type="text/javascript">swfobject.embedSWF("flash/video.swf", "vPlayer", "370", "256", "9.0.0", "flash/expressInstall.swf",{},{wmode:"transparent"})</script>'

fistWidhtArray = [76,130,88,97,73,89,97,130,110,113];
imgArray[0] = ['images/gallery/Garden-View-Standard-1.jpg','images/gallery/Sea-View-Standard-1.jpg','images/gallery/Junior-Suite-1.jpg','images/gallery/Sea-View-Suite-1.jpg','images/gallery/Villa-Suite-1.jpg']; //SLEEPING
imgArray[1] = ['images/gallery/Eating-and-Drinking-1.jpg','images/gallery/Eating-and-Drinking-2.jpg','images/gallery/Eating-and-Drinking-3.jpg','images/gallery/Eating-and-Drinking-4.jpg','images/gallery/Eating-and-Drinking-5.jpg','images/gallery/Eating-and-Drinking-6.jpg']; //EATING & DRINKING
imgArray[2] = ['images/gallery/Pampering-1.jpg','images/gallery/Pampering-2.jpg','images/gallery/Pampering-3.jpg'];	//PAMPERING
imgArray[3] = ['images/gallery/Sun-and-Sea-1.jpg','images/gallery/Sun-and-Sea-2.jpg','images/gallery/Sun-and-Sea-3.jpg','images/gallery/Sun-and-Sea-4.jpg','images/gallery/Sun-and-Sea-5.jpg']; //SUN AND SEA
imgArray[4] = ['images/gallery/Offers-1.jpg']; //OFFERS
imgArray[5] = ['images/gallery/Occasions-1.jpg','images/gallery/Occasions-2.jpg','images/gallery/Occasions-3.jpg']; //OCCASIONS
imgArray[6] = ['images/gallery/What-We-Do-1.jpg','images/gallery/What-We-Do-2.jpg','images/gallery/What-We-Do-3.jpg']; //WHAT WE DO
imgArray[7] = ['images/gallery/What-Poeople-Say-1.jpg']; //WHAT PEOPLE SAY
imgArray[8] = ['images/gallery/Where-We-Are-1.jpg']; //WHERE WE ARE
imgArray[9] = ['images/gallery/Contacting-Us-1.jpg']; //CONTACTING US
imgArray[10] = ['images/gallery/Story-of-Macakizi-1.jpg']; //STORY OF MAÇAKIZI

imgArray[11] = ['images/gallery/Garden-View-Standard-1.jpg']; //STANDARD ROOMS GARDEN VIEW  //OK
imgArray[12] = ['images/gallery/Sea-View-Standard-1.jpg','images/gallery/Sea-View-Standard-2.jpg','images/gallery/Sea-View-Standard-3.jpg','images/gallery/Sea-View-Standard-4.jpg']; //STANDARD ROOMS SEA VIEW  //OK
imgArray[13] = ['images/gallery/Junior-Suite-1.jpg']; //JUNIOR SUITES //OK
imgArray[14] = ['images/gallery/Sea-View-Suite-4.jpg','images/gallery/Sea-View-Suite-2.jpg','images/gallery/Sea-View-Suite-3.jpg','images/gallery/Sea-View-Suite-1.jpg']; //SEA VIEW SUITES //OK
imgArray[15] = ['images/gallery/Villa-Suite-1.jpg','images/gallery/Villa-Suite-2.jpg']; //VILLA SUITES
imgArray[16] = ['images/gallery/black.jpg']; // NEW ROOMS
imgArray[17] = ['images/gallery/Home-1.jpg','images/gallery/Home-3.jpg','images/gallery/Home-4.jpg','images/gallery/Home-2.jpg','images/gallery/Home-5.jpg','images/gallery/Home-6.jpg']; //DEFAULT IMAGES 


var activePhotoIndex = imgArray.length - 1;

function storyOpen(){if(!isStoryOpen){menuClose();$(".story").fadeToggle("slow",function(){loadImage(imgArray[10][0],10);});isStoryOpen = true;$('#vPlayer').html(videoHTML);}};
function storyClose(){soundOpen();if(isStoryOpen){$(".story").fadeOut(); isStoryOpen = false; $('.video_frame').html('<div id="vPlayer"></div>')}};
function newsOpen(){if(!isNewsOpen){menuClose();$(".news_sub").fadeToggle();isNewsOpen = true;}};
function newsClose(){if(isNewsOpen){$(".news_sub").fadeOut();isNewsOpen = false}};
function addScroll(){$('.scroll-pane').height($('.scroll-pane').parent('div').height()).jScrollPane({showArrows: true})};
function changeHashEmpty(){window.location.hash = ""};
function offersOpen(){if(!isOffersOpen){$(".offers").fadeToggle();isOffersOpen = true;}};
function offersClose(){if(isOffersOpen){$(".offers").fadeOut();isOffersOpen = false}};

<!--Dynamic URL Management-->

//Açılışta kontrol ediliyor..
function soundOpen(){var flashObj = document.getElementById("mPlayer");flashObj.callFlash2();}
function soundClose(){var flashObj = document.getElementById("mPlayer");flashObj.callFlash();}

function controlURL() {	
	var hash = window.location.hash;
	//console.log("hash:"+hash);
	if (hash == " " || hash == "#" || hash == "")	{	
			offersOpen();
			//console.log("1:"+hash);
			if(isStoryOpen){storyClose()};
			if(isNewsOpen){newsClose()};
			if(activeMenuIndex != -1){clickAnimOut(activeMenuIndex)};
			activeMenuIndex = -1;
			document.title = "Maca Kizi – Turkbuku - Bodrum";
			if(setBgWorkedOnce == false){
				//setBg();	
				//clearInterval (interval);			
				loadImage(imgArray[imgArray.length - 1][activeBg], imgArray.length - 1);						
			}
	}else if(hash == "#home"){
			offersOpen();
			//console.log("2:"+hash);
			if(isStoryOpen){storyClose()};
			if(isNewsOpen){newsClose()};
			if(activeMenuIndex != -1){clickAnimOut(activeMenuIndex)};
			activeMenuIndex = -1;
			activeBg = 0;
			//activePhotoIndex = imgArray.length - 1;
			document.title = "Maca Kizi - Turkbuku - Bodrum";
			//setBg();
			/*if(isFirstOpened == false){
				setTimeout("loadImage(imgArray[imgArray.length - 1][activeBg], imgArray.length - 1)", 500);
			}else{*/
				//clearInterval (interval);
				loadImage(imgArray[imgArray.length - 1][activeBg], imgArray.length - 1);			
			//}
	}else if(hash ==  "#story-of-macakizi"){
			offersClose();
			//console.log("3:"+hash);
			if(!isStoryOpen){storyOpen()};
			if(isNewsOpen){newsClose()};
			if(isFirstOpened == false){	
				setTimeout(soundClose, 1000);
			}else{
				soundClose();
			}
			/*var flashObj = null;
			if (navigator.appName.indexOf( "Microsoft" ) != -1){
			   flashObj = window[mPlayer];
			} else {
				flashObj = window.document[mPlayer];
			}
			flashObj.callFlash();*/
			
			//activeMenuIndex = 10;
			//activePhotoIndex = 10;
			activeBg = 0;
			//setBg();
			//loadImage(imgArray[10][activeBg], 10);
			document.title = "Maca Kizi – Turkbuku - Bodrum - story-of-macakizi";			
	}else if(hash == "#newsletter-subscription"){
			offersClose();
			//console.log("4:"+hash);
			if(isStoryOpen){storyClose()};
			if(!isNewsOpen){newsOpen()};	
			if(setBgWorkedOnce == false){
				//clearInterval (interval);
				loadImage(imgArray[imgArray.length - 1][activeBg], imgArray.length - 1);						
			}
			document.title = "Maca Kizi – Turkbuku - Bodrum - newsletter-subscription";
	}else{
			offersClose();
			//console.log("5:"+hash);
			if(isStoryOpen){storyClose()};
			if(isNewsOpen){newsClose()};
					
			
						
			for(var i = 0; i < hrefArray.length; i++){
				if(hash == "#"+hrefArray[i]){
					hash = "#"+hrefArray[i];
					inde = i;
					break;				
				}
			}
			
			
			//console.log("hash: "+hash);	
			//console.log("hrefArray[0]: "+hrefArray[0]);	
			//	clearInterval (interval);		
					
			if(activeMenuIndex != -1){clickAnimOut(activeMenuIndex, inde)};
			if(activeMenuIndex == -1 && isFirstOpened == true){clickAnimIn(inde)};			
			activeMenuIndex = inde;
			if(activePhotoIndex != inde){	
				activeBg = 0;
			}
			//console.log("activePhotoIndex: "+activePhotoIndex);
						
			if(Math.round(menuItemWidthLast) != Math.round($(menuArray[activeMenuIndex]).width())){mouseOverAnim(inde)}				
			document.title = "Maca Kizi – Turkbuku - Bodrum - " + hash.replace("#", "");
			if(isFirstOpened == false){				
				setTimeout("clickAnimIn(inde)", 500);
			}/*else{
				clickAnimIn(inde);	
			}	*/		
						
			
	}
	if(isFirstOpened == false){
		isFirstOpened = true;
	}
}

<!--Dynamic URL Management-->

<!--Document Load Fuctions-->

$(function() {	
	activeMenuIndex = -1;
	winW = $(window).width();
	winH = $(window).height();
	menuItemWidthLast = winW - winPadd;
	menuArray = jQuery.makeArray($(".menu_item")); // returns a nodeList
	//hrefArray = jQuery.makeArray($("a.menu_link").index()); // returns a nodeList
	
	for(var i=0; i < menuArray.length; i++){
		hrefArray[i] = $(menuArray[i]).find('a.menu_link').text();		
		hrefArray[i] = hrefArray[i].replace(/\s/g,'-');
		hrefArray[i] = hrefArray[i].toLowerCase();
	}
	addEvents();
	scaleBg();
			
	//console.log(navigator.appVersion  );
	
	if (navigator.appVersion.indexOf("Mac")!=-1){
		//console.log("mac");
		osFix = 10;
		
		$('.menu_item').each(function(index){
			//$(this).css('width',menuArray[index].find('a.menu_link')+20)
			fistWidhtArray[index] = $(menuArray[index]).find('a.menu_link').width()+osFix;
		});
	}
	
	$('.menu_item').each(function(index){$(this).css('width',fistWidhtArray[index]+osFix)});	
	
	$(window).hashchange(function(){setTimeout(controlURL, 100)});
	setTimeout(controlURL, 100);
	//window.location.hash = "#home";
});
<!--Document Load Fuctions-->

<!--Document Resize Fuctions-->
$(window).resize(function(){	
	winW = $(window).width();
	winH = $(window).height();
	menuItemWidthLast = winW - winPadd;		
	if(activeMenuIndex != -1){		
		$(menuArray[activeMenuIndex]).stop(true, false);
		$(menuArray[activeMenuIndex]).find(".content_container").animate({opacity:0.0},100);
		mouseOverAnim(activeMenuIndex);
		clickAnimIn(activeMenuIndex, false);
	}	
	scaleBg();	
});
<!--Document Resize Fuctions-->

function scaleBg(){
	imgW = winW = $(window).width();	
	imgH = Math.round(imgW / imgRat);
	if(imgH <= winH){
		$('.bgImage').height(winH);		
		$('.bgImage').width(Math.round(winH * imgRat));		
	}else{
		$('.bgImage').width('100%');
		$('.bgImage').height('auto');
	}	
}
function addEvents(){
	if(isEventAdded == false){
		isEventAdded = true;
		$('.menu_item > a').live('mouseover', mouseOver);
		$('.menu_item > a').live('mouseout', mouseOut);
		$('.menu_item > a').live('click', mouseClick);
	}
}
function addEvent(){
	/*if(isEventAdded == false){
		isEventAdded = true;*/
		$('.menu_item > a').live('click', mouseClick);
	//}
}
function removeEvent(){
	/*if(isEventAdded == true){
		isEventAdded = false;*/
		$('.menu_item > a').die('click', mouseClick);
	//}
}
var menuTimeSpace = true;
function menuTimeSpaceTrue(){
	menuTimeSpace = true;
}
function mouseClick(){
	/*removeEvent();	
	setTimeout(addEvent , 2000);*/
	if(menuTimeSpace == true){
		menuTimeSpace = false
		setTimeout(menuTimeSpaceTrue, 1200);
		var num = $(this).parent('div').index();
		//console.log("num: " +num );
		window.location.hash = "#"+hrefArray[num];		
		if(activeMenuIndex == $(this).parent('div').index() ){setTimeout(changeHashEmpty, 50)};	
	}
}
function mouseOver(){
	if(activeMenuIndex != $(this).parent('div').index() ){
		var index = $(this).parent('div').index();
		mouseOverAnim(index);
	}
}
function mouseOut(){
	if(activeMenuIndex != $(this).parent('div').index() ){
		var index = $(this).parent('div').index();
		mouseOutAnim(index);
	}
}
function clickAnimIn(no, bgChange){
	$(menuArray[no]).find('.content_container').width(winW-60);
	menuItemHeightLast = $(menuArray[no]).find('.content_container').height()+50;
	$(menuArray[no]).animate({height:menuItemHeightLast, opacity:0.8},300,'easeInOutCubic',function(){
		$(menuArray[no]).find('.content_container').fadeTo(300,1);
		$(menuArray[no]).find('a.close').show();
		addScroll();
		if(bgChange != false){
			//clearInterval (interval);
			loadImage(imgArray[no][activeBg], no);
		}
	});
}
function clickAnimOut(no, newNo){
	$(menuArray[no]).find('a.close').hide();
	$(menuArray[no]).find('.content_container').fadeTo(200,0,function(){		
		$(menuArray[no]).animate({height:menuItemHeightFirst, opacity:0.6},80,'easeInOutCubic',function(){			
			$(menuArray[no]).animate({width:fistWidhtArray[no]+osFix},200,'easeInOutCubic', function(){
				if(newNo != undefined || newNo != "undefined"){
					clickAnimIn(newNo);
				}
			});
		});
	});
}
function clickAnimOutEqual(no){	
	$(menuArray[no]).find('a.close').hide();
	$(menuArray[no]).find('.content_container').fadeTo(200,1,function(){		
		$(menuArray[no]).animate({height:menuItemHeightFirst, opacity:0.6},80,'easeInOutCubic');		
	});	
}
function mouseOverAnim(no){$(menuArray[no]).animate({width:menuItemWidthLast, opacity:0.8},700,'easeInOutCubic')};
function mouseOutAnim(no){	
	if($(menuArray[no]).height() <= menuItemHeightFirst){
		$(menuArray[no]).stop(true, false);
		$(menuArray[no]).animate({width:fistWidhtArray[no]+osFix, opacity:0.6},200,'easeInOutCubic');				
	}	
}
function menuClose(){	
	if(activeMenuIndex != -1){
		clickAnimOut(activeMenuIndex);	
		activeMenuIndex = -1;
	}
}

<!-- Background Management -->
function loadImage(url, activePhoto){
	clearInterval (interval);
	//console.log(url, activePhoto);
	var arr = [url];
	$.preload(arr, {
		init: function(loaded, total) {
			$('#loading').show();			
		},
		loaded: function(img, loaded, total) {
			$('#loading').hide();	
			//$("#full-screen").append(img);
			if(activePhoto == undefined || activePhoto == "undefined"){
				changeImage();
				fixInterval();
			}else{
				activePhotoIndex = activePhoto;
				setBg();
			}
			if(imgArray[activePhotoIndex].length > 1){
				fixInterval();
			}
		},
		loaded_all: function(loaded, total) {
			//$("#indicator").html("Loaded: "+loaded+"/"+total+". Done!");
		}
	});
}

function setBg2(no){
	if(no != undefined || no != "undefined"){
		activeBg = 0;		
		loadImage(imgArray[no][activeBg], no);
	}
}

function setBg(){ //Arkaplan resim ataması	//Default arkaplan resimleri döndürülmeye başlıyor.	
	//console.log("setBg activePhotoIndex: "+activePhotoIndex);	
	if(activePhotoIndex == imgArray.length - 1){
		if(imgArray[imgArray.length - 1].length == 1){
			clearInterval (interval);
			changeImage();
			//fixInterval();
		}else if(imgArray[imgArray.length - 1].length > 1){
			changeImage();
			fixInterval();
		}
	}else{
		if(imgArray[activePhotoIndex].length == 1){
			clearInterval (interval);
			changeImage();
			//fixInterval();
		}else if(imgArray[activePhotoIndex].length > 1){
			changeImage();
			fixInterval();
		}
	}
}
function fixInterval(){
	clearInterval (interval);
	interval = setInterval("loadImage(imgArray[activePhotoIndex][activeBg])", slideSpeed);
}
function changeImage(){
		if(setBgWorkedOnce == false){
			setBgWorkedOnce = true;
		}
		if(activeDiv == 1){
			$('.page_bg2').find('img').attr('src', imgArray[activePhotoIndex][activeBg]);
			//console.log('resim1: '+imgArray[activeMenuIndex][activeBg])
			$('.page_bg2').animate({opacity:1.0},800);
			$('.page_bg1').animate({opacity:0.0},800,function(){
				$(this).find('img').attr('src', '');									   
			});
			activeDiv = 2;
		}else if(activeDiv == 2){				
			$('.page_bg1').find('img').attr('src', imgArray[activePhotoIndex][activeBg]);
			//console.log('resim2: '+imgArray[activeMenuIndex][activeBg])
			$('.page_bg1').animate({opacity:1.0},800);
			$('.page_bg2').animate({opacity:0.0},800,function(){
				$(this).find('img').attr('src', '');									   
			});
			activeDiv = 1;
		}
		//aktif menu resim array uzunluk kontrol ediliyor
		if(activeBg == imgArray[activePhotoIndex].length - 1){			
			activeBg = 0;
		}else{
			activeBg++;
		}
}
<!-- Background Management -->
