﻿var currentFrontImage = 1;
var frontPageMax = 0;
var rotationDelay = 5000;
var fpImageObj;
function initMiniGal(){
    var loadCount = 0;
    var tmpImageObj;
    theVals = xmlDataReader('frontPage');
	fpImageObj = new Array((theVals.length+1));
	frontPageMax = (theVals.length+1);
	
	
	for (i = 0; i < (theVals.length+1); i++) {
	    if(i==0){
	        picSrc = "../img/ssFrontBlank.png";
	    }else{
	        picSrc = "../gallery/frontPage/" + theVals[(i-1)];
	    }
        fpImageObj[i] = new Image()
	    fpImageObj[i].onload = function() {
	        loadCount = (loadCount + 1);
	        if (loadCount == theVals.length + 1){
                if (checkIE()==1){
                    theHtml2=fixIE6(fpImageObj[0].src);
                    theHtml=fixIE6(fpImageObj[1].src);
                }else{
	                theHtml = "<img src='" + fpImageObj[1].src + "'" + "/>";
	                theHtml2 = "<img src='" + fpImageObj[0].src + "'" + "/>";
	            }
	            
	            $('#frontImgBg').html(theHtml2);
	            $('#frontImgGal').hide().html(theHtml).fadeIn(300);
	            currentFrontImage = (currentFrontImage + 2);
	            setTimeout("rotateFrontImg()",rotationDelay);
	        }
	    }
	    
	    
	    fpImageObj[i].src=picSrc;
	}
}
function rotateFrontImg(){
    if (checkIE()==1){
        theHtml=fixIE6(fpImageObj[currentFrontImage-1].src);
    }else{
        theHtml = "<img src='" + fpImageObj[(currentFrontImage-1)].src + "'" + "/>";
    }
    //$('#frontImgGal').fadeOut(600).fadeIn(600).html(theHtml);
    $('#frontImgGal').fadeOut(300,function(){$(this).html(theHtml);}).fadeIn(300);
    if (currentFrontImage == frontPageMax){
        currentFrontImage = 2;
    }else{
        currentFrontImage = (currentFrontImage + 1);
    }
    
    setTimeout("rotateFrontImg()",rotationDelay);
}
function checkIE(){
    var isOldIE = 0;
    var theBrowser=navigator.appVersion.toLowerCase();
    if ( theBrowser.indexOf('msie') != -1 ){
        tmpVar = theBrowser.split('msie');
        tmpVar1 = tmpVar[1].split(';');
        theVersion = tmpVar1[0].split('.');
        if ( theVersion[0] < 7 ){
            isOldIE = 1;
        }
    }
    return isOldIE;
}
function mnuHoverIn(theID){
    if (checkIE() != 1){
        document.getElementById(theID + 'HL').style.backgroundPosition = '0px';
    }else{
        var innerCode = "<span style=" + '"' + "width:80px;height:50px;display:inline-block;border:none;font-size:0px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/mnuHighLight.png',sizingMethod='image');" + '"' + "></span>";
        document.getElementById(theID + 'HL').innerHTML = innerCode;
    }
    //if (theID == 'mnuProducts'){
    //    subMenu(theID);
    //}
}
function mnuHoverOut(theID){
    if (checkIE() != 1){
        document.getElementById(theID + 'HL').style.backgroundPosition = '-70px';
        document.getElementById("ctl00_" + theID + "Title").style.backgroundPosition = '0px';
        
    }else{
        document.getElementById(theID + 'HL').innerHTML = "";
    }
    if (theID == 'mnuProducts'){
        //d = document.getElementById('subMenu');
        //document.body.removeChild(d);
    }
}
function mnuClickDown(theID,theDelta){
	if (checkIE() != 1){
        document.getElementById("ctl00_" + theID + "Title").style.backgroundPosition = "-" + theDelta + "px";
    }else{
        var innerCode = getIE6Stuff(theID, 'Down');
        document.getElementById("ctl00_" + theID + "Title").innerHTML = innerCode;
    }
}
function mnuClickUp(theID,theDelta){
	if (checkIE() != 1){
        document.getElementById("ctl00_" + theID + "Title").style.backgroundPosition = '0px';
    }else{
        var innerCode = getIE6Stuff(theID, 'Up');
        document.getElementById("ctl00_" + theID + "Title").innerHTML = innerCode;
    }
}
function getIE6Stuff(theID,theDir){
    
    var breakId = theID.split('mnu')
    var theTitle = breakId[1].toLowerCase() + 'MnuIE6' + theDir + '.png';

    var newImg = new Image();
    newImg.src = "img/ie6sux/" + theTitle;

    var height = newImg.height;
    var width = newImg.width;

    var innerCode = "<span style=" + '"' + "width:"+ width + "px;height:" + height +"px;display:inline-block;border:none;font-size:0px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/ie6sux/" + theTitle + "',sizingMethod='image');" + '"' + "></span>";
    return innerCode;
        
}
function fixIE6(theIMG, theWidth, theHeight, theSizing){
    var sizingMethod = 'scale';
    var newImg = new Image();
    newImg.src = theIMG;
    if (theSizing){
        sizingMethod = theSizing;
    }
    if (theWidth){
        var width=theWidth;
        var height=theHeight;
    }else{
        var height = newImg.height;
        var width = newImg.width;
    }
    var innerCode = "<span style=" + '"' + "width:"+ width + "px;height:" + height +"px;display:inline-block;border:none;font-size:0px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + theIMG + "',sizingMethod='"+sizingMethod+"');" + '"' + "></span>";
    return innerCode;
        
}

function subMenu(theID){
    anchorPos = getAnchorPosition(theID);
    //alert(anchorPos.x);
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'subMenu');
    newdiv.style.width = '150px';
    newdiv.style.height = '300px';
    newdiv.style.position = "absolute";
    newdiv.style.left = anchorPos.x + 'px';
    newdiv.style.top = (anchorPos.y + 30) + 'px';
    newdiv.style.backgroundImage = "url('img/subMnuBg.png')";
    newdiv.style.border = "none";
    document.body.appendChild(newdiv); 
}
function subMnuIn(theID){

    document.getElementById(theID).style.backgroundPosition = '-160px';
}
function ssSubMnuIn(theID){

    document.getElementById(theID).style.backgroundColor = '#432A26';
}

function subMnuOut(theID){
    document.getElementById(theID).style.backgroundPosition = '0px';
}
function ssSubMnuOut(theID){
    document.getElementById(theID).style.backgroundColor = '#2C1311';
    ssSubMnuBtnUp(theID);
}

function subMnuClick(theID){
    document.getElementById(theID).style.backgroundPosition = '-320px';

}
function ssSubMnuClick(theID){
    document.getElementById(theID + "Text").style.color = '#A8A8A8';
}
function ssSubMnuBtnUp(theID){
    document.getElementById(theID + "Text").style.color = '#F3F3F3';
}

function financeInx(cPos, fPos){
    var theElements=new Array("ctl00_mnuClickhere","ctl00_mnuFinancing");
    var thePos=new Array(cPos, fPos);
    if (checkIE() != 1){
        for (i=0; i <theElements.length; ++i){
            document.getElementById(theElements[i]).style.backgroundPosition = thePos[i];
        }
    }else{
        for (i=0; i <theElements.length; ++i){
        if (thePos[0] == '0px'){
            vDir = 'Up';
        }else{
            vDir = 'Down';
        }
        var innerCode = getIE6Stuff(theElements[i], vDir);
        document.getElementById(theElements[i]).innerHTML = innerCode;
        }
    }
}
function financeIn(theID, thePos){
    if (checkIE() != 1){
        document.getElementById("ctl00_" + theID).style.backgroundPosition = thePos;
        //alert("ctl00_" + theID);
    }else{
        if (thePos == '0px'){
            vDir = 'Up';
        }else{
            vDir = 'Down';
        }
        var innerCode = getIE6Stuff("ctl00_" + theID, vDir);
        document.getElementById("ctl00_" + theID).innerHTML = innerCode;
    }
}
function ulTxt(theID, theAct){
    if (theAct == 1){
        document.getElementById(theID + "Txt").style.textDecoration = "underline";
    }else{
        document.getElementById(theID + "Txt").style.textDecoration = "none";
    }
}
function btmBtn(theID, theAction){
    if (checkIE() != 1){
        if (theAction == 1){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Panel").style.backgroundPosition = "-235px";
        }else if (theAction == 0){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Panel").style.backgroundPosition = "0px";
        }else if (theAction == 2){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Img").style.backgroundPosition = "-202px";
        }else if (theAction == 3){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Img").style.backgroundPosition = "0px";
        }
    }else{
        var breakId = theID.split('Title');
        //alert(breakId[0]);
        if (theAction == 0){
            var theBreak = breakId[0] + "Panel";
            theID = theID + "Panel";
            theDir = "Up";
        }else if (theAction == 1){
            theDir = "Down";
            theID = theID + "Panel";
            var theBreak = breakId[0] + "Panel";
        }else if (theAction == 2){
            theDir = "Down";
            theID = theID + "Img";
            var theBreak = breakId[0];
            //alert(theBreak);
            //alert(theID);
        }else if (theAction == 3){
            theDir = "Up";
            theID = theID + "Img";
            var theBreak = breakId[0];
        }
        
        innerCode = getIE6Stuff(theBreak,theDir);
        document.getElementById("ctl00_mainContentContainer_" + theID).innerHTML = innerCode;

    }
}
function btmBtnGal(theID, theAction){
    if (checkIE() != 1){
        if (theAction == 1){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Panel").style.backgroundPosition = "-235px";
        }else if (theAction == 0){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Panel").style.backgroundPosition = "0px";
        }else if (theAction == 2){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Img").style.backgroundPosition = "-202px";
        }else if (theAction == 3){
            document.getElementById("ctl00_mainContentContainer_" + theID + "Img").style.backgroundPosition = "0px";
        }
    }else{
        var breakId = theID.split('Title');
        //alert(breakId[0]);
        if (theAction == 0){
            var theBreak = breakId[0] + "Panel";
            theID = theID + "Panel";
            theDir = "Up";
        }else if (theAction == 1){
            theDir = "Down";
            theID = theID + "Panel";
            var theBreak = breakId[0] + "Panel";
        }else if (theAction == 2){
            theDir = "Down";
            theID = theID + "Img";
            var theBreak = breakId[0] + "Gal";
            //alert(theBreak);
            //alert(theID);
        }else if (theAction == 3){
            theDir = "Up";
            theID = theID + "Img";
            var theBreak = breakId[0] + "Gal";
        }
        
        innerCode = getIE6Stuff(theBreak,theDir);
        document.getElementById("ctl00_mainContentContainer_" + theID).innerHTML = innerCode;

    }
}
function cursorIn(){
    document.body.style.cursor='pointer';
}
function cursorOut(){
    document.body.style.cursor='none';
}
function comingSoon(){
    alert('Coming Soon!');
}