// JavaScript Document


function thisMovie(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        return window[movieName];
    } else
    {
        return document[movieName];
    }
}


function onPlayClick()
{
    thisMovie("BackPlayer").onPlayClick();
}

function onMuteClick()
{
    thisMovie("BackPlayer").onMuteClick();
}

function onPreviousClick()
{
    thisMovie("BackPlayer").onPreviousClick();
}

function onNextClick()
{
    thisMovie("BackPlayer").onNextClick();
}


$(document).ready(function ()
{

	$('.css-scrollbar').scrollbar();
	
    $("#PlayPause").click(function ()
    {
        onPlayClick();
    });

});


$(window).load(function ()
{

    //When mouse rolls over

    // Top Menu 
    $("#TopMenu").mouseover(function ()
    {
        $(this).stop().animate({ top: '0px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
        $("#TopMenuBottom").stop().animate({ top: '-5px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
		$("#TopMenuBottom").css("background-position" , "left bottom");
    });


    $("#TopMenu").mouseout(function ()
    {
        $(this).stop().animate({ top: '-35px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
		$("#TopMenuBottom").stop().animate({ top: '-40px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
        $("#TopMenuBottom").css("background-position" , "left top");
    });

    $("#TopMenuBottom a").mouseover(function ()
    {
        $("#TopMenu").stop().animate({ top: '0px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
		$("#TopMenuBottom").stop().animate({ top: '-5px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
		$("#TopMenuBottom").css("background-position" , "left bottom");
    });


    $("#TopMenuBottom a").mouseout(function ()
    {
        $("#TopMenu").stop().animate({ top: '-35px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
		$("#TopMenuBottom").stop().animate({ top: '-40px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
		$("#TopMenuBottom").css("background-position" , "left top");
    });

    $("#TopMenu").stop().animate({ top: '-35px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
	$("#TopMenuBottom").stop().animate({ top: '-40px' }, { queue: false, duration: 1000, easing: 'easeOutCubic' });
	
	$("#TopMenuBottom").css("background-position" , "left top");
	
	
	
	$("#PlayPause").click(function ()
    {
		
		if ($("#PlayPause").css("background-position") == "0% 0%") 
		{
            $("#PlayPause").css("background-position", "left bottom");
        } 
		else 
		{
            $("#PlayPause").css("background-position", "left top");
        }
        
    });
	
    /* Anasayfa slide */

    $(".ClickContainer a").click(function ()
    {
        if ($("#SlideContent").offset().left < -200)
        {
            SetHomePageSliderPosition('right');
        }
        else
        {
            SetHomePageSliderPosition('left');
        }

        return false;
    });

});

$(window).resize(function ()
{
    SetHomePageSliderPosition('resize');
});

function SetHomePageSliderPosition(action)
{
    if (!action)
    {
        return; 
    }

    var $container = $("#SlideContent");
    var pos = $container.offset();

    if (action == 'resize')
    {
        if (pos.left < -200)
        {
            var leftDiff = ($(window).width() - $('#HomeContainer').width()) / 2;

            $container.css('left', '-' + ($("#SlideContent").width() + leftDiff - 21) + 'px');// .stop().animate({ left:  }, { queue: false, duration: 900, easing: 'easeOutCubic' })
        }
        //alert(pos.left);
        //alert('resize');
    }
    else if (action == 'left')
    {
        //alert('left');
        $container.stop().animate({ left: '-' + (pos.left + $("#SlideContent").width() - 20) + 'px' }, { queue: false, duration: 900, easing: 'easeOutCubic' })
        $('.ClickContainer').css('background-position', 'top right');
    }
    else if (action == 'right')
    {
        //alert('right');
        $container.stop().animate({ left: '0px' }, { queue: false, duration: 900, easing: 'easeInCubic' })
        $('.ClickContainer').css('background-position', 'top left');
    }
}

$(document).ready(function ()
{

    $('#loopedSlider').loopedSlider({
        restart: 5000,
        slidespeed: 700,
        containerClick: false
    });

    /* WIDTH 940 */

    var currentPage = 0;

    var totalWidth = 0;
    $(".UrunContent > div").each(function ()
    {
        totalWidth += $(this).outerWidth();
    });
    $(".UrunContent").width(totalWidth);

    if (totalWidth <= 844)
    {
        $(".SlidingContent .next").hide();
        $(".SlidingContent .previous").hide();
    }
	

    var pageSize = 211;
    var animationDuration = 700;
    $(".SlidingContent .next").click(function ()
    {
        var containerWidth = $(".UrunContent").width();
        var visibleWidth = $(".UrunContainer").width();
        var maxPage = Math.ceil((containerWidth - visibleWidth + 10) / pageSize);
        if (currentPage < maxPage)
        {
            currentPage++;
            if (currentPage == maxPage)
                $(".UrunContent").animate({ left: -(containerWidth - visibleWidth + 10) }, animationDuration);
            else
                $(".UrunContent").animate({ left: -currentPage * pageSize }, animationDuration);

        }

        return false;
    });
    $(".SlidingContent .previous").click(function ()
    {
        if (currentPage > 0)
        {
            currentPage--;
            $(".UrunContent").animate({ left: -currentPage * pageSize }, animationDuration);
        }

        return false;
    });


});



/* FOOTER */

$(window).load(function ()
{
    SetBottomBarPosition();

    $(window).resize(function ()
    {
        SetBottomBarPosition();
    });
});

function SetBottomBarPosition()
{
    var $bottomBar = $('#FooterContainer');

    if ($bottomBar.length == 0)
    {
        return;
    }

    var mainContainerHeight = 675;
    var windowHeight = $(window).height();
    //alert(windowHeight);

    if (windowHeight > mainContainerHeight)
    {
        $bottomBar.css('position', 'absolute');
        $bottomBar.css('bottom', '0px');

        //$('#MasterContainer').height();
    }
    else
    {
        $bottomBar.css('position', 'static');
        $bottomBar.css('bottom', '0px');
        $('#HomeContainer').height(505);
    }

    //alert("windowHeight: " + windowHeight);

    //alert($('html').height());
    //alert($('body').height());

}

// Shadowbox
$(document).ready(function ()
{
    //Shadowbox.init();

    Shadowbox.init({
        continuous: 'true',
        handleOversize: 'resize',
        onClose: back_to_resize,
        onChange: back_to_resize,
        onOpen: back_to_resize
    });
});

// Detay sayfasında resme tıklandığında videoyu başlat
$(document).ready(function ()
{
    $('.ProjectImage > img').click(function ()
    {
        $(this).hide();
        $f(0).play();
    });
});

