﻿/// <reference path="jquery-1.4.1.js" />
/// <reference path="jquery-1.4.1.min-vsdoc.js"/>

$(document).ready(function () {
    //            $("body").randombg({
    //                directory: "Images/Backgrounds/", //directory to image folder
    //                howmany: 3 //how many images are in this folder
    //            });

    var flashvars = {};
    var params = {};
    var attributes = {};
    params.loop = "true";
    params.wmode = "transparent";

    // swfobject.embedSWF("Flashs/Totem1.swf", "MainFlash", "214", "450", "9.0.0", false, flashvars, params, attributes);
    swfobject.embedSWF("Flashs/Logo.swf", "LogoFlash", "200", "100", "9.0.0", false, flashvars, params, attributes);

    var paramsbg = {};
    paramsbg.loop = "true";
    paramsbg.wmode = "transparent";
    paramsbg.scale = "noscale";
    paramsbg.align = "top";
    paramsbg.salign = "t";


    swfobject.embedSWF("Flashs/bg.swf", "background", "100%", "100%", "9.0.0", false, flashvars, paramsbg, attributes);


    //            $('#buttons img').click(function () {
    //                AnimateButtons(this);
    //            });

    //            $('#buttons img:first').click();

    $('#menu img').click(function () {
        AnimateMenu(this);
    });

    $('#menu img:first').click();


    $('#topmenu li').click(function () {
        menuClick(this);
    });


    $("#news-container, .leftButton, .rightButton").hover(function () {
        $(".leftButton, .rightButton").fadeIn();
    }, function () {
        $(".leftButton, .rightButton").fadeOut();
    });



    var c = 0;

    $(".rightButton").click(function () {

        var m = $("#news > .new").length - 4;

        if (c < m) {
            c++;
        }
        else { return; }


        for (var i = 0; i < c; i++) {
            var div = $("#news > .new:eq(" + i + ")");

            var x = $(div).css("marginLeft").replace("px", "");

            if (x == "auto") {
                x = 0;
            }

            x = parseInt(x) - 200;

            $(div).animate({
                marginLeft: x
            }, 100);
        }


    });

    $(".leftButton").click(function () {
        if (c > 0) {
            c--;
        } else { return; }


        for (var i = 0; i < c + 1; i++) {
            var div = $("#news > .new:eq(" + i + ")");

            var x = $(div).css("marginLeft").replace("px", "");

            if (x == "auto") {
                x = 0;
            }

            x = parseInt(x) + 200;

            $(div).animate({
                marginLeft: x
            }, 100);
        }

    });

    $(".info-button").click(function () {
        var state = $(this).attr("state");

        switch (state) {
            case "":
                $(this).attr("state", "in");
                break;
            case "in":
                $(this).attr("state", "out");
                break;
            case "out":
                $(this).attr("state", "in");
                break;
            default:
                break;
        }


        if ($(this).attr("state") == "in") {
            $(".info-content").fadeIn("slow", function () {
                //$(this).css("opacity", "0.8"); 
            });
        } else {
            $(".info-content").fadeOut("slow");
        }

    });

});

function openNew(obj) {
    $("#" + obj + " .new-content").show();
    $("#" + obj + " .new-image").hide();

    $("#news .new").each(function (i) {
        if (obj != this.id) {
            $(this).animate({
                top: "+150px",
                width: "100px",
                height: "150px"
            }, 500);

            $("#" + this.id + " span").hide();
            $("#" + this.id + " .new-content").hide();
            $("#" + this.id + " .new-image").show();
        }
    });

    $("#" + obj).animate({
        top: "0px",
        width: "488px",
        height: "300px"
    }, 500, function () {
        $("#" + obj + " span").show();
    });
}


function closeNew(obj) {
    $("#" + obj).animate({
        top: "+150px",
        width: "197px",
        height: "150px"
    }, 500);

    $("#news .new").each(function (i) {
        if (obj != this.id) {
            $(this).animate({
                top: "+150px",
                width: "197px",
                height: "150px"
            }, 500);
        }
    });


    $("#" + obj + " span").hide();
    $("#" + obj + " .new-content").hide();
    $("#" + obj + " .new-image").show();
}

//        function AnimateButtons(obj) {
//            if (!$(obj).hasClass('current')) {

//                $(obj).stop();
//                $("#buttons img").each(function (i) {
//                    if ($(this).hasClass('current')) {
//                        $(this).animate({
//                            marginTop: "32px",
//                            width: "64px",
//                            height: "64px",
//                            marginLeft: "0px",
//                            marginRight: "0px"
//                        }, 500, function () {
//                            $(this).removeClass("current");
//                        });
//                    }
//                });


//                $(obj).addClass('current');

//                $(obj).animate({
//                    marginTop: "0px",
//                    width: "128px",
//                    height: "128px",
//                    marginLeft: "225px",
//                    marginRight: "225px"
//                }, 1000);

//            }
//        }

function AnimateMenu(obj) {
    if (!$(obj).hasClass('current')) {

        $(obj).stop();

        $("#menu img").each(function (i) {
            if ($(this).hasClass('current')) {
                $(this).animate({
                    width: "12px",
                    height: "26px",
                    marginLeft: "0px",
                    marginRight: "0px"
                }, 500, function () {
                    $(this).removeClass("current");

                    var src = $(this).attr("src").replace("h", "");
                    $(this).attr("src", src);
                });
            }
        });

        var src = $(obj).attr("src").match(/[^\.]+/) + "h.png";
        $(obj).attr("src", src);

        $(obj).addClass('current');

        $("#content").slideUp();

        $(obj).animate({
            marginTop: "0px",
            width: "120px",
            height: "26px"
        }, 1000, function () {
            var title = $(obj).attr("title");
            var content = $(obj).attr("content");
            var color = $(obj).attr("color");

            if (content != null) {
                $("#content").slideDown();
                $("#content").css({ backgroundColor: color });
                $("#content-title").text(title);
                $("#content-content").text("Yükleniyor...");
                $("#content-content").load(content, function () {
                    //Contents lerde sağ taraftaki menü nün click eventı
                    $('.cMenu li').click(function () {
                        product(this);

                    });

                    $(".cMenu > li:eq(0)").click();
                });
            } else {
                $("#content").slideUp();
            }
        }
                );

    }
}

function menuClick(obj) {
    $(obj).addClass("selected");
    var selected = 0;

    $("ul#topmenu li").each(function (index) {
        if ($(this).hasClass("selected")) {
            selected = index;
        }
    });

    $(obj).removeClass("selected");

    $("#menu > img:eq(" + selected + ")").click();

    return false;
}



function product(obj) {

    $("#p div").each(function (i) {
        $(this).slideUp(500);
    });

    $("#pimg img").each(function (i) {
        $(this).slideUp(700);
    });

    $("#p-sub div").each(function (i) {
        $(this).slideUp(700);
    });

    var title = $(obj).attr("title");

    $("#" + title).slideDown(500);
    $("#" + title + "img").slideDown(500);

    $("#" + title + "-sub").slideDown(500);

}
