$(document).ready(function () {
    $(".tab_content").hide();
    $("ul.tabs li:first").addClass("active").show();
    $(".tab_content:first").show();
    $("ul.tabs li").mouseover(function () {
        $("ul.tabs li").removeClass("active");
        $(this).addClass("active");
        $(".tab_content").hide();
        $(".tab_content").stop(true, true);
        var activeTab = $(this).find("a").attr("href");
        $(activeTab).fadeIn('slow');
        return false;
    });
    imageTabDefault('1');
});

function imageTabDefault(id) {
    for (i = 1; i <= 5; i++) {
        $('#tbDefault' + i).removeClass('selected');
    }
    $('#tbDefault' + id).addClass('selected');
}
$(document).ready(function () {
    $('#tabMenu > li').click(function () {
        $('#tabMenu > li').removeClass('selected');
        $(this).addClass('selected');
        $('.boxBody div').slideUp('1500');
        $('.boxBody div:eq(' + $('#tabMenu > li').index(this) + ')').slideDown('1500');
    }).mouseover(function () {
        $(this).addClass('mouseover');
        $(this).removeClass('mouseout');
    }).mouseout(function () {
        $(this).addClass('mouseout');
        $(this).removeClass('mouseover');
    });
});
$(document).ready(function () {
    $("div.control_button").click(function () {
        $("div#control").animate({
            width: "255px"
        }).animate({
            width: "215px"
        }, "fast");
    });
    $("div#hide_buttonstudy").click(function () {
        if (document.getElementById("control").style.width == "215px") {
            $("div#control").animate({
                width: "0px"
            }, "fast");
        }
    });
    $("div.control_button1").mouseover(function (event) {
        if (document.getElementById("control1").style.width != "215px") {
            $("div#control1").animate({
                width: "255px"
            }).animate({
                width: "215px"
            }, "fast");
            event.cancelBubble = true;
        }
    });
    $("div#homegallery1").mouseover(function (event) {
       /* if (document.getElementById("control1").style.width == "215px") {
            $("div#control1").animate({
                width: "0px"
            }, "fast");
        }*/
        event.cancelBubble = true;
    });
});
(function ($) {
    $.extend($.fx.step, {
        backgroundPosition: function (fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem, 'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0], start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0], end[2]];
                fx.unit = [end[1], end[3]];
            }
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0] + ' ' + nowPosX[1];

            function toArray(strg) {
                strg = strg.replace(/left|top/g, '0px');
                strg = strg.replace(/right|bottom/g, '100%');
                strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g, "$1px$2");
                var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
                return [parseFloat(res[1], 10), res[2], parseFloat(res[3], 10), res[4]];
            }
        }
    });
})(jQuery);
$(function () {
    $('.banner1 a').css({
        backgroundPosition: "0 100px"
    }).mouseover(function () {
        $(this).addClass("height", 2000);
        document.getElementById("new" + $(this).attr('id')).style.display = 'none';
        $(this).animate({
            backgroundPosition: "(0 200px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(0 300px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(0 400px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(0 503px)"
        }, {
            duration: 2000
        })
    }).mouseout(function () {
        $(this).removeClass("height", 2000);
        document.getElementById("new" + $(this).attr('id')).style.display = 'block';
        $(this).stop(true, true).animate({
            backgroundPosition: "(0 100px)"
        }, {
            duration: 2000
        })
    })
});
(jQuery);
$(function () {
    $('.banner2 a').css({
        backgroundPosition: "-203px 100px"
    }).mouseover(function () {
        $(this).addClass("height", 2000);
        document.getElementById("new" + $(this).attr('id')).style.display = 'none';
        $(this).animate({
            backgroundPosition: "(-203px 200px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(-203px 300px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(-203px 400px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(-203px 503px)"
        }, {
            duration: 2000
        })
    }).mouseout(function () {
        $(this).removeClass("height", 2000);
        document.getElementById("new" + $(this).attr('id')).style.display = 'block';
        $(this).stop(true, true).animate({
            backgroundPosition: "(-203px 100px)"
        }, {
            duration: 2000
        })
    })
});
(jQuery);
$(function () {
    $('.banner3 a').css({
        backgroundPosition: "-405px 98px"
    }).mouseover(function () {
        $(this).addClass("height", 2000);
        document.getElementById("new" + $(this).attr('id')).style.display = 'none';
        $(this).animate({
            backgroundPosition: "(-405px 200px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(-405px 300px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(-405px 400px)"
        }, {
            duration: 2000
        })
        $(this).animate({
            backgroundPosition: "(-405px 503px)"
        }, {
            duration: 2000
        })
    }).mouseout(function () {
        $(this).removeClass("height", 2000);
        document.getElementById("new" + $(this).attr('id')).style.display = 'block';
        $(this).stop(true, true).animate({
            backgroundPosition: "(-405px 98px)"
        }, {
            duration: 2000
        })
    })
});
var simpleGallery_navpanel = {
    panel: {
        height: '45px',
        opacity: 0.5,
        paddingTop: '5px',
        fontStyle: 'bold 11px Verdana'
    },
    images: ['btnleft', 'btnplay', 'btnright', 'btnpause'],
    imageSpacing: {
        offsetTop: [0, 0, 0],
        spacing: 10
    },
    slideduration: 500
}

function simpleGallery(settingarg) {
    this.setting = settingarg
    settingarg = null
    var setting = this.setting
    setting.panelheight = (parseInt(setting.navpanelheight) > 5) ? parseInt(setting.navpanelheight) : parseInt(simpleGallery_navpanel.panel.height)
    setting.fadeduration = parseInt(setting.fadeduration)
    setting.curimage = (setting.persist) ? simpleGallery.routines.getCookie("gallery-" + setting.wrapperid) : 0
    setting.curimage = setting.curimage || 0
    setting.ispaused = !setting.autoplay[0]
    setting.currentstep = 0
    setting.totalsteps = setting.imagearray.length * setting.autoplay[2]
    setting.fglayer = 0,
        setting.bglayer = 1
        setting.oninit = setting.oninit ||
    function () {}
    setting.onslide = setting.onslide ||
    function () {}
    var preloadimages = [],
        longestdesc = null
        setting.longestdesc = ""
		
    for (var i = 0; i < setting.imagearray.length; i++) {
        preloadimages[i] = new Image()
	//	alert(i);
      //  if (setting.imagearray[i][3].length && setting.imagearray[i][3] > setting.longestdesc.length) setting.longestdesc = setting.imagearray[i][3]
    }
    var slideshow = this
    jQuery(document).ready(function ($) {
        var setting = slideshow.setting
        setting.$wrapperdiv = $('#' + setting.wrapperid).css({
            position: 'relative',
            visibility: 'visible',
            background: '#fff',
            overflow: 'hidden',
            width: setting.dimensions[0],
            height: setting.dimensions[1]
        }).empty()
        if (setting.$wrapperdiv.length == 0) {
            alert("Error: DIV with ID \"" + setting.wrapperid + "\" not found on page.")
            return
        }
        setting.$gallerylayers = $('<div class="gallerylayer"></div><div class="gallerylayer"></div>').css({
            position: 'absolute',
            left: 0,
            top: 0
        }).appendTo(setting.$wrapperdiv)
        setting.gallerylayers = setting.$gallerylayers.get()
        setting.navbuttons = simpleGallery.routines.addnavpanel(setting)
        if (setting.longestdesc != "") setting.descdiv = simpleGallery.routines.adddescpanel(setting)
        $(setting.navbuttons).filter('img.navimages').css({
            opacity: 0.8
        }).bind('mouseover mouseout', function (e) {
            $(this).css({
                opacity: (e.type == "mouseover") ? 1 : 0.8
            })
        }).bind('click', function (e) {
            var keyword = e.target.title.toLowerCase()
            slideshow.navigate(keyword)
        })
        setting.$wrapperdiv.bind('mouseenter', function () {
            slideshow.showhidenavpanel('show')
        })
        setting.$wrapperdiv.bind('mouseleave', function () {
            slideshow.showhidenavpanel('hide')
        })
        slideshow.showslide(setting.curimage)
        setting.oninit.call(slideshow)
        $(window).bind('unload', function () {
            $(slideshow.setting.navbuttons).unbind()
            if (slideshow.setting.persist) simpleGallery.routines.setCookie("gallery-" + setting.wrapperid, setting.curimage)
            jQuery.each(slideshow.setting, function (k) {
                if (slideshow.setting[k] instanceof Array) {
                    for (var i = 0; i < slideshow.setting[k].length; i++) {
                        if (slideshow.setting[k][i].tagName == "DIV") slideshow.setting[k][i].innerHTML = null
                        slideshow.setting[k][i] = null
                    }
                }
                if (slideshow.setting[k].innerHTML) slideshow.setting[k].innerHTML = null
                slideshow.setting[k] = null
            })
            slideshow = slideshow.setting = null
        })
    })
}
simpleGallery.prototype = {
    navigate: function (keyword) {
		
        clearTimeout(this.setting.playtimer)
        this.setting.totalsteps = 100000
        if (!isNaN(parseInt(keyword))) {
            this.showslide(parseInt(keyword))
        } else if (/(prev)|(next)/i.test(keyword)) {
            this.showslide(keyword.toLowerCase())
        } else {
            var slideshow = this
            var $playbutton = $(this.setting.navbuttons).eq(1)
            if (!this.setting.ispaused) {
                this.setting.autoplay[0] = false
                $playbutton.attr({
                    title: 'Play'
                })
                $playbutton.removeClass('navimages btnpause').addClass('navimages btnplay');
            } else if (this.setting.ispaused) {
                this.setting.autoplay[0] = true
                this.setting.playtimer = setTimeout(function () {
                    slideshow.showslide('next')
                }, this.setting.autoplay[1])
                $playbutton.attr({
                    title: 'Pause'
                })
                $playbutton.removeClass('navimages btnplay').addClass('navimages btnpause');
            }
            slideshow.setting.ispaused = !slideshow.setting.ispaused
        }
		
    },
    showslide: function (keyword) {
        var slideshow = this
        var setting = slideshow.setting
        var totalimages = setting.imagearray.length
		if(  $.browser.msie)
			totalimages=totalimages-1;
		
        var imgindex = (keyword == "next") ? (setting.curimage < totalimages - 1 ? setting.curimage + 1 : 0) : (keyword == "prev") ? (setting.curimage > 0 ? setting.curimage - 1 : totalimages - 1) : Math.min(keyword, totalimages - 1)
		
		
        setting.gallerylayers[setting.bglayer].innerHTML = simpleGallery.routines.getSlideHTML(setting.imagearray[imgindex])
        setting.$gallerylayers.eq(setting.bglayer).css({
            zIndex: 1000,
            opacity: 0
        }).stop().css({
            opacity: 0
        }).animate({
            opacity: 1
        }, setting.fadeduration, function () {
            clearTimeout(setting.playtimer)
            setting.gallerylayers[setting.bglayer].innerHTML = null
            try {
                setting.onslide.call(slideshow, setting.gallerylayers[setting.fglayer], setting.curimage)
            } catch (e) {
                alert("Simple Controls Gallery: An error has occured somwhere in your code attached to the \"onslide\" event: " + e)
            }
            setting.currentstep += 1
            if (setting.autoplay[0]) {
                if (setting.currentstep <= setting.totalsteps) setting.playtimer = setTimeout(function () {
                    slideshow.showslide('next')
                }, setting.autoplay[1])
                else slideshow.navigate("play/pause")
            }
        })
        setting.gallerylayers[setting.fglayer].style.zIndex = 999
        setting.fglayer = setting.bglayer
        setting.bglayer = (setting.bglayer == 0) ? 1 : 0
        setting.curimage = imgindex
        if (setting.imagearray[imgindex][3]) {
            setting.$descpanel.css({
                visibility: 'visible'
            })
            setting.descdiv.innerHTML = setting.imagearray[imgindex][3]
        } else if (setting.longestdesc != "") {
            setting.descdiv.innerHTML = null
            setting.$descpanel.css({
                visibility: 'hidden'
            })
        }
    },
    showhidenavpanel: function (state) {
        var setting = this.setting
        var endpoint = (state == "show") ? setting.dimensions[1] - setting.panelheight : this.setting.dimensions[1]
        setting.$navpanel.stop().animate({
            top: endpoint
        }, simpleGallery_navpanel.slideduration)
        if (setting.longestdesc != "") this.showhidedescpanel(state)
    },
    showhidedescpanel: function (state) {
        var setting = this.setting
        var endpoint = (state == "show") ? 0 : -setting.descpanelheight
        setting.$descpanel.stop().animate({
            top: endpoint
        }, simpleGallery_navpanel.slideduration)
    }
}
simpleGallery.routines = {
    getSlideHTML: function (imgelement) {
        var layerHTML = (imgelement[1]) ? '<a href="' + imgelement[1] + '" target="' + imgelement[2] + '">\n' : ''
        layerHTML += imgelement[0]
        layerHTML += (imgelement[1]) ? '</a>' : ''
        return layerHTML
    },
    addnavpanel: function (setting) {
        var interfaceHTML = ''
        for (var i = 0; i < 3; i++) {
            var imgstyle = 'position:relative;  cursor:hand; cursor:pointer; top:' + simpleGallery_navpanel.imageSpacing.offsetTop[i] + 'px; margin-right:' + (i != 2 ? simpleGallery_navpanel.imageSpacing.spacing + 'px' : 0)
            var title = (i == 0 ? 'Prev' : (i == 1) ? (setting.ispaused ? 'Play' : 'Pause') : 'Next')
            var imagesrc = (i == 1) ? simpleGallery_navpanel.images[(setting.ispaused) ? 1 : 3] : simpleGallery_navpanel.images[i]
            interfaceHTML += '<img src="'+itei_site_url+'/images/blank.gif" height="15" width="15" title="' + title + '" class="navimages ' + imagesrc + '" style="' + imgstyle + '" />'
        }
        setting.$navpanel = $('<div class="navpanellayer"></div>').css({
            position: 'absolute',
            width: '100%',
            height: setting.panelheight,
            left: 0,
            top: setting.dimensions[1],
            font: simpleGallery_navpanel.panel.fontStyle,
            zIndex: '1001'
        }).appendTo(setting.$wrapperdiv)
        $('<div class="navpanelbg"></div><div class="navpanelfg"></div>').css({
            position: 'absolute',
            left: 0,
            top: '-8px',
            width: '11%',
            height: '100%'
        }).eq(0).css({
            opacity: simpleGallery_navpanel.panel.opacity
        }).end().eq(1).css({
            paddingTop: simpleGallery_navpanel.panel.paddingTop,
            marginLeft: '50px',
            color: 'white'
        }).html(interfaceHTML).end().appendTo(setting.$navpanel)
        return setting.$navpanel.find('img.navimages, div.gallerystatus').get()
    },
    adddescpanel: function (setting) {
        setting.$descpanel = $('<div class="gallerydesc"><div class="gallerydescbg"></div><div class="gallerydescfg"><div class="gallerydesctext"></div></div></div>').css({
            position: 'absolute',
            width: '100%',
            left: 0,
            top: -1000,
            zIndex: '1001'
        }).find('div').css({
            position: 'absolute',
            left: 0,
            top: 0,
            width: '100%'
        }).eq(0).css({
            opacity: simpleGallery_navpanel.panel.opacity
        }).end().eq(1).css({
            color: 'white'
        }).end().eq(2).html(setting.longestdesc).end().end().appendTo(setting.$wrapperdiv)
        var $gallerydesctext = setting.$descpanel.find('div.gallerydesctext')
        setting.descpanelheight = $gallerydesctext.outerHeight()
        setting.$descpanel.css({
            top: -setting.descpanelheight,
            height: setting.descpanelheight
        }).find('div').css({
            height: '100%'
        })
        return setting.$descpanel.find('div.gallerydesctext').get(0)
    },
    getCookie: function (Name) {
        var re = new RegExp(Name + "=[^;]+", "i");
        if (document.cookie.match(re)) return document.cookie.match(re)[0].split("=")[1]
        return null
    },
    setCookie: function (name, value) {
        document.cookie = name + "=" + value + ";path=/"
    }
}
