﻿
var minFrameHeight = 900//850
var leftFrameOffset = 98
var rightFrameOffset = 203
var debugSideBars = false

var Games = { "NULL": 0, "MountAndBlade": 1, "Warband": 2, "Ogniem": 3, "Renfest":4 };

function isEmbeddedPageOpen() {
    var doc = getDoc()
    
    try {
        var mainFrameAddress = doc.getElementById('mainframe').contentWindow.location.href

        // if browser does not throw exception, throw manualy
        if (mainFrameAddress.indexOf(".php") != -1) {
            throw 'not local'
        }
        // iframe src is currently local
    }
    catch (err) {
        // iframe src is currently not local
        return true
    }
    return false
}

function getWrappedFrameBodyScrollHeight() {

    var doc = getDoc()
    var wrappedFrameBodyScrollHeight

    try {
        wrappedFrameBodyScrollHeight = Math.max(minFrameHeight,
			Math.min(doc.getElementById('mainframe').contentDocument.body.scrollHeight, doc.getElementById('mainframe').contentDocument.body.offsetHeight))
    }
    catch (err) {
        try {
            wrappedFrameBodyScrollHeight = Math.max(minFrameHeight,
			    Math.min(doc.getElementById('mainframe').contentWindow.document.body.scrollHeight, doc.getElementById('mainframe').contentWindow.document.body.offsetHeight))
        }
        catch (errr) {
            wrappedFrameBodyScrollHeight = minFrameHeight
        }
    }

    return wrappedFrameBodyScrollHeight
}

function setPositionsAndSizes() {

    var doc = getDoc()
    
    var logoFrameOffset = 0
    if (!(doc.getElementById('LogoFrameWrapper') && doc.getElementById('LogoFrameWrapper').style.display != 'none')) {
		logoFrameOffset -= 117
    }

    if (isEmbeddedPageOpen()) {
    
        doc.getElementById('mainframe').style.height = minFrameHeight + 'px'
        if (debugSideBars) {
            doc.getElementById('MainPageLeftSideBarID').style.height = '0px'
            doc.getElementById('MainPageRightSideBarID').style.height = '0px'
        } else {
            doc.getElementById('MainPageLeftSideBarID').style.height = (minFrameHeight + leftFrameOffset + logoFrameOffset) + 'px'
            doc.getElementById('MainPageRightSideBarID').style.height = (minFrameHeight + rightFrameOffset + logoFrameOffset) + 'px'
        }

        doc.getElementById('FooterLeftEmbossID').style.display = ''
        doc.getElementById('FooterRightEmbossID').style.display = ''

        return;
    }


    var wrappedFrameBodyScrollHeight = getWrappedFrameBodyScrollHeight()

    doc.getElementById('mainframe').style.height = wrappedFrameBodyScrollHeight + 'px'

    if (debugSideBars) {
        doc.getElementById('MainPageLeftSideBarID').style.height = '0px'
        doc.getElementById('MainPageRightSideBarID').style.height = '0px'
    } else {
        doc.getElementById('MainPageLeftSideBarID').style.height = (wrappedFrameBodyScrollHeight + leftFrameOffset + logoFrameOffset) + 'px'
        doc.getElementById('MainPageRightSideBarID').style.height = (wrappedFrameBodyScrollHeight + rightFrameOffset + logoFrameOffset) + 'px'
    }

    doc.getElementById('FooterLeftEmbossID').style.display = ''
    doc.getElementById('FooterRightEmbossID').style.display = ''

    leftMenuOpen()

}

function mainFrameOnLoad() {

    var heightOffset = 0

    var doc = getDoc()

    if (doc == undefined) {
        return
    }
    
    var logoFrameOffset = 0
    if (!(doc.getElementById('LogoFrameWrapper') && doc.getElementById('LogoFrameWrapper').style.display != 'none')) {
		logoFrameOffset -= 117
    }
    

    var wrappedFrameBodyScrollHeight = getWrappedFrameBodyScrollHeight()
    
    doc.getElementById('mainframe').style.height = wrappedFrameBodyScrollHeight + 'px'

    if (debugSideBars) {
        doc.getElementById('MainPageLeftSideBarID').style.height = '0px'
        doc.getElementById('MainPageRightSideBarID').style.height = '0px'
    } else {
        doc.getElementById('MainPageLeftSideBarID').style.height = (wrappedFrameBodyScrollHeight + leftFrameOffset + logoFrameOffset) + 'px'
        doc.getElementById('MainPageRightSideBarID').style.height = (wrappedFrameBodyScrollHeight + rightFrameOffset + logoFrameOffset) + 'px'
    }

    doc.getElementById('FooterLeftEmbossID').style.display = ''
    doc.getElementById('FooterRightEmbossID').style.display = ''

    leftMenuOpen()


    setTopBannerGameType(false)
    
    

}

function mainFrameRegisterOnLoad() {
    document.onload = function() {
        mainFrameOnLoad()
    }
}


var ssCount
var ssCountWarband
var ssCountMNB
var ssCountOgniem
var gameType


function isSSDefaultType() {
    return true;//TODO
    var control = getDoc().getElementById('ScreenshotPathID')
    return control.title != null && control.title != ""
}

function ssPath() {
    return getDoc().getElementById('ScreenshotPathID').href
}

function ssThumbPath() {
    return getDoc().getElementById('ScreenshotPathID').title
}

function ssThumbMouseOver() {
    document.getElementById('SSThumbLeftArrow').style.display = ''
    document.getElementById('SSThumbRightArrow').style.display = ''

    ssCheckLimits()
}

function ssThumbMouseOut() {
    document.getElementById('SSThumbLeftArrow').style.display = 'none'
    document.getElementById('SSThumbRightArrow').style.display = 'none'
}

function ssCheckLimits() {
    if (!ssCanIncrement())
        document.getElementById('SSThumbLeftArrow').style.display = 'none'
    else
        document.getElementById('SSThumbLeftArrow').style.display = ''
        
    if(!ssCanDecrement())
        document.getElementById('SSThumbRightArrow').style.display = 'none'
    else
        document.getElementById('SSThumbRightArrow').style.display = ''
}

function ssGetNextImageLink(increment) {
    var doc = getDoc()
    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(doc.getElementById('DisplayScreenshotID').href.match(re1)[0].match(re2)[0])

    if (increment) {
        if (ssCanIncrement2())
            ssID++
    }
    else {
        if (ssCanDecrement2())
            ssID--
    }

    doc.getElementById('DisplayScreenshotID').href = ssPath() + ssID + '.jpg'
}

function ssChangeThumb(increment) {

    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(document.getElementById('Image1').src.match(re1)[0].match(re2)[0])
    if (increment) {
        if (ssCanIncrement())
            ssID++
    }
    else {
        if (ssCanDecrement())
            ssID--
    }
    document.getElementById('Image1').src = ssThumbPath() + ssID + '.jpg'
    document.getElementById('Image1Href').href = ssPath() + ssID + '.jpg'

    ssCheckLimits()
}

function ssCheckSSGridViewPage() {
    alert(getFrame('mainframe').getFrame('wrappedframe').document.getElementById('GridViewScreenShots'))
    
}

function ssCanDecrement() {

    if (document.getElementById('Image1') == null) {
        return false
    }

    if (getDoc().getElementById('DisplaySingleImageHrefID').href.indexOf("images/troops/") != -1) {
        return false
    }

    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(document.getElementById('Image1').src.match(re1)[0].match(re2)[0])
    return ssID > 1
}

function ssCanIncrement() {

    if (document.getElementById('Image1') == null) {
        return false
    }

    if (getDoc().getElementById('DisplaySingleImageHrefID').href.indexOf("images/troops/") != -1) {
        return false
    }
    
    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(document.getElementById('Image1').src.match(re1)[0].match(re2)[0])
    
    return ssID < ssCount
}

function ssCanDecrement2() {
    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(getDoc().getElementById('DisplayScreenshotID').href.match(re1)[0].match(re2)[0])
    return ssID > 1
}

function ssCanIncrement2() {
    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(getDoc().getElementById('DisplayScreenshotID').href.match(re1)[0].match(re2)[0])
    return ssID < parseInt(getDoc().getElementById('ScreenshotPathID').innerHTML)
}

function ssThumbLeft() {
    ssChangeThumb(true)
    blockSS = true
}

function ssThumbRight() {
    ssChangeThumb(false)
    blockSS = true
}

function openPopup(url) {
    window.open(url, "popup_id", "scrollbars,resizable,width=400,height=300");
    return false;
}

// opens video from inner frame
function showVideo(url) {

    // change url params
    var swfmovieparam = window.parent.parent.document.getElementById('swfobjectid')
    swfmovieparam.setAttribute('movie', 'fPlayerIn.swf?v=' + url)

    var swfembed = window.parent.parent.document.getElementById('swfembedid')
    swfembed.setAttribute('src', 'fPlayerIn.swf?v=' + url)

    // then simulate href click
    var target = window.parent.parent.document.getElementById('videohref')
    if (document.dispatchEvent) { // W3C
        var oEvent = document.createEvent("MouseEvents");
        oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
        target.dispatchEvent(oEvent);
    }
    else if (document.fireEvent) { // IE
        target.fireEvent("onclick");
    }
}

function ssSetDefaultType() {
    return;//TODO
    var path = getDoc().getElementById('ScreenshotPathID')
    path.href = "images/ss"
    path.title = "images/sthumb"
    path.href = ssPath()
    path.title = ssThumbPath()
}

function clearSingleImage() {
    getDoc().getElementById('DisplaySingleImageHrefID').href = ""
}

function showSingleImage(url) {

    var doc = getDoc()

    var target = doc.getElementById('DisplaySingleImageHrefID')
    target.href = "App_Themes/Theme1/images/" + url

    // simulate href click
    if (document.dispatchEvent) { // W3C
        var oEvent = document.createEvent("MouseEvents");
        oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
        target.dispatchEvent(oEvent);
    }
    else if (document.fireEvent) { // IE
        target.fireEvent("onclick");
    }
}

function showScreenShot(ssNo) {

    var doc = getDoc()

    // change main ss thumb
    doc.getElementById('Image1Href').href = "images/ss/" + ssNo + ".jpg"
    doc.getElementById('Image1').src = "images/ssthumb/" + ssNo + ".jpg"

    var path = doc.getElementById('ScreenshotPathID')
    path.href = "images/ss/" // image path
    path.title = "images/ssthumb/" // thumb path, set null
    path.innerHTML = ssCountWarband //"17" // sscount
    
    ssCount = ssCountWarband

    var target = doc.getElementById('DisplayScreenshotID')
    target.href = "images/ss/" + ssNo + ".jpg"

    // simulate href click
    if (document.dispatchEvent) { // W3C
        var oEvent = document.createEvent("MouseEvents");
        oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
        target.dispatchEvent(oEvent);
    }
    else if (document.fireEvent) { // IE
        target.fireEvent("onclick");
    }
}

function showScreenShotOgniem(ssNo) {

    var doc = getDoc()

    // change main ss thumb
    doc.getElementById('Image1Href').href = "images/ss_ogniem/" + ssNo + ".jpg"
    doc.getElementById('Image1').src = "images/ssthumb_ogniem/" + ssNo + ".jpg"

    var path = doc.getElementById('ScreenshotPathID')
    path.href = "images/ss_ogniem/" // image path
    path.title = "images/ssthumb_ogniem/" // thumb path, set null
    path.innerHTML = ssCountOgniem //"17" // sscount
    
    ssCount = ssCountOgniem

    var target = doc.getElementById('DisplayScreenshotID')
    target.href = "images/ss_ogniem/" + ssNo + ".jpg"
    

    // simulate href click
    if (document.dispatchEvent) { // W3C
        var oEvent = document.createEvent("MouseEvents");
        oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
        target.dispatchEvent(oEvent);
    }
    else if (document.fireEvent) { // IE
        target.fireEvent("onclick");
    }
}

function showScreenShotMNB(ssNo) {

    var doc = getDoc()

    // change main ss thumb
    doc.getElementById('Image1Href').href = "images/ss_mnb/" + ssNo + ".jpg"
    doc.getElementById('Image1').src = "images/ssthumb_mnb/" + ssNo + ".jpg"

    var path = doc.getElementById('ScreenshotPathID')
    path.href = "images/ss_mnb/" // image path
    path.title = "images/ssthumb_mnb/" // thumb path, set null
    path.innerHTML = ssCountMNB //"33" // sscount
    
    ssCount = ssCountMNB

    var target = doc.getElementById('DisplayScreenshotID')
    target.href = "images/ss_mnb/" + ssNo + ".jpg"


    // simulate href click
    if (document.dispatchEvent) { // W3C
        var oEvent = document.createEvent("MouseEvents");
        oEvent.initMouseEvent("click", true, true, window, 1, 1, 1, 1, 1, false, false, false, false, 0, target);
        target.dispatchEvent(oEvent);
    }
    else if (document.fireEvent) { // IE
        target.fireEvent("onclick");
    }
}


function adjustMainPageState() {
    
    var doc = getDoc()
    var url = getPageNameWithoutAnyParameters(document.URL)
    var state

    if (
		url == "renfest.aspx" ||
		url == "renfestvideos.aspx" ||
		url == "renfestfaq.aspx" ||
		url == "renfestdownload.aspx" ||
		url == "renfestbuy.aspx"
        ) {
        state = "reduced"
        setGameThemeToRenfest2()
    }
    else if (
		url == "login.aspx" ||
		url == "logo.aspx" ||
		url == "buy.aspx" ||
		url == "download.aspx" ||
		url == "features.aspx" ||
		url == "weapons.aspx" ||
		url == "factions.aspx" ||
		url == "multiplayer.aspx"
		) {
        state = "preserve"
    }
    else {
        state = "default"
        if (parent.gameType == Games.Renfest){
			parent.gameType = Games.Warband
        }
		setGameTheme(false)
    }


    if (state == "default") {
        doc.getElementById('loginframe').style.display = ''
        doc.getElementById('OtherGamesRight').style.display = ''
        doc.getElementById('HiringPanel').style.display = ''
        doc.getElementById('LeftChainPanel').style.display = ''
        doc.getElementById('RightChainPanel').style.display = ''
        doc.getElementById('LogoFrameWrapper').style.display = ''
        doc.getElementById('HighlightRightBar').style.display = ''
    }
    else if (state == "reduced") {
        doc.getElementById('loginframe').style.display = 'none'
        doc.getElementById('OtherGamesRight').style.display = 'none'
        doc.getElementById('HiringPanel').style.display = 'none'
        doc.getElementById('LeftChainPanel').style.display = 'none'
        doc.getElementById('RightChainPanel').style.display = 'none'
        doc.getElementById('LogoFrameWrapper').style.display = 'none'
        doc.getElementById('HighlightRightBar').style.display = 'none'
    }

}


function checkIfIsInFrame(redirPagename) {
    
    var isInFrame = window.parent.parent.document.getElementById('Image1Href') != null || window.parent.document.getElementById('Image1Href') != null

    if (!isInFrame) {

        if (!redirPagename) {
            window.location = 'http://www.taleworlds.com/main.aspx'
        }
        else {
            var strs = window.location.href.split('/')
            var pagename = strs[strs.length - 1]
            window.location = 'http://www.taleworlds.com/main.aspx?dir=' + pagename
        }

    }
    else {
        adjustMainPageState()
    }

}

function adjustSerial(textbox) {

    var text = textbox.value
    
    text = text.toUpperCase()

    var indexes = new Array(4, 9, 14)//, 19, 24, 29, 34)
    for (var i in indexes) {
        var index = indexes[i]

        while (text.substr(index - 4, 4).indexOf('-') != -1) {
            text = text.substr(0, index - 4) + text.substr(index - 4, 4).replace(/-/, '') + text.substr(index)
        }
        
        if (text.length > index && text.charAt(index) != '-') {
            if (text.charAt(index) == ' ' || text.charAt(index) == '_') {
                text = text.substr(0, index) + '-' + text.substr(index + 1)
            }
            else {
                text = text.substr(0, index) + '-' + text.substr(index)
            }
        }
    }
    
    textbox.value = text.substr(0, Math.min(text.length, 19))

}

function resizeAvatar(img) {
    if (img.height > img.width) {
        if (img.height > 80) {
            img.width *= 80 / img.height
            img.height = 80
        }
    } else {
        if (img.width > 80) {
            img.height *= 80 / img.width
            img.width = 80
        }
    }
}

function logoPageOnLoad() {
    // wait till it loads
    if (!getFrame('logoframe').window.document.getElementById('innerHighlightedNewsID')) {
        setTimeout("logoPageOnLoad()", 500)
    } else {
        logoPageOnLoad2()
    }
}

function logoPageOnLoad2() {
    
    if (getFrame('logoframe').window.document.getElementById('innerHighlightedNewsID').offsetHeight <=
        getFrame('logoframe').window.document.getElementById('outerHighlightedNewsID').offsetHeight) {
        getFrame('logoframe').window.document.getElementById('PanelHighlightedNewsMore').style.display = 'none'

        // vertical align the highlighted news
        getFrame('logoframe').window.document.getElementById('innerHighlightedNewsID').style.display = 'table-cell'
        getFrame('logoframe').window.document.getElementById('innerHighlightedNewsID').style.height = '80px'
        getFrame('logoframe').window.document.getElementById('innerHighlightedNewsID').style.verticalAlign = 'middle'
    }
    else {
        getFrame('logoframe').window.document.getElementById('PanelHighlightedNewsMore').style.display = ''
    }
}

function changeBackGroundImages(leftStyle, rightStyle, killerLeftStyle, killerRightStyle, control, topControl, ident) {

    if (!document.getElementById('MainPageLeftSideID')) {
        return;
    }

    document.getElementById('MainPageLeftSideID').className = leftStyle
    document.getElementById('MainPageRightSideID').className = rightStyle

    document.getElementById('KillerKnightLeftID').className = killerLeftStyle
    //document.getElementById('KillerKnightRightID').className = killerRightStyle

    document.getElementById('KillerKnightLeft2ID').className = killerLeftStyle + '2'
    document.getElementById('KillerKnightRight2ID').className = killerRightStyle + '2'
    
}

function loginFrameOnLoad() {
    // getFrame("loginframe").window.document.getElementById('LoginPageBodyID').className = document.getElementById('MainPageRightSideID').className
}

function expandArchievedNews(news) {
    if (news.style.height == '') {
        news.style.height = '100%'
    } else {
        news.style.height = ''
    }
    mainFrameOnLoad()
}

function getFrame(frameName){
    if (window.frames[frameName]) {
        return window.frames[frameName]
    } else {
        return document.getElementById(frameName).contentWindow
    }
}

function removeFontOptionFromAdmintoolsEditor() {
    var select = document.getElementById('Editor1_ctl01_ctl22_select')
    if (select != null) {
        select.style.display = 'none'
    }
}

function hideDagger() {
    getDoc().getElementById('LeftMenuDagger').style.backgroundPosition = '-100px -100px'
}

function setLeftMenuDaggerPosition(control) {

    setLeftMenuDaggerPosition2(control)
    mainFrameOnInit()
}

// without mainFrameOnInit
function setLeftMenuDaggerPosition2(control) {

    if (control) {
        
        if (control.offsetTop == 0) {
            // if has ie bug
            getDoc().getElementById('LeftMenuDagger').style.backgroundPosition = '29px ' + (jqueryOffsetTop(control) - 435) + 'px'
        } else {
            getDoc().getElementById('LeftMenuDagger').style.backgroundPosition = '29px ' + (control.parentNode.offsetTop - 142) + 'px'
        }

        
    } else {
        hideDagger()
    }
    
}

// fetches asd.aspx from http://www.hebele.com/dubaa/asd.aspx?p=1
function getPageNameWithoutAnyParameters(url) {
    var arr = url.split('/')
    return arr[arr.length - 1].split('?')[0]
}

function leftMenuOpen() {

    setGameTheme(false, true)
    
    var className = 'LeftMenuLinkStyle'
    
    var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)")
    var allElements = getDoc().getElementsByTagName("*")
    var results = []

    var element
    var framePage
    for (var i = 0; (element = allElements[i]) != null; i++) {
        var elementClass = element.className
        if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
            results.push(element)
    }

    if (results.length) {
        framePage = getPageNameWithoutAnyParameters(getDoc().getElementById('mainframe').contentWindow.document.URL)
        
        
        // tabbed pages
        if (framePage == 'multiplayer.aspx' || framePage == 'weapons.aspx' || framePage == 'factions.aspx')
        {
			framePage = 'features.aspx'
        }
        
        for (var i in results) {
            if (getPageNameWithoutAnyParameters(results[i].href) == framePage) {

                if (results[i].parentNode.parentNode.style.display != 'none') {
                    setLeftMenuDaggerPosition2(results[i])
                    break
                }
            }
        }
    }
}

function embedderOnLoad(redirPage) {
    window.location = redirPage
}

function mainFrameOnInit() {

    var doc = getDoc()

    doc.getElementById('FooterLeftEmbossID').style.display = 'none'
    doc.getElementById('FooterRightEmbossID').style.display = 'none'

    var wrappedFrameBodyScrollHeight = minFrameHeight
    
    var logoFrameOffset = 0
    if (!(doc.getElementById('LogoFrameWrapper') && doc.getElementById('LogoFrameWrapper').style.display != 'none')) {
		logoFrameOffset -= 117
    }

    doc.getElementById('mainframe').style.height = wrappedFrameBodyScrollHeight + 'px'

    if (debugSideBars) {
        doc.getElementById('MainPageLeftSideBarID').style.height = '0px'
        doc.getElementById('MainPageRightSideBarID').style.height = '0px'
    } else {
        doc.getElementById('MainPageLeftSideBarID').style.height = (wrappedFrameBodyScrollHeight + leftFrameOffset + logoFrameOffset) + 'px'
        doc.getElementById('MainPageRightSideBarID').style.height = (wrappedFrameBodyScrollHeight + rightFrameOffset + logoFrameOffset) + 'px'
    }
}

function closeProfilePages() {
    var doc = getDoc()

    if (isEmbeddedPageOpen() || doc.getElementById('mainframe').contentWindow.location.href.indexOf("mygames.aspx") != -1) {
        doc.getElementById('mainframe').contentWindow.location.href = "news.aspx"
    }
}

function getDoc() {
    var doc, par
    if (document.getElementById('mainframe')) {
        doc = document
        par = parent
    } else if (parent.document.getElementById('mainframe')) {
        doc = parent.document
        par = parent.parent
    }
    return doc
}

function isOnMainPage() {
    if (document.getElementById('mainframe')) {
        return true
    } else {
        return false
    }
}

function selectLeftMenuGame(section, otherGameDiv, daggerControl, leftStyle, rightStyle, killerLeftStyle, killerRightStyle, closeOtherGames) {
    var doc = getDoc()

    doc.getElementById('LeftMenuOtherGameWarband').style.display = ''
    doc.getElementById('LeftMenuOtherGameMNB').style.display = ''
    doc.getElementById('LeftMenuOtherGameOgniem').style.display = ''
    doc.getElementById(otherGameDiv).style.display = 'none'
    
    doc.getElementById('LeftMenuSectionWarband').style.display = 'none'
    doc.getElementById('LeftMenuSectionMNB').style.display = 'none'
    doc.getElementById('LeftMenuSectionOgniem').style.display = 'none'
    doc.getElementById('LeftMenuSectionRenfest').style.display = 'none'
    doc.getElementById(section).style.display = ''

    if (!isOnMainPage()) {
        return;
    }

    if (closeOtherGames) {
        // instant close
        // doc.getElementById('LeftMenuOtherGames').style.display = 'none'

        // smooth close
        $("#LeftMenuOtherGamesHeadID").parent().children('div.menu_body').slideUp("slow")
    }



    // it causes quick appear disappears, so remove it
    // setLeftMenuDaggerPosition(doc.getElementById(daggerControl))

    
    changeBackGroundImages(leftStyle, rightStyle, killerLeftStyle, killerRightStyle)
}

function leftDaggerSelectNews() {
    var doc = getDoc()

    if (doc.getElementById('LeftMenuSectionWarband').style.display != 'none') {
        setLeftMenuDaggerPosition(doc.getElementById('LeftMenuNewsWarbandID'))
    } else if (doc.getElementById('LeftMenuSectionMNB').style.display != 'none') {
        setLeftMenuDaggerPosition(doc.getElementById('LeftMenuNewsMNBID'))
    } else if (doc.getElementById('LeftMenuSectionOgniem').style.display != 'none') {
        setLeftMenuDaggerPosition(doc.getElementById('LeftMenuNewsOgniemID'))
    }
}

function setTopBannerGameType(force) {
	if(navigator.userAgent.indexOf('Opera') != -1)
		// delay func to prevent opera bug occuring
		setTimeout("setTopBannerGameType2("+force+")", 300)
	else
		setTopBannerGameType2(force)
}

function setTopBannerGameType2(force) {

    if (!isOnMainPage()) {
        return;
    }

    var doc = getDoc()

    if (force ||
        (doc.getElementById('TopBannerFlashWrapperIDMNB').style.display == 'none' &&
        doc.getElementById('TopBannerFlashWrapperIDWarband').style.display == 'none' &&
        doc.getElementById('TopBannerFlashWrapperIDOgniem').style.display == 'none' &&
        doc.getElementById('TopBannerFlashWrapperIDRenfest').style.display == 'none'
        )) {

        if (force) {
            doc.getElementById('TopBannerFlashWrapperIDOgniem').style.display = 'none'
            doc.getElementById('TopBannerFlashWrapperIDWarband').style.display = 'none'
            doc.getElementById('TopBannerFlashWrapperIDMNB').style.display = 'none'
            doc.getElementById('TopBannerFlashWrapperIDRenfest').style.display = 'none'
        }

        switch (gameType) {
            case Games.Ogniem:
                doc.getElementById('TopBannerFlashWrapperIDOgniem').style.display = ''
                break
            case Games.MountAndBlade:
                doc.getElementById('TopBannerFlashWrapperIDMNB').style.display = ''
                break
            case Games.Renfest:
				doc.getElementById('TopBannerFlashWrapperIDRenfest').style.display = ''
				break
            case Games.Warband:
            default:
                doc.getElementById('TopBannerFlashWrapperIDWarband').style.display = ''
                break
            
        }

    }
}

function setGameTheme(closeOtherGames, disableTop) {

    if (gameType == undefined) {
        return
    }

    var doc = getDoc()
    switch (gameType) {
        case Games.Ogniem:
            selectLeftMenuGame('LeftMenuSectionOgniem', 'LeftMenuOtherGameOgniem', 'LeftMenuFeaturesOgniem', 'MainPageLeftSideStyleOgniem', 'MainPageRightSideStyleOgniem', 'KillerKnightLeftStyleOgniem', 'KillerKnightRightStyleOgniem', closeOtherGames)


            if (doc.getElementById('Image1').src.indexOf("images/ssthumb_ogniem/") == -1) {

                var lastSSNo = ssCountOgniem
                doc.getElementById('Image1Href').href = 'images/ss_ogniem/' + lastSSNo + '.jpg'
                doc.getElementById('Image1').src = 'images/ssthumb_ogniem/' + lastSSNo + '.jpg'
                doc.getElementById('DisplayScreenshotID').href = 'images/ss_ogniem/' + lastSSNo + '.jpg'
            }

            var path = doc.getElementById('ScreenshotPathID')
            path.href = "images/ss_ogniem/" // image path
            path.title = "images/ssthumb_ogniem/" // thumb path, set null
            path.innerHTML = ssCountWarband //"33" // sscount

            ssCount = ssCountOgniem




            break

        case Games.MountAndBlade:
            selectLeftMenuGame('LeftMenuSectionMNB', 'LeftMenuOtherGameMNB', 'LeftMenuFeaturesMNB', 'MainPageLeftSideStyleMNB', 'MainPageRightSideStyleMNB', 'KillerKnightLeftStyleMNB', 'KillerKnightRightStyleMNB', closeOtherGames)

            if (doc.getElementById('Image1').src.indexOf("images/ssthumb_mnb/") == -1) {

                var lastSSNo = ssCountMNB
                doc.getElementById('Image1Href').href = 'images/ss_mnb/' + lastSSNo + '.jpg'
                doc.getElementById('Image1').src = 'images/ssthumb_mnb/' + lastSSNo + '.jpg'
                doc.getElementById('DisplayScreenshotID').href = 'images/ss/' + lastSSNo + '.jpg'
            }

            var path = doc.getElementById('ScreenshotPathID')
            path.href = "images/ss_mnb/" // image path
            path.title = "images/ssthumb_mnb/" // thumb path, set null
            path.innerHTML = ssCountMNB //"33" // sscount

            ssCount = ssCountMNB

            break
            
        case Games.Renfest:
        
            selectLeftMenuGame('LeftMenuSectionRenfest', 'LeftMenuOtherGameWarband', 'LeftMenuFeaturesWarband', 'MainPageLeftSideStyleWarband', 'MainPageRightSideStyleWarband', 'KillerKnightLeftStyleWarband', 'KillerKnightRightStyleWarband', closeOtherGames)

            if (doc.getElementById('Image1').src.indexOf("images/ssthumb/") == -1) {
            
                var lastSSNo = ssCountWarband
                doc.getElementById('Image1Href').href = 'images/ss/' + lastSSNo + '.jpg'
                doc.getElementById('Image1').src = 'images/ssthumb/' + lastSSNo + '.jpg'
                doc.getElementById('DisplayScreenshotID').href = 'images/ss/' + lastSSNo + '.jpg'
            }

            var path = doc.getElementById('ScreenshotPathID')
            path.href = "images/ss/" // image path
            path.title = "images/ssthumb/" // thumb path, set null
            path.innerHTML = ssCountWarband //"33" // sscount

            ssCount = ssCountWarband

            break
            
        case Games.Warband:
        default:
            selectLeftMenuGame('LeftMenuSectionWarband', 'LeftMenuOtherGameWarband', 'LeftMenuFeaturesWarband', 'MainPageLeftSideStyleWarband', 'MainPageRightSideStyleWarband', 'KillerKnightLeftStyleWarband', 'KillerKnightRightStyleWarband', closeOtherGames)

            if (doc.getElementById('Image1').src.indexOf("images/ssthumb/") == -1) {
            
                var lastSSNo = ssCountWarband
                doc.getElementById('Image1Href').href = 'images/ss/' + lastSSNo + '.jpg'
                doc.getElementById('Image1').src = 'images/ssthumb/' + lastSSNo + '.jpg'
                doc.getElementById('DisplayScreenshotID').href = 'images/ss/' + lastSSNo + '.jpg'
            }

            var path = doc.getElementById('ScreenshotPathID')
            path.href = "images/ss/" // image path
            path.title = "images/ssthumb/" // thumb path, set null
            path.innerHTML = ssCountWarband //"33" // sscount

            ssCount = ssCountWarband

            break
        
    }

    //if (!disableTop) {
        setTopBannerGameType(true)
    //}
}

function closeLeftMenuOtherGames() {
    // instant close
    // doc.getElementById('LeftMenuOtherGames').style.display = 'none'

    // smooth close
    $("#LeftMenuOtherGamesHeadID").parent().children('div.menu_body').slideUp("slow");
    $("#LeftMenuOtherGamesHeadID").contents('div.menu_head2').css({ backgroundImage: "url(App_Themes/Theme1/images/madde_imi_expand.png)" });
}

function setGameThemeToWarband() {
    if (!document.getElementById('LeftMenuSectionWarband')) return;
    closeLeftMenuOtherGames()
    gameType = Games.Warband
    setGameTheme(true)
}

function setGameThemeToMNB() {
    if (!document.getElementById('LeftMenuSectionWarband')) return;
    closeLeftMenuOtherGames()
    gameType = Games.MountAndBlade
    setGameTheme(true)
}

function setGameThemeToOgniem() {
    if (!document.getElementById('LeftMenuSectionWarband')) return;
    closeLeftMenuOtherGames()
    gameType = Games.Ogniem
    setGameTheme(true)
}

function setGameThemeToRenfest() {
    if (!document.getElementById('LeftMenuSectionWarband')) return;
    closeLeftMenuOtherGames()
    gameType = Games.Renfest
    setGameTheme(true)
}

function setGameThemeToWarband2() {
    //closeLeftMenuOtherGames()
    parent.gameType = Games.Warband
    setGameTheme(false)
}

function setGameThemeToMNB2() {
    //closeLeftMenuOtherGames()
    parent.gameType = Games.MountAndBlade
    setGameTheme(false)
}

function setGameThemeToOgniem2() {
    //closeLeftMenuOtherGames()
    parent.gameType = Games.Ogniem
    setGameTheme(false)
}

function setGameThemeToRenfest2() {
    //closeLeftMenuOtherGames()
    parent.gameType = Games.Renfest
    setGameTheme(false)
}

function closeFancyBoxAndSetGameThemeToWarband() {
    $("#fancy_close").trigger("click");
    setGameThemeToWarband()
}

function showSerial(no) {
    document.getElementById('ClickToViewSerialID' + no).style.display = 'none'
    document.getElementById('ClickToViewSerialID2' + no).style.display = ''
}

function foo() {
    //alert('FLASSH')
    getDoc().getElementById('mainframe').src = 'features.aspx?type=2'
    setGameThemeToWarband()
}

function foo2() {
    //alert('FLASSH')
    getDoc().getElementById('mainframe').src = 'features.aspx?type=3'
    setGameThemeToOgniem()
}

function jqueryOffsetTop(elem) {

    var box = elem.getBoundingClientRect(), doc = elem.ownerDocument, body = doc.body, docElem = doc.documentElement,
			clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
			top = box.top + (self.pageYOffset || true /*|| jQuery.support.boxModel*/ && docElem.scrollTop || body.scrollTop) - clientTop,
			left = box.left + (self.pageXOffset || true /*|| jQuery.support.boxModel*/ && docElem.scrollLeft || body.scrollLeft) - clientLeft;

    return top

}

function checkScreenShotText() {

    if (gameType != Games.Warband) {
        return false
    }

    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(document.getElementById('Image1').src.match(re1)[0].match(re2)[0])

    var list = getDoc().getElementById('ScreenShotTextsID').innerHTML.split(";")

    for (var i = 0; i < list.length; i += 2) {
        try {
            var currentSSID = parseInt(list[i])
            if (ssID == currentSSID) {
                return true
            }
        } catch (ex) {
        }
    }
    
    return false
}

function getScreenShotText() {

    if (gameType != Games.Warband) {
        return ""
    }

    var re1 = /[\d]+.jpg/g
    var re2 = /[\d]+/g
    var ssID = parseInt(document.getElementById('Image1').src.match(re1)[0].match(re2)[0])

    var list = getDoc().getElementById('ScreenShotTextsID').innerHTML.split(";")

    for (var i = 0; i < list.length; i += 2) {
        try {
            var currentSSID = parseInt(list[i])
            if (ssID == currentSSID) {
                return list[i + 1]
            }
        } catch (ex) {
        }
    }

    return ""
}
