function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/;domain="+document.domain+";";    
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');    
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];        
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//use browser sniffing to determine if IE or Opera (ugly, but required)
var isOpera, isIE, isIE6 = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && (navigator.userAgent.indexOf('MSIE')>=0))
{
    isIE = true;
    isIE6 = /msie (\d)\.\d/i.test(navigator.userAgent);
}

function goToURL(url)
{    
  if (!isIE)
  { 
    window.location.href = url;
  }
  else
  {
      var referLink = document.createElement('a');
      referLink.href = url;
      document.body.appendChild(referLink);    
      referLink.click();
  }  
}


var VerticalScrollPosition = 0;

function ScrollPersistSetup()
{
    VerticalScrollPosition = readCookie("ScrollPosition");    
    if (VerticalScrollPosition != null)
    {        
        $(window).scrollTo(VerticalScrollPosition, 0);
    }   
    $(window).scroll(function(){    
        if( typeof( window.pageYOffset ) == 'number' )
        {    
            VerticalScrollPosition = window.pageYOffset;    
        } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
        {    
            VerticalScrollPosition = document.body.scrollTop;    
        }     
    });
}

function TitleFadeIn()
{    
    ScrollPersistSetup();
    $(window).scrollTo(0, 0);
    $('#Framer').animate({opacity : 1}, loadSpeed*1000);
    $('.HeaderCussion').animate({opacity : 1}, loadSpeed*1000);
    $('a.TitleLink img').animate({opacity : 1}, loadSpeed*1000);
    $('#GalleryMenuStripe').animate({opacity : 1}, loadSpeed*1000);
    $('#LanguageMenuStripe').animate({opacity : 1}, loadSpeed*1000);
    $('#Flow').animate({opacity : 1}, loadSpeed*1000);
    $('#ShieldImage').animate({opacity : 1}, loadSpeed*1000);
    $('a.TT-GENERAL_INFO,a.TT-GENERAL_TITLE,a.TT-GENERAL_NEWS').click(function(){        
        createCookie("ScrollPosition",VerticalScrollPosition, 1);        
        return TitleToInfoLeave(this);
    });
    $('a.TT-GENERAL_GALLERY').click(function(){
        createCookie("ScrollPosition",VerticalScrollPosition, 1);
        return TitleToGalleryLeave(this);
    });
}

function InfoFadeIn()
{    
    ScrollPersistSetup();
    $(window).scrollTo(0, 0);
    $('#Framer').animate({opacity : 1}, loadSpeed*1000);
    $('.HeaderCussion').animate({opacity : 1}, loadSpeed*1000);
    $('a.TitleLink img').animate({opacity : 1}, loadSpeed*1000);
    $('#GalleryMenuStripe').animate({opacity : 1}, loadSpeed*1000);
    $('#LanguageMenuStripe').animate({opacity : 1}, loadSpeed*1000);
    $('#Flow').animate({opacity : 1}, loadSpeed*1000);
    $('#ShieldImage').animate({opacity : 1}, loadSpeed*1000);
    $('a.TT-GENERAL_INFO,a.TT-GENERAL_TITLE,a.TT-GENERAL_NEWS').click(function(){        
        createCookie("ScrollPosition",VerticalScrollPosition, 1);
        return TitleToInfoLeave(this);
    });
    $('a.TT-GENERAL_GALLERY').click(function(){
        createCookie("ScrollPosition",VerticalScrollPosition, 1);
        return TitleToGalleryLeave(this);
    });
}

function GalleryFadeIn()
{    
    ScrollPersistSetup();
    $(window).scrollTo(0, 0);
    $('#Framer').animate({opacity : 1}, loadSpeed*1000);
    $('.HeaderCussion').animate({opacity : 1}, loadSpeed*1000);
    $('a.TitleLink img').animate({opacity : 0.3}, loadSpeed*1000);
    $('#GalleryMenuStripe').animate({opacity : 1}, loadSpeed*1000);
    $('#LanguageMenuStripe').animate({opacity : 1}, loadSpeed*1000);
    $('#Flow').animate({opacity : 0.6}, loadSpeed*1000);
    $('a.GalleryLink span').animate({opacity: 0.5}, loadSpeed*1000);
    $('.GMLangLink').animate({opacity: 0.5}, loadSpeed*1000);
    $('.MembershipLinks').animate({opacity: 0.5}, loadSpeed*1000);    
    $('#ShieldImage').animate({opacity : 1}, loadSpeed*1000);
    $('table.SampleTable').animate({opacity : 1}, loadSpeed*1000);
    $('a.TT-GENERAL_INFO,a.TT-GENERAL_TITLE,a.TT-GENERAL_NEWS').click(function(){        
        createCookie("ScrollPosition",VerticalScrollPosition, 1);
        return GalleryToInfoLeave(this);
    });
    $('a.TT-GENERAL_TITLE').click(function(){        
        createCookie("ScrollPosition",VerticalScrollPosition, 1);
        return GalleryToTitleLeave(this);
    });
    $('a.TT-GENERAL_GALLERY').click(function(){
        createCookie("ScrollPosition",VerticalScrollPosition, 1);
        return GalleryToGalleryLeave(this);
    });
    DisplayImage(0);
}

function TitleToInfoLoad()
{
    ScrollPersistSetup();
     $('a.TT-GENERAL_TITLE,a.TT-GENERAL_INFO, a.TT-GENERAL_GALLERY,a.TT-GENERAL_NEWS').click(function(){        
        return InfoLeave(this);
    });
    $('#PayLoad').animate({opacity : 1}, transFadeSpeed*1000);
    $('#ShieldImage').animate({opacity : 1}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 1}, transFadeSpeed*1000);
}

function InfoLeave(caller)
{
    caller.blur();
    $('#ShieldImage').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PayLoad').animate({opacity : 0}, transFadeSpeed*1000, function(){
        createCookie("ScrollPosition",VerticalScrollPosition, 1);        
        goToURL(caller);        
    });
    return false;
}

function InfoToTitleLoad()
{
    ScrollPersistSetup();
    $('a.TT-GENERAL_INFO,a.TT-GENERAL_TITLE,a.TT-GENERAL_NEWS').click(function(){        
        return TitleToInfoLeave(this);
    });
    $('a.TT-GENERAL_GALLERY').click(function(){        
        return TitleToGalleryLeave(this);
    });
    $('#ShieldImage').animate({opacity : 1}, transFadeSpeed*1000);
    $('#PayLoad').animate({opacity : 1}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 1}, transFadeSpeed*1000);
    $('#NewsStripe').animate({opacity : 1}, transFadeSpeed*1000);
    $('#RightColumnSplitter').animate({opacity : 1}, transFadeSpeed*1000);    
}

function TitleToInfoLeave(caller)
{
    caller.blur();
    $('#ShieldImage').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PayLoad').animate({opacity : 0}, transFadeSpeed*1000);
    $('#NewsStripe').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 0}, transFadeSpeed*1000);
    $('#RightColumnSplitter').animate({opacity : 0}, transFadeSpeed*1000, function(){
        createCookie("ScrollPosition",VerticalScrollPosition, 1);        
        goToURL(caller);        
    });
    return false;
}

function TitleToGalleryLeave(caller)
{
    caller.blur();
    $('#ShieldImage').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PayLoad').animate({opacity : 0}, transFadeSpeed*1000, function(){
        createCookie("ScrollPosition",VerticalScrollPosition, 1);
        goToURL(caller);        
    });
    $('#NewsStripe').animate({opacity : 0}, transFadeSpeed*1000);
    
    return false;
}

function TitleInfoToGalleryLoad()
{
    ScrollPersistSetup();    
    
    $('a.TT-GENERAL_INFO,a.TT-GENERAL_NEWS').click(function(){        
        return GalleryToInfoLeave(this);
    });
    $('a.TT-GENERAL_TITLE').click(function(){        
        return GalleryToTitleLeave(this);
    });
    $('a.TT-GENERAL_GALLERY').click(function(){        
        return GalleryToGalleryLeave(this);
    });     
    $('#Shield').animate({backgroundColor: "#262626", height: "700px"}, transSizeSpeed*1000);
    $('#ShadowMiddle').animate({height: "640px"}, transSizeSpeed*1000);
    $('#ColumnSplitters').animate({marginTop: "740px"}, transSizeSpeed*1000);
    $('.TitleLink').animate({opacity: 0.3}, transSizeSpeed*1000);
    $('#GalleryMenuStripe').animate({top: "578px"}, transSizeSpeed*1000);
    $('a.GalleryLink span').animate({opacity: 0.5}, transSizeSpeed*1000);
    $('.GMLangLink').animate({opacity: 0.5}, transSizeSpeed*1000);
    $('.MembershipLinks').animate({opacity: 0.5}, transSizeSpeed*1000);    
    $('#Flow').animate({opacity: 0.6}, transSizeSpeed*1000);
    $('#RightColumnSplitter').animate({opacity : 1}, transSizeSpeed*1000);
    $('#LeftColumnSplitter').animate({marginLeft : "350px"}, transSizeSpeed*1000, function(){        
        $('table.SampleTable').animate({opacity : 1}, transFadeSpeed*1000);
        $('#LeftGalleryMenuStripe').animate({opacity : 1}, transFadeSpeed*1000);
        $('#RightGalleryMenuStripe').animate({opacity : 1}, transFadeSpeed*1000);
        $('h1.GalleryH1, h4').animate({opacity : 1}, transFadeSpeed*1000);
        $('#PageFooter').animate({opacity : 1}, transFadeSpeed*1000);
        DisplayImage(0, function()
        {
            
        });
    });    
}

function GalleryToGalleryLoad(shift, sampleshift)
{        
    ScrollPersistSetup();    
    //if (shift) DisplayPreviousImage();
    
    $('a.TT-GENERAL_INFO,a.TT-GENERAL_NEWS').click(function(){        
        return GalleryToInfoLeave(this);
    });
    $('a.TT-GENERAL_TITLE').click(function(){        
        return GalleryToTitleLeave(this);
    });
    $('a.TT-GENERAL_GALLERY').click(function(){        
        return GalleryToGalleryLeave(this);
    });
    $('table.SampleTable').animate({opacity : 1}, transFadeSpeed*1000);
    
    if ($("table.SampleTable").length == 0)
    {
        DisplayImage(0, function()
        {
            if (!shift)
            {    
                $('h1.GalleryH1, h4').animate({opacity : 1}, transFadeSpeed*1000);     
                $('#LeftGalleryMenuStripe').animate({opacity : 1}, transFadeSpeed*1000);
                $('#RightGalleryMenuStripe').animate({opacity : 1}, transFadeSpeed*1000);           
            }
        });
    }
    else
    {
        if (!shift)
            {    
                $('h1.GalleryH1, h4').animate({opacity : 1}, transFadeSpeed*1000);     
                $('#LeftGalleryMenuStripe').animate({opacity : 1}, transFadeSpeed*1000);
                $('#RightGalleryMenuStripe').animate({opacity : 1}, transFadeSpeed*1000);           
            }
    }
    
    
    
}

function GalleryToTitleLoad()
{
    ScrollPersistSetup();
    $('a.TT-GENERAL_INFO,a.TT-GENERAL_TITLE,a.TT-GENERAL_NEWS').click(function(){        
        return TitleToInfoLeave(this);
    });
    $('a.TT-GENERAL_GALLERY').click(function(){        
        return TitleToGalleryLeave(this);
    });
    $('#ShieldImage').animate({opacity : 1}, transFadeSpeed*1000);
    $('#PayLoad').animate({opacity : 1}, transFadeSpeed*1000);
    $('#NewsStripe').animate({opacity : 1}, transFadeSpeed*1000);
    $('#RightColumnSplitter').animate({opacity : 1}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 1}, transFadeSpeed*1000);
}

function GalleryToGalleryLeave(caller, shift)
{            
    if (!shift) caller.blur();
    $("#ImageHolder").stop();    
    if (!isIE)
    {
        $('table.SampleTable').animate({opacity : 0}, transFadeSpeed*1000);
    }    
    $('#ThumbnailStripe').animate({opacity : 0}, transFadeSpeed*1000);
    if (!shift)
    {
        CancelSlideShow();
        $("#NewCorner").animate({opacity : 0}, transFadeSpeed*1000);
        $("#ImageHolder").animate({opacity : 0}, transFadeSpeed*1000);
        $('#LeftGalleryMenuStripe').animate({opacity : 0}, transFadeSpeed*1000);
        $('#RightGalleryMenuStripe').animate({opacity : 0}, transFadeSpeed*1000);
        $('h1.GalleryH1, h4').animate({opacity : 0}, transFadeSpeed*1000, function(){
            createCookie("ScrollPosition",VerticalScrollPosition, 1);
            goToURL(caller);        
        });
    }
    else
    {
        if (!isIE)
        {
            //$("#NewCorner").animate({opacity : 0}, transFadeSpeed*1000);
            //$('a#SlideRight').animate({opacity : 0.3}, transFadeSpeed*1000);
            //$('a#SlideLeft').animate({opacity : 0.3}, transFadeSpeed*1000);
            //$("#ImageHolder").animate({opacity : 0}, transFadeSpeed*1000, function(){
                createCookie("ScrollPosition",VerticalScrollPosition, 1);
                goToURL(caller);        
            //});
        }
        else
        {
            /*
            $("#NewCorner").animate({opacity : 0}, transFadeSpeed*1000);
            if ($("#ImageHolder").length > 0)
            {
                $("#ImageHolder").animate({opacity : 0}, transFadeSpeed*1000, function(){
                    createCookie("ScrollPosition",VerticalScrollPosition, 1);
                    goToURL(caller);        
                });
            }
            else
            {*/
                createCookie("ScrollPosition",VerticalScrollPosition, 1);
                goToURL(caller);
            //}
        }
    }

    return false;
}

function GalleryToTitleLeave(caller)
{
    caller.blur();
    $("#ImageHolder").animate({opacity : 0}, transFadeSpeed*1000);
    $('table.SampleTable').animate({opacity : 0}, transFadeSpeed*1000);
    $("#NewCorner").animate({opacity : 0}, transFadeSpeed*1000);
    $('#ThumbnailStripe').animate({opacity : 0}, 1000);
    $('#LeftGalleryMenuStripe').animate({opacity : 0}, transFadeSpeed*1000);
    $('#RightGalleryMenuStripe').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 0}, transFadeSpeed*1000);
    $('h1.GalleryH1, h4').animate({opacity : 0}, transFadeSpeed*1000, function(){        
        $('#Shield').animate({backgroundColor: "#404040", height: "470px"}, transSizeSpeed*1000);
        $('#ShadowMiddle').animate({height: "410px"}, transSizeSpeed*1000);
        $('#ColumnSplitters').animate({marginTop: "510px"}, transSizeSpeed*1000);
        $('#LeftColumnSplitter').animate({marginLeft: "250px"}, transSizeSpeed*1000);
        $('.TitleLink').animate({opacity: 1}, transSizeSpeed*1000);
        $('#GalleryMenuStripe').animate({top: "348px"}, transSizeSpeed*1000);
        $('a.GalleryLink span').animate({opacity: 1}, transSizeSpeed*1000);
        $('.GMLangLink').animate({opacity: 1}, transSizeSpeed*1000);        
        $('.MembershipLinks').animate({opacity: 1}, transSizeSpeed*1000, function(){
            createCookie("ScrollPosition",VerticalScrollPosition, 1);
            goToURL(caller);
        });    
    });
    return false;
}

function GalleryToInfoLeave(caller)
{
    caller.blur();
    $("#ImageHolder").animate({opacity : 0}, transFadeSpeed*1000);
    $('table.SampleTable').animate({opacity : 0}, transFadeSpeed*1000);
    $("#NewCorner").animate({opacity : 0}, transFadeSpeed*1000);
    $('#ThumbnailStripe').animate({opacity : 0}, transFadeSpeed*1000);
    $('#LeftGalleryMenuStripe').animate({opacity : 0}, transFadeSpeed*1000);
    $('#RightGalleryMenuStripe').animate({opacity : 0}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 0}, transFadeSpeed*1000);
    $('h1.GalleryH1, h4').animate({opacity : 0}, transFadeSpeed*1000, function(){        
        $('#Shield').animate({backgroundColor: "#404040", height: "470px"}, transSizeSpeed*1000);
        $('#ShadowMiddle').animate({height: "410px"}, transSizeSpeed*1000);
        $('#ColumnSplitters').animate({marginTop: "510px"}, transSizeSpeed*1000);
        $('#LeftColumnSplitter').animate({marginLeft: "250px"}, transSizeSpeed*1000);
        $('#RightColumnSplitter').animate({opacity: 0}, transSizeSpeed*1000);
        $('.TitleLink').animate({opacity: 1}, transSizeSpeed*1000);
        $('#GalleryMenuStripe').animate({top: "348px"}, transSizeSpeed*1000);
        $('a.GalleryLink span').animate({opacity: 1}, transSizeSpeed*1000);
        $('.GMLangLink').animate({opacity: 1}, transSizeSpeed*1000);
        $('.MembershipLinks').animate({opacity: 1}, transSizeSpeed*1000, function(){
            createCookie("ScrollPosition",VerticalScrollPosition, 1);
            goToURL(caller);
        });    
    });
    return false;
}

function GalleryToInfoLoad()
{
    ScrollPersistSetup();
     $('a.TT-GENERAL_TITLE,a.TT-GENERAL_INFO, a.TT-GENERAL_GALLERY,a.TT-GENERAL_NEWS').click(function(){        
        return InfoLeave(this);
    });
    $('#PayLoad').animate({opacity : 1}, transFadeSpeed*1000);
    $('#ShieldImage').animate({opacity : 1}, transFadeSpeed*1000);
    $('#PageFooter').animate({opacity : 1}, transFadeSpeed*1000);
}





