var pg = {};
var methodName = { a1: "红雪redsn0w", a2: "绿雨一键越狱", a3: "Spirit一键越狱", a4: "JailbreakMe越狱", a5: "绿毒A5越狱", a6: "绿毒A4越狱",a7:"红雪redsn0w(非完美越狱)",a8:"绿毒IOS5.1.1完美越狱" };

var yueyuData = {
	 iPhone_4S: {
		v5_1_1: "8", v5_0_1: "5", v5_0: "5"
	},
	 iPhone_4: {
		v5_1_1: "8",v5_1:"7",  v5_0_1: "1", v5_0: "1", v4_3_5: "7", v4_3_4: "1", v4_3_3: "1,4", v4_3_2: "1", v4_3_1: "1", v4_2_1: "1,6", v4_1: "2", v4_0_2: "2", v4_0_1: "2,4"
	},
	 iPhone_3GS: {
		v5_1_1: "8",v5_1:"7",   v5_0_1: "1", v5_0: "1", v4_3_5: "7", v4_3_4: "1", v4_3_3: "1,4", v4_3_2: "1", v4_3_1: "1", v4_3: "1",v4_2_1: "1,6",  v4_1: "2", v4_0_2: "2", v4_0_1: "2,4", v4_0: "2,4", v3_1_3: "3,4", v3_1_2: "3,4"
	 },
	iPhone_1: {
		 v3_1_3: "3", v3_1_2: "3"
	},
	iPad_3:{
		v5_1_1:"8"},
	iPad_2: { 
		v5_1_1: "8",v5_0_1: "5", v4_3_3: "4"
	},
	iPad_1: {
		v5_1_1: "8", v5_1:"7", v5_0_1: "1", v5_0: "1", v4_3_5: "7", v4_3_4: "1", v4_3_3: "1", v4_3_2: "1", v4_3_1: "1", v4_2_1: "1,6", v3_2_2: "2,4", v3_2_1: "2,4", v3_2: "2,4"
	},
	 iPod_4: {
		v5_1_1: "8",v5_1:"7",  v5_0_1: "1", v5_0: "1", v4_3_5: "7", v4_3_4: "1", v4_3_3: "1,4", v4_3_2: "1", v4_3_1: "1", v4_2_1: "1,6", v4_1: "2"
	},
	 iPod_3: {
		v5_1_1: "8",v5_1:"7",  v5_0_1: "1", v5_0: "1", v4_3_5: "7", v4_3_4: "1", v4_3_3: "1", v4_3_2: "1", v4_3_1: "1", v4_2_1: "1,6", v4_1: "2", v4_0_0: "4", v3_1_3: "3,4", v3_1_2: "3,4"
	}
};

var ios, url,displaybox, deviceList1, deviceList2, myiPhoneType, myiPhoneVersion, actIframe, strHTML, rightIOS, rightMethod, rightIOSList, rightMethodList, methods, defaultType, defaultDevice, defaultVersion, defaultIOS, methodNum;

try {
    myiPhoneType = external.MyiPhoneType();
    myiPhoneVersion = external.MyiPhoneVersion();
}catch (e) {
}

myiPhoneType = !myiPhoneType ? "" : myiPhoneType;
myiPhoneVersion = !myiPhoneVersion ? "" : myiPhoneVersion;
displaybox=!myiPhoneVersion? false : true ;

function makeDeviceList() {
    strHTML = "";
    var x = 0,mainVer;
    defaultType = 0;
    defaultDevice = "";
    for (i in yueyuData) {
        strHTML += '<li><a  title="' + i.replace("_", " ")
         + '完美越狱" target="actIframe" href="javascript:void(0)" onclick="changeType(\'' + i + '\')">'
          + i.replace("_", " ") + "</a></li>";
        //默认显示
        if (myiPhoneType != "" && myiPhoneVersion != "") {
            if (i.replace(/\_/g, " ") == myiPhoneType) {
                defaultType = x;
                defaultDevice = i;
            }
        }else {
            if (x == 0) {
                defaultDevice = i;
            }
        }
        x++;
    }
    $("#deviceList1") .html(strHTML);
}

function changeType(type) {
    strHTML = "";
    var s = 0;
    var yy = 0;
    for (y in yueyuData[type]) {
        yy++;
    }
    for (x in yueyuData[type]) {
        strHTML += '<li class="pgType"><a title="' + type.replace(/\_/g, " ") + x.replace(/\_/g, ".").replace("v", " ") + '完美越狱" href="javascript:void(0)" target="actIframe" onclick="methodTab(\'' + yueyuData[type][x] + '\',\'' + x + '\')">' + x.replace(/\_/g, ".").replace("v", "");
        if (s < yy-1) {
            strHTML += "</a></li><li class=\"lineV\">|</li>";
        }
        if (myiPhoneVersion != "" && type.replace(/\_/g, " ") == myiPhoneType) {
            if (x.replace(/\_/g, ".").replace("v", "") == myiPhoneVersion) {
                defaultVersion = yueyuData[type][x];
                defaultIOS = x;
                methodNum = s;
            }
        }else {
            if (s == 0) {
                defaultIOS = x;
                defaultVersion = yueyuData[type][defaultIOS];
                methodNum = 0;
            }
        }
        s++;   
    }

    changeHtml();
   methodTab(defaultVersion, defaultIOS);
    $("#rightIOSList").html(strHTML);
    rightVersionHover();
}
function changeHtml() {
    if (defaultVersion.indexOf(',') > 0) {
        url = "pg" + defaultVersion.substring(0, defaultVersion.indexOf(',')) + ".html";
    } else {
        url = "pg" + defaultVersion + ".html";
    }
	 setTimeout(function () {
		$("#actIframe").attr("src", url);
	 },1);
    ios = defaultIOS.replace(/\_/g, ".").replace("v", "")
    ios = parseInt(ios.replace(/\.[\S]*$/, ""));
	
    setTimeout(function () {
        if (displaybox) {
            actIframe.contentWindow.document.getElementById("message").style.display = "block"
        }
    }, 500);
}
function methodTab(methodNames, defios) {
    defaultVersion = methodNames;
    defaultIOS = defios;
    methods = methodNames.split(",");
    var strHTMLS = "";
    for (var s = 0; s < methods.length; s++) {
        strHTMLS += '<li><a href="pg' + (methods[s]) + '.html" target="actIframe">' + methodName["a" + methods[s]] + "</a></li>";
    }
    $("#rightMethodList").html(strHTMLS);
    rightMethodHover();
    changeHtml();
}
function rightMethodHover(){
	pg.yy.rightMethod = $("#rightMethodList").find("a");
	pg.yy.rightMethod.eq(0).addClass("current");
	 pg.yy.rightMethod.click(function(){
		 pg.yy.rightMethod.removeClass("current");
		$(this).addClass("current");
	 });
}
function rightVersionHover(){
	pg.yy.rightType = $("#rightIOSList").find("a");
	pg.yy.rightType.eq(methodNum).addClass("current");
	pg.yy.rightType.click(function(){
		$("#rightIOSList").find("a").removeClass("current");
		$(this).addClass("current");
	 });
}
function setIframe(){
	var iframeHeight = document.documentElement.clientHeight-$("#yyRightNav").outerHeight()-$("#yyRightType").outerHeight()-$("#yyRightTab").outerHeight();
	var iframeWidth = document.documentElement.clientWidth-142;
	$("#yyRight").css({"width":iframeWidth});
	$("#yyRightIframe").css({"width":iframeWidth,"height":iframeHeight});
	actIframe.width = iframeWidth;
	actIframe.height = iframeHeight;
}
$(function(){
	actIframe = document.getElementById("actIframe");
	document.getElementById("myTypeSpan").innerHTML = myiPhoneType;
	document.getElementById("myVerSpan").innerHTML = myiPhoneVersion;
    makeDeviceList();
	pg.yy = {};
	changeType(defaultDevice);	
	pg.yy = {
		leftNav:$("#deviceList1").find("a")
	}
	pg.yy.leftNav.eq(defaultType).addClass("current");
	 pg.yy.leftNav.click(function(){
		 pg.yy.leftNav.removeClass("current");
		$(this).addClass("current");
	 });
	setIframe();
	$(window).resize(function(){
	  setIframe();
	}); 
})