
// JavaScript Document

// imgs for intro animation
if ($('#intro').length) {
    var intro = ["#intro01", "#intro02", "#intro03", "#intro04"]
}
var backflag = 0;
//public var for position map

$(window).load(
	function(){
		init();
		}
   );
// trick to enable browser load
$(window).bind("unload", function(){ });

function init(){
	
    checkBrowserType();
	subMenu();
	menuSelect();
	centerContainer();
    
    //execute when exist
    introLogo();
    iconCopy();
    defaultActive();
    buildScroll();
    overlay();
   
	aboutPage();
	//buildInfoareaScroll();
	team();
	advertising();
	slideshow();
	project();
	project2();
	
	
}

//function for center the page
function centerContainer(){
       // $('.center').center();
       // $('.center').fadeIn(1);
	   if($('.heavycontent').length){
		   $('.heavycontent').fadeIn('slow');
		   $('.loader').fadeOut('slow');
	   }
		
        /*$(window).bind('resize', function(){
           $('.center').center();
        });*/
}
//function for build advertising
function advertising()
{
	if($('#myImageFlow').length){
		switch($.cookie('flag')){
			case 'extell': backflag =1
			break;
			case 'one57': backflag =2
			break;
			case '212': backflag =3
			break;
			case '535': backflag =4
			break;
			case '995': backflag =5
			break;
			case 'aldyn': backflag =6
			break;
			case 'altair': backflag =7
			break;
			case 'ariel': backflag =8
			break;
			case 'avery': backflag =9
			break;
			case 'igt': backflag =10
			break;
			case 'lucida': backflag =11
			break;
			case 'orion': backflag =12
			break;
			case 'rushmore': backflag =13
			break;
			default:backflag =1;
		}
		 if(!$('.mainAd').length){backflag =1};
		var instanceOne = new ImageFlow();
	    instanceOne.init({   ImageFlowID:'myImageFlow',
							 circular: false,
                             reflections: false,
                             reflectionP: 0.3,
							 buttons: true,
                             opacity: true,
							 xStep: 180,
							 imageFocusM: 2.1,
							 startID: backflag 
                      });
	}
	
}

//function for intro
function introLogo(){
    if ($('#intro').length) {
        for (var i = 0; i < intro.length; i++) {
            $(intro[i]).delay(1000 * (i + 1)).fadeIn(800);
        }
        setTimeout("logoFadeOut()", 6000);
        //window.location.href = "http://dboxdev.com/extell/html/extell_development.html";
    }
}

function logoFadeOut(){
    $('#intro').fadeOut(800, function(){
        window.location.href = 'http://www.extelldev.com/extell_development.html'
    })
};
//function for main menu fadeout before gotoURL/////////////////////////////////////////////////////////////////////////////////////////////////////////
function gotoURL(){
	if($('#menu').length){
		$('#menu>ul>li').click(
			function(){
				var href= $(this).find('a').attr('href');
				if(href!="map.html"){
						 window.location.href=href;
					}
				return false;
			}
		)
	}
}



// function for icons////////////////////////////////////////////////////////////////////////////////////////////////////////////
function iconCopy(){
    if ($(".iconContainer").length) {
        var position = $(".iconContainer").children('.iconCopy').position();
        $(".iconContainer").hover(function(){
            $(this).children('.iconCopy').stop().animate({
                bottom: -(position.top)+10,
				opacity: 1,
            }, {
                duration: 300
            });
        }, function(){
            $(this).children('.iconCopy').stop().animate({
                bottom: -(position.top),
				opacity: 0.8,
            }, {
                duration: 300
            });
            //$(this).children('.iconCopy').stop().animate({bottom:'-167px'},{duration:500});
        });
    }
    
}

//function for submenu///////////////////////////////////////////////////////////////////////////////////////////////////////////
function subMenu(){
    if ($(".about").length) {
        $("#accordion").tabs("#accordion div.pane",{
			tabs: 'h2',
            effect: 'slide',
			initialIndex:0
        });
    }
}
//function for sorting icons/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function aboutPage(){
	 if ($(".about").length){
		 var ulSection = $('.scrollcontent>ul');
		 var submenu = $('#accordion>h2');
		 submenu.click(
		     function(e){
				  var index = $('h2').index(this);
				  ulSection.fadeOut(700);
				  ulSection.eq(index).fadeIn(700);
				 // e.preventDefault();
				 });
		}
};

//function for about>team////////////////////////////////////////////////////////////////////////////////////////////////////////
//only active in about section
function team(){
		if($('.scrollbtn').length){
			var imgSection = $('.scrollcontent>ul:eq(2)>li:eq(0)');
			var teamSection = $('.scrollcontent>ul:eq(2)>li:eq(1)');
			//specital setting for team menu
			var teamMenu = $('#accordion>h2').eq(2);
			$(teamMenu).bind('click', function(){
						$('.scrollbtn>a').css('color','#FFF');
						if(teamSection){
							imgSection.css('display','block');
						}
						//imgSection.fadeIn('fast');
				}
			)
			
			$('.scrollbtn>a').click(
				function(e)
				{ 
				   if(imgSection){
					   imgSection.fadeOut('fast');
				   }
				   var btnString = $(this).attr('href');
				   var anchorObj = $('div[name='+btnString+']');
				   
				   $('.scrollbtn>a').css('color','#FFF');
				   $(this).css('color','#00aeef');
				   
				   $('.teamdetail').fadeOut('fast');
				   anchorObj.fadeIn('fast', function(){buildScroll()});
											
				   e.preventDefault();
				})
		}
}



//function for scroller//////////////////////////////////////////////////////////////////////////////////////////////////////////
function buildScroll(){
    if ($('.scroll-pane').length) {
        $('.scroll-pane').jScrollPane({
            showArrows: true,
			animateScroll: true
            //arrowScrollOnHover: true,
        });
		
    }
}


//function for scroller//////////////////////////////////////////////////////////////////////////////////////////////////////////
function buildInfoareaScroll(){
    if ($('.infoareaScroll').length) {
        $('.infoareaScroll').jScrollPane({
            showArrows: true,
			animateScroll: true
            //arrowScrollOnHover: true,
        });
    }
	
}

//function for highlight main menu/////////////////////////////////////////////////////////////////////////////////////////////////////////
function menuSelect(){
	if($('#menu').length){
			for (var i = 0; i < $('#menu a').length; i++) {
			var parentmenu = $('#menu').find('a').eq(i).html().toLowerCase();
			if ($(document).attr('title').indexOf(parentmenu) != -1) {
				$('#menu').find('a').eq(i).addClass("selected");
			    }
		    }
	}
}

//functions for slideshow/////////////////////////////////////////////////////////////////////////////////////////////////////////
function slideshow(){
    if ($('.slideshow').length) {
        $(".scrollable").scrollable({
			circular: true,
			mousewheel: true,
			speed:800
		}).navigator(// ul.tabs now functions as our navigator {navi:'ul.tabs'}
        {
            indexed: true
        }).autoscroll({
			autoplay:true,
			easing:'easeInOutSine',
			interval:5000
        });
        var api = $(".scrollable").data("scrollable");
       
        api.onSeek(function(){
            var targetIndex = this.getIndex();
			//alert('change');
            changeDescription(targetIndex);
        });	
        
    }
    
}

function menuActive(a){
    $('.infoarea>ul>li>h2').removeClass('active2');
    $('.infoarea>ul>li>h2').eq(a).addClass('active2');
}

function changeDescription(targetIndex){
    if ($('.projectname').length) {
        $('.projectname>div').fadeOut(0);
        $('.projectname>div').eq(targetIndex).delay(100).fadeIn('slow');
    }
}
function defaultActive(){
    changeDescription(0);
    menuActive(0)
}

//function for map//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function overlay(){
    // if the function argument is given to overlay,
    // it is assumed to be the onBeforeLoad event listener
    if ($("a[rel]").length) {
        $("a[rel]").overlay({
            mask: {
                color: '#000',
                opacity: 1
            },
            //effect: 'apple',
            left: 'center',
            top: 'center',
            onBeforeLoad: function(){
                // grab wrapper element inside content
                var wrap = this.getOverlay().find(".contentWrap");
                // load the page specified in the trigger
                wrap.load(this.getTrigger().attr("href"));
				wrap.css('display','none')
            },
            onLoad: function(){
				 var wrap = this.getOverlay().find(".contentWrap");
                 wrap.delay(300).fadeIn("slow","linear");
            },
			onBeforeClose:function(){
				if($('#myImageFlow').length){
					location.reload(true);
				}
			}
        });
        
        //close when resize the screen
        var overlayapi = $("a[rel]").data("overlay");
        $(window).resize(function(){
            overlayapi.close();
        });
    }
    
}
//function for individual project 1
function project(){
	if($('.projectbrief').length){
		$('.moreinfo').click(function(){
		$('.projectbrief').fadeToggle("slow","linear");
		$('.projectdetail').fadeToggle("slow","linear");
		
		})
	}
	
}
//function for individual project 2
function project2(){
	if($('.firstinfo').length){
		$('.firstinfo').click(function(){
			$('.firstinfo').fadeOut('slow');
		})
		$('.infobtn').click(function(){
			$('.firstinfo').fadeIn('slow');
		})
	}
}


//function for iPad css/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function checkBrowserType(){
    if (navigator.userAgent.indexOf("iPad") != -1 ||  navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
        if ($("#menu")) {
            $("#menu>ul>li").addClass("ipad");
            $("#menu>ul>li:last-child").removeClass("ipad");
        }
    }
	//navigator.userAgent.indexOf("Macintosh") != -1 ||
}


