﻿// HINTS FOR FORM INPUTS PLUG IN
(function ($) {
    $.fn.clearDefault = function () {
        return this.each(function () {
            var default_value = $(this).attr('title');
            $(this).val(default_value);
            var id = $(this).attr('id');

            var labl = $("label[for='" + id + "']");
            //alert(labl);
            if (typeof (labl) != undefined) {
                labl.hide();
            };
            $(this).focus(function () {
                if ($(this).val() == default_value) $(this).val("");
            });
            $(this).blur(function () {
                if ($(this).val() == "") $(this).val(default_value);
            });
        });
    };
})(jQuery);

// POP UP WINDOW PLUG IN
(function ($) {
    $.fn.popupWindow = function (instanceSettings) {

        return this.each(function () {

            $(this).click(function () {

                $.fn.popupWindow.defaultSettings = {
                    centerBrowser: 0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
                    centerScreen: 0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
                    height: 500, // sets the height in pixels of the window.
                    left: 0, // left position when the window appears.
                    location: 0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
                    menubar: 0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
                    resizable: 0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
                    scrollbars: 0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
                    status: 0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
                    width: 500, // sets the width in pixels of the window.
                    windowName: null, // name of window set from the name attribute of the element that invokes the click
                    windowURL: null, // url used for the popup
                    top: 0, // top position when the window appears.
                    toolbar: 0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
                };

                settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});

                var windowFeatures = 'height=' + settings.height +
                                ',width=' + settings.width +
                                ',toolbar=' + settings.toolbar +
                                ',scrollbars=' + settings.scrollbars +
                                ',status=' + settings.status +
                                ',resizable=' + settings.resizable +
                                ',location=' + settings.location +
                                ',menuBar=' + settings.menubar;

                settings.windowName = this.name || settings.windowName;
                settings.windowURL = this.href || settings.windowURL;
                var centeredY, centeredX;

                if (settings.centerBrowser) {

                    if ($.browser.msie) {//hacked together for IE browsers
                        centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120) / 2) - (settings.height / 2)));
                        centeredX = window.screenLeft + ((((document.body.offsetWidth + 20) / 2) - (settings.width / 2)));
                    } else {
                        centeredY = window.screenY + (((window.outerHeight / 2) - (settings.height / 2)));
                        centeredX = window.screenX + (((window.outerWidth / 2) - (settings.width / 2)));
                    }
                    window.open(settings.windowURL, settings.windowName, windowFeatures + ',left=' + centeredX + ',top=' + centeredY).focus();
                } else if (settings.centerScreen) {
                    centeredY = (screen.height - settings.height) / 2;
                    centeredX = (screen.width - settings.width) / 2;
                    window.open(settings.windowURL, settings.windowName, windowFeatures + ',left=' + centeredX + ',top=' + centeredY).focus();
                } else {
                    window.open(settings.windowURL, settings.windowName, windowFeatures + ',left=' + settings.left + ',top=' + settings.top).focus();
                }
                return false;
            });

        });
    };
})(jQuery);

// EASING
jQuery.easing['jswing'] = jQuery.easing['swing']; jQuery.extend(jQuery.easing, { def: 'easeOutQuad', swing: function (x, t, b, c, d) { return jQuery.easing[jQuery.easing.def](x, t, b, c, d) }, easeInQuad: function (x, t, b, c, d) { return c * (t /= d) * t + b }, easeOutQuad: function (x, t, b, c, d) { return -c * (t /= d) * (t - 2) + b }, easeInOutQuad: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b }, easeInCubic: function (x, t, b, c, d) { return c * (t /= d) * t * t + b }, easeOutCubic: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b }, easeInOutCubic: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b }, easeInQuart: function (x, t, b, c, d) { return c * (t /= d) * t * t * t + b }, easeOutQuart: function (x, t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b }, easeInOutQuart: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b }, easeInQuint: function (x, t, b, c, d) { return c * (t /= d) * t * t * t * t + b }, easeOutQuint: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b }, easeInOutQuint: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b }, easeInSine: function (x, t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b }, easeOutSine: function (x, t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b }, easeInOutSine: function (x, t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b }, easeInExpo: function (x, t, b, c, d) { return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b }, easeOutExpo: function (x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b }, easeInOutExpo: function (x, t, b, c, d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b }, easeInCirc: function (x, t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b }, easeOutCirc: function (x, t, b, c, d) { return c * Math.sqrt(1 - (t = t / d - 1) * t) + b }, easeInOutCirc: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b }, easeInElastic: function (x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4 } else var s = p / (2 * Math.PI) * Math.asin(c / a); return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b }, easeOutElastic: function (x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4 } else var s = p / (2 * Math.PI) * Math.asin(c / a); return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b }, easeInOutElastic: function (x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); if (a < Math.abs(c)) { a = c; var s = p / 4 } else var s = p / (2 * Math.PI) * Math.asin(c / a); if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b }, easeInBack: function (x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b }, easeOutBack: function (x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b }, easeInOutBack: function (x, t, b, c, d, s) { if (s == undefined) s = 1.70158; if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b }, easeInBounce: function (x, t, b, c, d) { return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b }, easeOutBounce: function (x, t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b } }, easeInOutBounce: function (x, t, b, c, d) { if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b; return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b } });


jQuery.browser.version = (jQuery.browser.msie && /msie 7\.0/i.test(navigator.userAgent)) ? "7.0" : (jQuery.browser.msie && /msie 8\.0/i.test(navigator.userAgent) ? "8.0" : jQuery.browser.version);
jQuery.easing.def = "easeOutCirc";

var rotateImages = function (img) {
    if (typeof (img.attr('src')) != "undefined") {
        img.hide().fadeIn(700).fadeOut(800, function () {
            rotateImages(img);
            //console.log(img.attr('src'));
        });
    };
}

$(document).ready(function () {

    $(".clearHint").clearDefault();
    /*
    $("form").submit(function () {
        var ret = true;
        $(".clearHint").each(function () {
            var $this = $(this);
            var title = $this.attr("title");
            if (title == $this.val()) {
                $this.val("");
                ret = false;
            }
        });
        return ret;
    });
    */

    $(".openTarget").click(function () {
        var $this = $(this);
        var target = $this.attr("href");
        $(target).animate({ height: "toggle", opacity: "toggle" }, 400);
        return false;
    });

    $(".changeIt").click(function () {
        var $this = $(this);
        var changeIt = $this.attr("ref");
        var src = $this.attr("src");
        //var usual = $.data($this, "usualImg");
        if (changeIt != "undefined") {
            $this.attr("src", changeIt);
            $this.attr("ref", src);
        }
    });

    $("a.opaque-links img").css("opacity", "0.4");
    $("a.opaque-links img").hover(function () {
        $(this).stop(true, true).animate({ opacity: "1" }, 200);
    },
    function () {
        $(this).animate({ opacity: "0.4" }, 500);
    });

    $(".rotateImages").each(function () {
        var img2 = $('img:eq(1)', this);
        var imgHeight = 0;
        $("img", this).load(function (e) {
            $(this).css({
                position: "absolute",
                top: 0,
                left: 0
            });
            imgHeight = ($(this).height() > imgHeight) ? $(this).height() : imgHeight;
            $(this).parents(".rotateImages").height(imgHeight);
        });
        $(this).css({
            display: "block",
            position: "relative"

        });
        //alert("sad");
        rotateImages(img2);
    });

    $("a[href='#']").click(function () {
        return false;
    });

    $("#footerLinkHelp, #footerLinkUserArangement").popupWindow({
        height: 500,
        width: 500,
        top: 100,
        left: 200
    });


    $('#main-site-nav ul li').hover(
        function () {

            $(this).children('ul').stop(true, true).animate({ "opacity": 0.9, "height": "show" }, 200);
        },
        function () {
            $(this).children('ul').animate({ "opacity": 0, "height": "hide" }, 100);
        }
    );
    $('#main-site-nav ul li ul li').css('opacity', 0.7);
    $('#main-site-nav ul li ul li').hover(
        function () {
            $(this).stop(true, true).animate({ "opacity": 1 }, 200);
        },
        function () {
            $(this).animate({ "opacity": 0.7 }, 200);
        }
    );

    $("#joyparaYukleHeader").flashembed(
    {
        src: '/i/joypara/JP-Yukle-120x135.swf?clickTAG=https://bill.joygame.com&target=_self',
        wmode: 'transparent'
    },
    {
        clickTAG: 'https://bill.joygame.com',
        target: '_self'
    });

    if ($("#joyparaFloat").attr("class") == "png") {
        var newpos = ($(window).height() + $(window).scrollTop()) - 175;
        $("#joyparaFloat").css({
            "left": "0px",
            "top": newpos + "px",
            "position": "absolute"
        });

        $(window).scroll(function () {
            var h = $(window).height();
            var w = $(window).width();
            var pos = $(window).scrollTop();
            var newpos = (pos + h) - 175;
            //console.log(newpos);
            $("#joyparaFloat").stop(true, true).animate({
                "top": newpos + "px"
            });
        });
    };

});
