var flyoutOpen = null;
var lightboxOpen = null;

function loadLightbox(id) {
	var width = $(window).width();
	var newWidth = width-1044
	var finalWidth = newWidth/2
	//console.log(finalWidth);
	$('.infoLightbox').css('left',finalWidth+'px');

    if (welcomeOpen = true) {
        $('.welcomeCard').animate({
            opacity: 0
        },
        400,
        function() {
            var welcomeOpen = false;
            $('.welcomeCard').css('display', 'none');

        });

        $('.infoLightbox').load(id + '.html');
        $('.infoLightbox').css('display','block')
        $('.infoLightbox').animate({
            opacity: 1
        },
        500,
        function() {
            lightboxOpen = true;

        });

    } else {



        $('.infoLightbox').load(id + '.html');
        $('.infoLightbox').animate({
            opacity: 1
        },
        1000,
        function() {
            lightboxOpen = true;

        });

    }

}

function setUpClients(){
	 $('.infoLightbox').css('background','url(img/lighboxBg_client.png)')
	 $('.infoLightbox').css('height','700px')
}

function setUpVideo(){
	 $('.infoLightbox').css('background','url(img/lighboxBg_client.png)')
	 $('.infoLightbox').css('height','700px')
}

function revertBg(){
	 $('.infoLightbox').css('background','url(img/about.jpg)')
	 $('.infoLightbox').css('height','756px')
	
}


function closeLightbox() {
    $('.infoLightbox').animate({
        opacity: 0
    },
    500,
    function() {
    	$('.infoLightbox').css('display','none')
        lightboxOpen = false;

    });

}




function swapBg(id) {

    var myCaptions = $('.captionFlyout');
    var myThumbs = $('ul.thumbsGallery li');
    var myThumbsAdd = $('ul.thumbsGallery li.' + id);

    myThumbs.removeClass('selected');
    myThumbsAdd.addClass('selected');

    $.getJSON('js/BgImages.js',
    function(data) {
        //alert(data[id]);
        $('.bg').animate({
            opacity: 0
        },
        300,
        function() {

            $('.bg').attr('src', data[id]);
            $('.bg').bind('load',
            function() {

                // alert('Load was performed.');
                setTimeout('resizeShiz()',0);
                $('.bg').animate({
                    opacity: 1
                },
                300,
                function() {
                    
                    });

            });

        });

    });
    //myCaptions.load('captions.html  #' + id);
}


function loadWelcome(id) {


    //$('.welcomeCard').css('display', 'block');
    $('.welcomeCard').animate({
        opacity: 1
    },
    1000,
    function() {
        welcomeOpen = true;

    });

};

function hideNav(){
	$('.galleryRight').animate({
        opacity: 0
    },
    300,
    function() {
       

    });
    $('.galleryLeft').animate({
        opacity: 0
    },
    300,
    function() {
       

    });


}

$('.galleryLeft').live('mouseenter',
function() {

	
	$('.galleryLeft').animate({
        opacity: .65
    },
    300,
    function() {
       

    });

});

$('.galleryLeft').live('mouseleave',
function() {
	$('.galleryLeft').animate({
        opacity: 0
    },
    300,
    function() {
       

    });
	

});

$('.galleryRight').live('mouseenter',
function() {

	$('.galleryRight').animate({
        opacity: 1.00
    },
    300,
    function() {
       

    });

});

$('.galleryRight').live('mouseleave',
function() {
	$('.galleryRight').animate({
        opacity: 0
    },
    300,
    function() {
       

    });
	

});




function loadDefaults() {
    $('ul.thumbsGallery').load('waterWorld.html');
    //$('.captionFlyout').load('captions.html #default');

}

$(window).load(function() {
    setTimeout('loadDefaults()', 0);
    setTimeout('hideNav()', 3000);
    setTimeout('loadWelcome("water1")',1000);
});



function loadGallery(galleryId, bgId) {
    $('ul.galleryNavigation a').removeClass('selected');
    $('ul.galleryNavigation a.' + galleryId).addClass('selected');
    $('ul.thumbsGallery').load(galleryId + '.html');

    $.getJSON('js/BgImages.js',
    function(data) {
        //alert(data[id]);
        $('.bg').animate({
            opacity: 0
        },
        300,
        function() {

            $('.bg').attr('src', data[bgId]);
            $('.bg').bind('load',
            function() {

                //alert('Load was performed.');
                setTimeout('resizeShiz()',0);
                $('.bg').animate({
                    opacity: 1
                },
                300,
                function() {
                    
                    });

            });

        });

    });


    //$('.captionFlyout').load('captions.html  #' + bgId);



}


$('.galleryNav').live('mouseenter mouseleave',
function() {
    if (!flyoutOpen) {
        setTimeout(function() {
            $('.thumbsFlyout').css('display', 'block');
            $('.thumbsFlyout').animate({
                opacity: 1
            },
            300,
            function() {
                flyoutOpen = true;
            });

            $('.welcomeCard').animate({
                opacity: 0
            },
            400,
            function() {
                var welcomeOpen = false;
                $('.welcomeCard').css('display', 'none');

            });

        },
        100)

    } else {
        $('.thumbsFlyout').animate({
            opacity: 0
        },
        300,
        function() {
            $('.thumbsFlyout').css('display', 'none');
            flyoutOpen = null;
        });
    }
});



$('.captionNav').live('mouseenter mouseleave',
function() {
    if (!flyoutOpen) {
        setTimeout(function() {
            $('.captionFlyout').css('display', 'block');
            $('.captionFlyout').animate({
                opacity: 1
            },
            300,
            function() {
                flyoutOpen = true;
            });

            $('.welcomeCard').animate({
                opacity: 0
            },
            400,
            function() {
                welcomeOpen = false;
                $('.welcomeCard').css('display', 'none');

            });

        },
        100)



    } else {
        $('.captionFlyout').animate({
            opacity: 0
        },
        300,
        function() {
            $('.captionFlyout').css('display', 'none');
            flyoutOpen = null;
        });
    }
});



$('.galleryRight').live('click',
function() {

$('.welcomeCard').animate({
            opacity: 0
        },
        400,
        function() {
            var welcomeOpen = false;
            $('.welcomeCard').css('display', 'none');

        });

    var loadId = 'images1'

    var id = $('ul.thumbsGallery li.selected').next().attr('class');


    $('ul.thumbsGallery li').removeClass('selected');
    $('ul.thumbsGallery li.' + id).addClass('selected');

    $.getJSON('js/BgImages.js',
    function(data) {
        //alert(data[id]);
        $('.bg').animate({
            opacity: 0
        },
        300,
        function() {

            $('.bg').attr('src', data[id]);
            $('.bg').bind('load',
            function() {

                //alert('Load was performed.');
                $('.bg').animate({
                    opacity: 1
                },
                300,
                function() {
                    // Animation complete.
                    });

            });

        });

    });


    if (!currentItem) {
        currentItem = $('ul.thumbsGallery li:first');

        var margin = currentItem.width();

        $('ul.thumbsGallery').animate({
            marginLeft: '-287px'
        },
        500,
        function() {
            $(this).find('li:last').after(currentItem);
            $(this).css('marginLeft', '-169px')
            currentItem = null;
        });
    }


    $('.captionFlyout').load('captions.html  #' + id);
});



$('.galleryLeft').live('click',
function() {

$('.welcomeCard').animate({
            opacity: 0
        },
        400,
        function() {
            var welcomeOpen = false;
            $('.welcomeCard').css('display', 'none');

        });

    var loadId = 'images1'

    var id = $('ul.thumbsGallery li.selected').prev().attr('class');


    $('ul.thumbsGallery li').removeClass('selected');
    $('ul.thumbsGallery li.' + id).addClass('selected');

    $.getJSON('js/BgImages.js',
    function(data) {
        //alert(data[id]);
        $('.bg').animate({
            opacity: 0
        },
        300,
        function() {

            $('.bg').attr('src', data[id]);
            $('.bg').bind('load',
            function() {

                //alert('Load was performed.');
                $('.bg').animate({
                    opacity: 1
                },
                300,
                function() {
                    // Animation complete.
                    });

            });

        });

    });


    if (!currentItem) {
        currentItem = $('ul.thumbsGallery li:last');

        var margin = currentItem.width();

        $('ul.thumbsGallery').animate({
            marginLeft: '-51px'
        },
        500,
        function() {
            $(this).find('li:first').before(currentItem);
            $(this).css('marginLeft', '-169px')
            currentItem = null;
        });
    }


    $('.captionFlyout').load('captions.html  #' + id);

});



function json(id) {

    $.getJSON('js/BgImages.js',
    function(data) {
        //alert(data[id]);
        $('.bg').animate({
            opacity: 0
        },
        300,
        function() {

            $('.bg').attr('src', data[id]);
            $('.bg').bind('load',
            function() {

                //alert('Load was performed.');
                $('.bg').animate({
                    opacity: 1
                },
                300,
                function() {
                    // Animation complete.
                    });

            });

        });

    });
}

function socialHoversLI(){
	$('a.linkedIn').css('opacity','0')
	$('a.linkedIn').css('background','url(img/icon_linkedInH.png)').animate({
            opacity: 1
        },
        200,
        function() {
           
        });

}

function socialHoversOutLI(){
	$('a.linkedIn').animate({
            opacity: 0
        },
        200,
        function() {
           $('a.linkedIn').css('background','url(img/icon_linkedIn.png)')
           $('a.linkedIn').css('opacity','1')
        });

}

function socialHoversFB(){
	$('a.fb').css('opacity','0')
	$('a.fb').css('background','url(img/icon_facebookH.png)').animate({
            opacity: 1
        },
        200,
        function() {
           
        });
        
    $('.fbLike').css('display','block')
    $('.fbLike').animate({
            opacity: 1
        },
        200,
        function() {
           
        });

        

}

function socialHoversOutFB(){
	$('a.fb').animate({
            opacity: 0
        },
        200,
        function() {
           $('a.fb').css('background','url(img/icon_facebook.png)')
           $('a.fb').css('opacity','1')
        });
        
        setTimeout('hideFbHover()',3000); 
        
         

}


function hideFbHover(){
	$('.fbLike').animate({
            opacity: 0
        },
        200,
        function() {
        
         $('.fbLike').css('display','none')
           
        });
}

function socialHoversTwitter(){
	$('a.twitter').css('opacity','0')
	$('a.twitter').css('background','url(img/icon_twitterH.png)').animate({
            opacity: 1
        },
        200,
        function() {
           
        });

}

function socialHoversOutTwitter(){
	$('a.twitter').animate({
            opacity: 0
        },
        200,
        function() {
           $('a.twitter').css('background','url(img/icon_twitter.png)')
           $('a.twitter').css('opacity','1')
        });

}

$('.ieWarning a.close').live('click',
function() {
	$('.ieWarning').css('display','none')
        });





$(window).resize(function() {
	var width = $(window).width();
	var newWidth = width-1044
	var finalWidth = newWidth/2
	//console.log(finalWidth);
	$('.infoLightbox').css('left',finalWidth+'px');
  
});

$(window).resize(function() {
	var width = $(window).width();
	var newWidth = width-400
	var finalWidth = newWidth/2
	//console.log(finalWidth);
	$('.loadingWrapper').css('left',finalWidth+'px');
  
});

$(document).ready(function() {
	var width = $(window).width();
	var newWidth = width-400
	var finalWidth = newWidth/2
	//console.log(finalWidth);
	$('.loadingWrapper').css('left',finalWidth+'px');
  
});

$(window).resize(function() {
	var width = $(window).width();
	var newWidth = width-175
	var finalWidth = newWidth/2
	//console.log(finalWidth);
	$('.galleryNav').css('left',finalWidth+'px');
  
});

$(document).ready(function() {
	var width = $(window).width();
	var newWidth = width-175
	var finalWidth = newWidth/2
	//console.log(finalWidth);
	$('.galleryNav').css('left',finalWidth+'px');
  
});

$(window).resize(function() {
	var height = $(window).height();
	var finalHeight = height-39;
	var windowWidth = $(window).width();
	var imgWidth = $('#bgWrapper #default img').attr('width');
	var newWidth = windowWidth-imgWidth
	var finalWidth = newWidth/2
	//console.log(height);
	//$('#bgWrapper').css('position','absolute');
	$('#bgWrapper').css('width','auto');
	$('#bgWrapper').css('position','absolute');
	$('#bgWrapper').css('height',finalHeight+'px');
	$('#bgWrapper').css('left',finalWidth+'px');
	$('#bgWrapper #default img').css('height',finalHeight+'px');
	
  
});

$(window).load(function() {
	//$('#bgWrapper').css('display','none');	
	var height = $(window).height();
	var finalHeight = height-39;
	var windowWidth = $(window).width();
	$('#bgWrapper #default img').css('height',finalHeight+'px');
	var imgHeight = $('#bgWrapper #default img').attr('height');
	var divisor = imgHeight/.67
	var left = windowWidth-divisor
	var newLeft = left/2
	//console.log(newLeft)
	//console.log(divisor);
	//$('#bgWrapper').css('position','absolute');
	//$('#bgWrapper').css('height',finalHeight+'px');
	$('#bgWrapper').css('left',newLeft+'px');
	$('#bgWrapper').css('width','auto');
	$('#bgWrapper').css('position','absolute');
	$('#bgWrapper #default img').css('height',finalHeight+'px');
	$('#bgWrapper').animate({
        opacity: 1
    },
    300,
    function() {
       

    });
  
});


function maximizeHack(){

$(window).resize(function() {
	var height = $(window).height();
	var finalHeight = height-39;
	var windowWidth = $(window).width();
	var imgWidth = $('#bgWrapper #default img').attr('width');
	var newWidth = windowWidth-imgWidth
	var finalWidth = newWidth/2
	//console.log(height);
	//$('#bgWrapper').css('position','absolute');
	$('#bgWrapper').css('width','auto');
	$('#bgWrapper').css('position','absolute');
	$('#bgWrapper').css('height',finalHeight+'px');
	$('#bgWrapper').css('left',finalWidth+'px');
	$('#bgWrapper #default img').css('height',finalHeight+'px');
	//console.log('running!')
	
});

}

setTimeout('maximizeHack()',0);

function resizeShiz(){
var height = $(window).height();
	var finalHeight = height-39;
	var windowWidth = $(window).width();
	var imgWidth = $('#bgWrapper #default img').attr('width');
	var newWidth = windowWidth-imgWidth
	var finalWidth = newWidth/2
	//console.log(height);
	//$('#bgWrapper').css('position','absolute');
	$('#bgWrapper').css('width','auto');
	$('#bgWrapper').css('position','absolute');
	$('#bgWrapper').css('height',finalHeight+'px');
	$('#bgWrapper').css('left',finalWidth+'px');
	$('#bgWrapper #default img').css('height',finalHeight+'px');
	//console.log('running!')

}

