﻿/// <reference path="vsdoc.js" />
var _scrollTo = 0;
$(function() {
    $(window).bind('hashchange', function() {
        var hash = window.location.hash || "auktioner";
        var objectDiv = $('#objectDiv');
        var auctionDiv = $('#auctionDiv');
        var myDiv = $('#myDiv');
        var loadingDiv = $('#loadingDiv');
        if (hash.indexOf("objectid") > 0) {
            CheckRequests();
            $(auctionDiv).empty();
            objectID = hash.replace("#objectid=", "");
            auctionDiv.load("Pages/ObjectPage.aspx?" + hash.replace("#", "") + " #ObjectContent", function() { $.getScript('Scripts/ObjectPage.js'); });
            $(auctionDiv).hide();
            $(myDiv).hide();
            $(objectDiv).hide();
            $(auctionDiv).show();
        } else if (hash.indexOf("filter") > 0) {
            CheckRequests();
            $(objectDiv).empty();
            filterhash = hash;
            $(auctionDiv).hide();
            $(myDiv).hide();
            $(auctionDiv).html('<table width="100%"><tr><td align="center" ><br/><img alt="laddar" src="Images/loading.gif" style="top: 50%; left: 50%;" /></td></tr></table>');
            $(auctionDiv).show();
            auctionDiv.load("Pages/ObjectListPage.aspx?" + hash.replace("#", "") + " #divObjectList").ready(function(){window.setTimeout('scroll()', 2500)});
        } else if (hash.indexOf("min-sida") > 0) {
            CheckRequests();
            myDiv.load("Pages/MyPage.aspx?type=auktioner  #tabs", function() { $.getScript('Scripts/MyPage.js'); }).ready(function() {
                $(auctionDiv).hide();
                $(objectDiv).hide();
                $(myDiv).show();
            });
        } else if (hash.indexOf("mina-auktioner") > 0) {
            CheckRequests();
            myDiv.load("Pages/MyPage.aspx?type=auktioner  #MyContent");
            $(auctionDiv).hide();
            $(objectDiv).hide();
            $(myDiv).show();
        } else if (hash.indexOf("mina-bevakningar") > 0) {
            CheckRequests();
            myDiv.load("Pages/MyPage.aspx?type=watches  #MyContent");
            $(auctionDiv).hide();
            $(objectDiv).hide();
            $(myDiv).show();
        } else if (hash.indexOf("mina-fakturor") > 0) {
            CheckRequests();
            myDiv.load("Pages/MyPage.aspx?type=fakturor  #MyContent");
            $(auctionDiv).hide();
            $(objectDiv).hide();
            $(myDiv).show();
        } else if (hash.indexOf("mina-installningar") > 0) {
            CheckRequests();
            myDiv.load("Pages/MyPage.aspx?type=settings  #MyContent");
            $(auctionDiv).hide();
            $(objectDiv).hide();
            $(myDiv).show();
        } else if (hash.indexOf("auktioner") > 0) {
            filterhash = hash;
            CheckRequests();
            $(objectDiv).hide();
            $(myDiv).hide();
            $(auctionDiv).html('<table width="100%"><tr><td align="center" ><br/><img alt="laddar" src="Images/loading.gif" style="top: 50%; left: 50%;" /></td></tr></table>');
            $(auctionDiv).show();
            auctionDiv.load("Pages/ObjectListPage.aspx?filter=%%&aid=0&cid=0 #divObjectList").ready(function(){window.setTimeout('scroll()', 2500)});
        } else if (hash.indexOf("registrering") > 0) {
            CheckRequests();
            myDiv.load("Pages/Register.aspx #settings-tab", function() { $.getScript('Scripts/RegisterPage.js'); });
            //$(document).ready(function() { $.getScript('Scripts/RegisterPage.js'); });
            $(objectDiv).hide();
            $(myDiv).show();
            $(auctionDiv).hide();
        } else if (hash.indexOf("confirm") > 0) {
            CheckRequests();
            myDiv.load("Pages/Confirmation.aspx #grattis");
            $(objectDiv).hide();
            $(myDiv).show();
            $(auctionDiv).hide();
        } else if (hash.indexOf("token") > 0) {
            CheckRequests();
            myDiv.load("Pages/TokenConfirm.aspx?" + hash.replace("#", "") + "#tokenConfirm");
            $(objectDiv).hide();
            $(myDiv).show();
            $(auctionDiv).hide();
        } else if (hash.indexOf("omoss") > 0) {
            CheckRequests();
            myDiv.load("Pages/AboutUs.aspx #aboutus");
            $(objectDiv).hide();
            $(myDiv).show();
            $(auctionDiv).hide();
        } else if (hash.indexOf("faq") > 0) {
            CheckRequests();
            myDiv.load("Pages/faq.aspx #faq");
            $(objectDiv).hide();
            $(myDiv).show();
            $(auctionDiv).hide();
        } if (hash.indexOf("losenord") > 0) {
            CheckRequests();
            myDiv.load("Pages/LostPassword.aspx #LostContent", function() { $.getScript('Scripts/LostPassword.js'); });
            $(objectDiv).hide();
            $(myDiv).show();
            $(auctionDiv).hide();
        }
        //        else {
        //            window.location.hash = hash;
        //        }
        //$(loadingDiv).hide();
        $.bbq.pushState(hash);
    });

    $(window).trigger("hashchange");
});

//$(document).ready(function() {
//    $('.horizontal_scroller').SetScroller({ velocity: 60,
//        direction: 'horizontal',
//        startfrom: 'right',
//        loop: 'infinite',
//        movetype: 'linear',
//        onmouseover: 'pause',
//        onmouseout: 'play',
//        onstartup: 'play',
//        cursor: 'pointer'
//    });
//});

function scroll() {
    window.scrollTo(0, _scrollTo);  
}

function findPos(obj) {
    var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
	    do {
	        curtop += obj.offsetTop;
	    } while (obj = obj.offsetParent);
	}
	_scrollTo = curtop;
}
