﻿//------: CHECK BROWSER
var version = "";
var browser ="";
var isIE6 = false;
var isIE7 = false;

function getBrowser() {	
	if (navigator.appVersion.indexOf("MSIE")>0){
		version = parseFloat(navigator.appVersion.split("MSIE")[1]);  
		browser = "MSIE";
	} else {
		browser = "not MSIE"
	}
}
getBrowser();

if(browser=="MSIE"){
	if(version<7){
		isIE6 = true;
	}
	if(version<8 && version>6){
		isIE7 = true;
	}
}
//------: GENERAL FUNCTIONS
function DoPopupAdvanced(theURL, theWinName, theLeft, theTop, theWidth, theHeight, theresize, thescrollbars, thestatusbar, themenu, thetools, thelocationbar, thedirs) {
	// EXAMPLE doPopup('popup.asp', 'popwin', 10, 10, 500, 300, 'no', 'no', 'yes', 'no', 'no', 'no', 'no')
	// USE theLeft AND theTop = -1 FOR AUTO-CENTER

	if (theLeft == -1 && theTop == -1) {
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	var paramstr;
	paramstr = "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=" + theresize + ",scrollbars=" + thescrollbars + ",status=" + thestatusbar + ",menubar=" + themenu + ",toolbar=" + thetools + ",location=" + thelocationbar + ",directories=" + thedirs;
	window.open(theURL, theWinName, paramstr);
}

function DoPopup(TheURL, TheWidth, TheHeight,Resize,Scrollbars) {
	Resize = !Resize ? 'no' : Resize;
	Scrollbars = !Scrollbars ? 'no' : Scrollbars;
	DoPopupAdvanced(TheURL, 'popwin', -1, -1, TheWidth, TheHeight, Resize, Scrollbars, 'yes', 'no', 'no', 'no', 'no');
}
var flashTimer;
function getFlashMovieObject(movieName){
	var obj;
	if (window.document[movieName]){
		obj = window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]){
			obj = document.embeds[movieName];
		}
	} else {// if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	   obj = document.getElementById(movieName);	   
	}
	if(obj){
		if(obj!=undefined){
			return obj;
		} else {
			setTimeout("getFlashMovieObject('"+movieName+"')",300);
			return null;
		}
	} else {
		setTimeout("getFlashMovieObject('"+movieName+"')",300);
		return null;
	}
}

function switchVis(objId1, objId2){
	$('#'+objId1).hide();
	$('#'+objId2).show();
}
function LoginInput(obj, dValue, setValue){
	if(obj.value==dValue)
		obj.value = setValue;
}

function TogglePassword(textId,passId,viewPassword) {
	var aPasswordValue = $("#"+passId).attr('value');
	if (viewPassword) {
	    
	    if (aPasswordValue == "") {
	        $("#" + passId).show();
	        $("#" + passId).focus();
	        $("#" + textId).hide();
	    }
	    else {
	        $("#" + textId).hide();
	        $("#" + passId).show();
	    }
	} else {
		if (aPasswordValue == "") {
			$("#"+textId).show();
			$("#"+passId).hide();
		}
	}	
}


	

function HideText() {
	document.getElementById('<%=theRegularTextBox.ClientID%>').style.display = 'none';
	document.getElementById('<%=thePasswordTextBox.ClientID%>').style.display = 'block';
	document.getElementById('<%=thePasswordTextBox.ClientID%>').focus();
}


/*-- ITEMS SET DEFAULT SIZE SCRIPTS: START --*/
var defItemContHeight = 372;
var pageSize = 9;

var ItemsCount;
var FocusOn;

//function setItemSizes(focusPosition){
//	var tmpSize
//	$(".ItemContentsWrapper").show();	
//	
//	$(".ItemContents").each(function (){
//		tmpSize = $(this).height();
//		
//		if(tmpSize>defItemContHeight){
//			defItemContHeight = tmpSize;
//		}
//	});

//	$(".ItemContents").css("height", defItemContHeight + "px");
//	
//	for (var i = focusPosition+2; i < (pageSize+2)-(pageSize/3); i++) {
//		$("#Item"+i).css("display", "none");
//	
//	}
//	
//	for (var i =  2; i < focusPosition-1; i++) {
//		$("#Item" + i).css("display", "none");
//	
//	}
//	
//	if(isIE6){
//		$(".ListItemContentsWrapper").height(defItemContHeight);
//	} else {
//		$(".ListItemContentsWrapper").height(defItemContHeight-91);
//	}
//	
//	$(".ItemContentsWrapper").hide();
//	
//	
//	$(".itemsBgs").height(Number(defItemContHeight));
//	$(".contentBgs").height(Number(defItemContHeight));
//	
//	
//	$("#ItemContainer").height(Number($(".itemsBgs").outerHeight()));

//}

function ProductPageSizes(){
	if($(".ProductTextWrapper") && $(".PrPageMoreContentWrapper")){
		var ProdTxtWrappH = Number($(".ProductTextWrapper").outerHeight());
		var PrPageMoreH = Number($(".PrPageMoreContentWrapper").outerHeight());
		
		var HeightToGet = 0;	
		
		if(ProdTxtWrappH > PrPageMoreH){
			HeightToGet = ProdTxtWrappH;		
		} else if(ProdTxtWrappH < PrPageMoreH){
			HeightToGet = PrPageMoreH;		
		} else {
			HeightToGet = PrPageMoreH;		
		}
			
		
		$(".ProductPageMore").height(HeightToGet);
		$(".PrPageMoreContent").height(HeightToGet);
		$(".ProductTextWrapper").height(HeightToGet);
	
		var dif = Number((HeightToGet - $(".FlashProductMore").outerHeight())/2);
		$(".FlashProductMore").css("top",dif + "px");
	}

}


/*-- ITEMS SET DEFAULT SIZE SCRIPTS: END --*/

/*-- ITEMS OPEN- CLOSE SCRIPTS: START --*/
var AllItems = new Array();
var itemsPerPage;
var zindexNum = 0;
var currentItemId = "";
var defaultBg = "bg0";
var listItemIsOpen = false;
var openItem = "";
var openBg = "";

function showBg(id, Direction){
    var tempNum;    
	
	$(".contentBgs").each(function (){
		tempNum = Number($(this).css("z-index"));
		if(tempNum>zindexNum){
			zindexNum = tempNum;
		}
	});
	zindexNum++;
	
	$('#'+id).css({ opacity: 0, "z-index":zindexNum });
	$('#'+id).effect("slide",  { direction: Direction }, 500 ).animate({'opacity':1},{queue:false,duration:'slow'});
	
}
function showItem(itemId, bgId) {
    
	focusOut();
	if(currentItemId!=""){
		hideItem(currentItemId, true);
	}
	currentItemId = itemId;
	
	if(bgId){
		showBg(bgId,"down");
	}
	
	$('#'+itemId).show();
	
	var obj = $('#'+itemId+">div.ItemContents");
	obj.animate({
		marginTop: "0px"
	 }, 500, function() {
		 // Animation complete.
	 });

}
function hideItem(itemId,changeBg){	
	focusOut();
	listItemIsOpen = false;
	currentItemId = "";
	if(changeBg){
		showBg(defaultBg,"up");
	}
	
	var obj = $('#'+itemId+">div.ItemContents");
	obj.animate({
		marginTop: Number(-defItemContHeight) + "px"
	 }, 300, function() {
		 $('#'+itemId).hide();
		// Animation complete.
	});
}
function showListItem(itemId){
	focusOut();
	if(listItemIsOpen){			
		hideItem(itemId,false);	
	} else {		
		showItem(itemId);
		listItemIsOpen = true;
	}
	
}
function GoAndOpenItem(itemId,bgId){
	var itemisInPage = getItemPage(itemId);
	
	if(cPage==itemisInPage){
		showItem(itemId,bgId);
	} else {
		openItem = itemId;
		openBg = bgId;
		if(cPage>itemisInPage){
			SeeMoreItems("prev");			
		} else if(cPage<itemisInPage){
			SeeMoreItems("next");
		}
	}
	
	
}
function getItemPage(itemId){
	page = 1;
	w = 0;
	for(i=0;i<AllItems.length;i++){
		if(itemId == AllItems[i].ItemId){
			return page;	
		}		
		w++
		if(w>=itemsPerPage){
			w = 0;
			page++;
		}
	}
	return page;
}
function focusOut(){
	$('a').blur();
}
/*-- ITEMS OPEN- CLOSE SCRIPTS: END --*/

/*-- ITEMS SEE MORE PAGES: START --*/
var cPage = 1;
var allPages;
var delayToOpenItem = 0;
//function SeeMoreItems(nextprev){
//	focusOut();
//	if(seeMorePanelOpen){
//		SeeMore(false,true);
//	}
//	
//	if(currentItemId!=""){
//		hideItem(currentItemId, true);
//	}
//	
//	//$('.SeeMoreNextBtn').hide();
//	//$('.SeeMorePrevBtn').hide();	
//	
//	
//	nextprev == "next" ? cPage++ : cPage--;
//	
//	
//	if(isIE6){
//		$('.BgHolder').fadeOut(500, function() {
//			$('.ItemsHolder').fadeOut(500, function() {
//				ShowSeeMoreItems(nextprev);
//			});
//		});			
//	} else {
//		if(nextprev == "next"){					
//			$('.BgHolder').animate({'opacity':0},500,function(){																		 
//				$('.ItemsHolder').animate({'opacity':0,'left':-930},500,function(){
//					ShowSeeMoreItems(nextprev);
//				})
//			});	
//			
//		} else {			
//			$('.BgHolder').animate({'opacity':0},500,function(){																		 
//				$('.ItemsHolder').animate({'opacity':0,'left':930},500,function(){
//					ShowSeeMoreItems(nextprev);			
//				})
//			});
//		}
//	}
//}
function setItemHeights() {

    var tmpSize
    $(".ItemContentsWrapper").show();

    $(".ItemContents").each(function () {
        tmpSize = $(this).height();

        if (tmpSize > defItemContHeight) {
            defItemContHeight = tmpSize;
        }
    });

    $(".ItemContents").css("height", defItemContHeight + "px");

    if (isIE6 || isIE7) {
        $(".ListItemContentsWrapper").height(defItemContHeight);
    } else {
        $(".ListItemContentsWrapper").height(defItemContHeight - 91);
    }

    $(".ItemContentsWrapper").hide();


    $(".itemsBgs").height(Number(defItemContHeight));
    $(".contentBgs").height(Number(defItemContHeight));


    $("#ItemContainer").height(Number($(".itemsBgs").outerHeight()));

}
var TotalColumns = 0;
function setItemSizes(focusPosition, pageSize) {
    ItemsCount = pageSize;
    FocusOn = focusPosition;
   
    var tmpSize
    $(".ItemContentsWrapper").show();

    $(".ItemContents").each(function () {
        tmpSize = $(this).height();

        if (tmpSize > defItemContHeight) {
            defItemContHeight = tmpSize;
        }
    });

    $(".ItemContents").css("height", defItemContHeight + "px");
    //First Page
    if (focusPosition == TotalColumns || focusPosition == TotalColumns - 1 || focusPosition == TotalColumns+1) {
        for (var i = TotalColumns + 2; i < (pageSize + 2); i++) {
            $("#Item" + i).css("display", "none");


        }
        $("#PrevBtn").css("display", "none");
        if (pageSize <= TotalColumns) {
            $("#NextBtn").css("display", "none");
        }
    } //Last page
    else{        
        var j = parseInt((focusPosition - 2) / TotalColumns);
        var size = parseInt(pageSize);
        var curpos = parseInt(focusPosition);

        var posInPage = focusPosition - j - 2;
        //alert(j);

        for (i = 2; i < j * TotalColumns + 2; i++) {
            //alert(i);
            //alert((position + 2) + ":" + pageSize + "/" + i);
            $("#Item" + i).css("display", "none");
        }

        for (k = (j+1) * TotalColumns+2; k < size+2; k++) {
            
            $("#Item" + k).css("display", "none");
        }


        if (j>0)
            $("#PrevBtn").css("display", "block");
        else
            $("#PrevBtn").css("display", "none");
        if (size - (j* TotalColumns)>0)
            $("#NextBtn").css("display", "block");
        else
            $("#NextBtn").css("display", "none");

    } 

    if (isIE6 || isIE7) {
        $(".ListItemContentsWrapper").height(defItemContHeight);
    } else {
        $(".ListItemContentsWrapper").height(defItemContHeight - 91);
    }

    $(".ItemContentsWrapper").hide();


    $(".itemsBgs").height(Number(defItemContHeight));
    $(".contentBgs").height(Number(defItemContHeight));


    $("#ItemContainer").height(Number($(".itemsBgs").outerHeight()));

}

function SeeMoreItems(nextprev) {
    focusOut();
    if (seeMorePanelOpen) {
        SeeMore(false, true);
    }

    if (currentItemId != "") {
        hideItem(currentItemId, true);
    }

    //$('.SeeMoreNextBtn').hide();
    //$('.SeeMorePrevBtn').hide();	


    nextprev == "next" ? cPage++ : cPage--;


    if (isIE6 || isIE7) {
       ShowSeeMoreItems(nextprev);
    } else {
        if (nextprev == "next") {
            $('.BgHolder').animate({ 'opacity': 0 }, 500, function () {
                $('.ItemsHolder').animate({ 'opacity': 0, 'left': -930 }, 500, function () {
                    ShowSeeMoreItems(nextprev);
                })
            });

        } else {
            $('.BgHolder').animate({ 'opacity': 0 }, 500, function () {
                $('.ItemsHolder').animate({ 'opacity': 0, 'left': 930 }, 500, function () {
                    ShowSeeMoreItems(nextprev);
                })
            });
        }
    }

}
function ShowSeeMoreItems(nextprev) {

    //Dipslay BLock-None;  
    if ((FocusOn == TotalColumns || FocusOn == TotalColumns - 1) && nextprev == "next") {
        for (var i = 2; i < 2 + TotalColumns; i++) {
            $("#Item" + i).css("display", "none");
        }
        for (var i = 2 + 2 * TotalColumns; i < ItemsCount + 2; i++) {
            $("#Item" + i).css("display", "none");
        }
        for (var i = TotalColumns + 2; i < 2 + 2 * TotalColumns; i++) {
            $("#Item" + i).css("display", "block");
        }
        FocusOn = TotalColumns * 2;
        if (ItemsCount >= TotalColumns * 2)
            $("#NextBtn").css("display", "block");
        else
            $("#NextBtn").css("display", "none");

        $("#PrevBtn").css("display", "block");
        setItemHeights();
        
    }

    else if (FocusOn > TotalColumns && nextprev == "next") {
        var curpage = parseInt((FocusOn - 2) / TotalColumns) + 1;
        var foc = parseInt(FocusOn);
        var total = parseInt(ItemsCount);
        var posinpage = (foc - 2) - (curpage) * TotalColumns +1 ;
        if (foc + TotalColumns >= total + 2) {
            //alert('nxt ' + foc);

            for (var i = 2; i < total + 1; i++) {
                //alert(i);
                $("#Item" + i).css("display", "none");
            }
            //alert(posinpage);
            if (TotalColumns == 3 && posinpage <= 0)
                $("#Item" + total).css("display", "none");
            else
                $("#Item" + total).css("display", "block");
            total = total + 1;
            FocusOn = total + 1;
            $("#Item" + total).css("display", "block");
            $("#NextBtn").css("display", "none");
            $("#PrevBtn").css("display", "block");
        }
        
        else {            
            var curpage = parseInt((FocusOn - 2) / TotalColumns) + 1;
            var foc = parseInt(FocusOn);
            foc = foc + TotalColumns;
            FocusOn = foc;

            var posinpage = (foc - 2) - (curpage) * TotalColumns +1 ;
            
            for (var i = 2; i < curpage * TotalColumns + 2; i++) {
                $("#Item" + i).css("display", "none");
            }
            for (var i = (curpage + 1) * TotalColumns + 2; i < ItemsCount + 2; i++) {
                $("#Item" + i).css("display", "none");
            }
            for (var i = curpage * TotalColumns + 2; i < (curpage + 1) * TotalColumns + 2; i++) {
                $("#Item" + i).css("display", "block");
            }
            //alert('as');
            if (foc + TotalColumns > total + 2)
                $("#NextBtn").css("display", "none");

            $("#PrevBtn").css("display", "block");
            
        }
        setItemHeights();
    }
    if (nextprev == "prev") {
        var foc = parseInt(FocusOn);
        var total = parseInt(ItemsCount);
        foc = Math.max(foc - TotalColumns, 2);

        for (var i = 2; i < foc - 1; i++) {
            $("#Item" + i).css("display", "none");
        }
        for (var j = foc + 2; j < total + 2; j++) {
            $("#Item" + j).css("display", "none");
        }
        if (foc > 2) {
            

            if (TotalColumns == 4) {
                for (var l = foc - 2; l < foc + TotalColumns - 2; l++) {
                    $("#Item" + l).css("display", "block");

                }
            }

            else {
                for (var l = foc - 1; l < foc + TotalColumns - 1; l++) {
                    $("#Item" + l).css("display", "block");
                }

            }
            if (foc > TotalColumns)
                $("#PrevBtn").css("display", "block");
            else
                $("#PrevBtn").css("display", "none");
            FocusOn = foc;
        }
        else {
            
            for (var l = 2; l < foc + TotalColumns; l++) {
                $("#Item" + l).css("display", "block");
            }
            FocusOn = TotalColumns;
            $("#PrevBtn").css("display", "none");
        }
        //alert(':'+FocusOn);
        $("#NextBtn").css("display", "block");
        setItemHeights();
    }

    if (isIE6 || isIE7) {
    } else {
        if (nextprev == "next") {
            $('.ItemsHolder').css('left', 930);
        } else {
            $('.ItemsHolder').css('left', -930);
        }
        $('.ItemsWrapper').css({ "z-index": 100 });

        $('.ItemsHolder').animate({ 'opacity': 1, 'left': 0 }, 500, function () {
            $('.BgHolder').animate({ 'opacity': 1 }, { duration: 500 })
        });
    }

    	if(openItem){ // It is get from the list
    		clearTimeout(delayToOpenItem);
       		delayToOpenItem = setTimeout("openDelayItem();", 1000);		
    	}
}
function openDelayItem(){
	clearTimeout(delayToOpenItem);
	showItem(openItem,openBg);
	openItem = "";
	openBg = "";	
}
/*-- ITEMS SEE MORE PAGES: END --*/


/*-- ALL MENU SCRIPTS: START --*/
var isout=true;
var t;
var cmenuItem;
function showHide(thisObj, MenuWrapper, str){
	hideAll();
	
	$(".SubMenuWrapperInner").css("display","block");
	$("." + MenuWrapper).css("display","block");	
	
	$("#"+ str).show();		
	var obj  = $("#"+ thisObj).attr("id");	
	$(thisObj).addClass('menuSelected');
	
	var itemOffset = $(thisObj).offset();
	var MenuWrapperOffset = $("." + MenuWrapper).offset();
	var dif = Number(MenuWrapperOffset.left - itemOffset.left);
	
	var menuSpan = $(thisObj).find("span");	
	
	//$("#test").html(String(menuSpan.css("background-position")));
	
	if(MenuWrapper=="FooterMenuWrapper"){
		menuSpan.css("background-position",dif+"px -150px");
	} else {
		menuSpan.css("background-position",dif+"px 0px");
	}	
}
function timersetMenuDefault(num) {	
	if(!num)
		num = 500;
	
	t = setTimeout("if(isout){hideAll()}", num);
	
}
function hideAll(){
	$(".SubMenuWrapper").css("display","none");
	$(".SubMenu").css("display","none");
	$(".FooterMenuWrapper").css("display","none");
	$(".FooterMenu").css("display","none");
	$(".menuSelected").removeClass("menuSelected");
	clearTimeout(t);
}

/*-- ALL MENU SCRIPTS: END --*/

/*-- SEE MORE SCRIPTS: START --*/
var defTop;
var seeMorePanelOpen = false;
function SeeMore(ToOpen,closeFlash){
	if(ToOpen){
		seeMorePanelOpen = true;
		$(".MoreContsWrapper").show();
		var footerOffset = $(".footerWrapper").offset();
		var footerTopMargin = $(".footerWrapper").css("margin-top");
		footerTopMargin = Number(footerTopMargin.substring(0,footerTopMargin.lastIndexOf("px")));		
		
		var MoreWrapperPos = $(".MoreContsWrapper").offset();
		
		var Height = Number(footerOffset.top - footerTopMargin - MoreWrapperPos.top);
		
		$(".MoreContsWrapper").animate({'height':Height});
	} else {
		seeMorePanelOpen = false
		$(".MoreContsWrapper").animate({'height':0}, function() { $(".MoreContsWrapper").hide(); });
		if(closeFlash){
			closeFlashSeeMore();
		}
	}
}
function closeFlashSeeMore(){
	var flashMovie = getFlashMovieObject("FlashObjectMore");
	if (flashMovie!=null){
		flashMovie.closeSeeMore();
	} else {
		setTimeout("closeFlashSeeMore()", 300);
	}
}


/*-- SEE MORE SCRIPTS: END --*/

/*-- LIST HOVERS SCRIPTS: START --*/
var maxLeft = -220;
var maxBgRight = 195;
var objHovered;
var hovertimer = 0;
function ListHover(obj){
	objHovered = obj;	
	hovertimer = setTimeout("ListHoverAnim()", 100);	
}
function ListHoverAnim(){
	clearTimeout(hovertimer);

	if(objHovered){
		if(browser=="MSIE"){
			$(objHovered).animate({'background-position-x':"0px"},400);
		} else {
			$(objHovered).animate({'background-position':"0px 0px"},400);
		}
	
		var insObj = $(objHovered).find("span.IndexItemTitle");	

		insObj.animate({'left':maxLeft},600);
	}
}

function ListHoverOut(obj){
	objHovered = undefined;
	
	var insObj = $(obj).find("span.IndexItemTitle");
	
	setTimeout(function() {
		insObj.animate({'left':0},400);
	}, 10);
	
	setTimeout(function() {
		if(browser=="MSIE"){
			$(obj).animate({'background-position-x':maxBgRight+"px"},800);
		} else {
			$(obj).animate({'background-position':maxBgRight+"px 0px"},800);
		}
	}, 100);	
	
}
/*-- LIST HOVERS SCRIPTS: END --*/

/*-- PRODUCT PAGE OPEN- CLOSE SCRIPTS: START --*/
var defWidthOpen = 627;
function openProductMore(ToOpen){
	if(ToOpen){
		$('.PrPageMoreContentWrapper').animate({'width':defWidthOpen},{duration:500})
	} else {
		$('.PrPageMoreContentWrapper').animate({'width':0},{duration:500})
	}
}
/*-- PRODUCT PAGE OPEN- CLOSE SCRIPTS: END --*/

/*-- SHOW LOGIN AREA AT HOME PAGE: START --*/
var loginAreaOpen = false;
function showLoginArea(){
	focusOut();
	if (loginAreaOpen) {
		$('.LoginArea').animate({ 'left': 200 }, 500, function () {
			loginAreaOpen = false;
			$('.LoginArea').hide();
			$('.alreadyMember').removeClass("loginAreaOpened");
        });
		
	} else {
		$('.alreadyMember').addClass("loginAreaOpened");
		$('.LoginArea').show();
		$('.LoginArea').css('left','200px');
		$('.LoginArea').animate({ 'left': 569 }, 500, function () {
			loginAreaOpen = true;
        });
	}

}

/*-- SHOW LOGIN AREA AT HOME PAGE: END --*/

/*-- DROP DOWN FOR HOME ALL RESTAURANTS LINKS: START --*/
var dropDownRestOpen = false;
function openRestaurants(){
	focusOut();
	var TextH = Number($(".AllRestaurantsText").outerHeight());
	
	if(dropDownRestOpen==false){
		dropDownRestOpen = true;
		$('.chooseRest').addClass("isOpened");
		$('.AllRestaurants').animate({'height':TextH},{duration:300})
	} else {
		dropDownRestOpen = false;
		$('.chooseRest').removeClass("isOpened");
		$('.AllRestaurants').animate({'height':0},{duration:300})
	}
}
/*-- DROP DOWN FOR HOME ALL RESTAURANTS LINKS: END --*/

/*-- FLASH DIARY CONTROLS AT HOME PAGE: START --*/
function DiaryFlip(page,firstTime){
	var CalendarLeft = getFlashMovieObject("CalendarLeft");
	var CalendarRight = getFlashMovieObject("CalendarRight");
	
	if(CalendarLeft!=null && CalendarRight!=null){		
		try {
			CalendarLeft.ExternalDiaryFlip(page,firstTime);
		}
		catch(err) {
		}
		try {
			CalendarRight.ExternalDiaryFlip(page,firstTime);
		}
		catch(err) {
		}
	} else {
		setTimeout("DiaryFlip()", 300);
	}
	
}

function DiaryFlipped(page,bydrag){
	if(!bydrag){
		bydrag = false;
	}
	var cloackMovie = getFlashMovieObject("Clock");
	var CalendarLeft = getFlashMovieObject("CalendarLeft");
	var CalendarRight = getFlashMovieObject("CalendarRight");

	if(cloackMovie!=null && CalendarLeft!=null && CalendarRight!=null){
		try {
			cloackMovie.ExternalDiaryFlip(page);
		}
		catch(err) {
		}
		try {
			CalendarLeft.ExternalDiaryFlip(page,false,bydrag);
		}
		catch(err) {
		}
		try {
			CalendarRight.ExternalDiaryFlip(page,false,bydrag);
		}
		catch(err) {
		}
	} else {
		setTimeout("DiaryFlipped()", 300);
	}
}
function SetSound(cases){
	var cloackMovie = getFlashMovieObject("Clock");
	var CalendarLeft = getFlashMovieObject("CalendarLeft");
	var CalendarRight = getFlashMovieObject("CalendarRight");
	if(cloackMovie!=null && CalendarLeft!=null && CalendarRight!=null){		
		try {
			cloackMovie.ExternalSoundControl(cases);
		}
		catch(err) {
		}			
	
	
		try {
			CalendarLeft.ExternalSoundControl(cases);
		}
		catch(err) {
		}
		
	
		try {
			CalendarRight.ExternalSoundControl(cases);
		}
		catch(err) {
		}
	} else {
		setTimeout("SetSound()", 300);
	}
}

function ExternalMovieReady(){
	var cloackMovie = getFlashMovieObject("Clock");
	if(cloackMovie!=null){
		try {			
			cloackMovie.ExternalMovieReady();
		}
		catch(err) {
		}
	} else {
		setTimeout("ExternalMovieReady()", 300);
	}
}

/*-- FLASH DIARY CONTROLS AT HOME PAGE: END --*/

//------: LIST GALLERY SCRIPTS: START
var allowExpand = true; // Allow expand of highslide by default
function Gallery(imgId,prevnext,array){
	var img = $('#'+imgId);
	var changePage = false;
	var objImage = new Image();
	var Len = array.length;
	var cpage = getCurrentPage(img,array);
	var thePage;
	$('.prevnextBtns').removeClass("disabled");
		
	switch(prevnext){
		case "prev":
			if(cpage>0){
				changePage = true;
				thePage = cpage-1;
				if(thePage==0){
					$('.prevImg').addClass("disabled");
				}
			}
			break;
		case "next":
			if(cpage<(Len-1)){
				changePage = true;
				thePage = cpage+1;
				if(thePage>=Number(Len-1)){
					$('.nextImg').addClass("disabled");
				}
			}
			break;
	}
	
	if(changePage){
		allowExpand = false;
		$('.prevnextBtns').css("display","none");
		objImage.src=array[thePage].Img;
		img.animate({ 'opacity': 0 }, 500, function () {
			objImage.onLoad=GalleryImageLoaded(img,objImage.src);
		});
	}
	
}
function GalleryImageLoaded(img,imgsrc){
	img.attr("src",imgsrc);
	img.animate({ 'opacity': 1 }, 500);
	$('.prevnextBtns').css("display","block");
	allowExpand = true;
}
function getCurrentPage(img,array){
	var Len = array.length;
	var theImage;
	var cImage = img.attr("src");	
	if (cImage.substr(0,7) != "http://") { 
		theImage = cImage;
	} else {		
		theImage = cImage.substring(imgPath.length);
	}
	if(Len>0){
		for(i=0;i<Len;i++){
			if(theImage==array[i].Img){
				return i;
			}
		}
	}
	return null;
}
//------: LIST GALLERY SCRIPTS: END
