$(function () {
    //ajax setup
    $.ajaxSetup({ cache: false, dataType: "html" });

    //load ajax mailing
    if ($('#ajaxmailing').length > 0 && $('#ajaxmailing').html() == '&nbsp;') {
        ajaxMailing(1, '');
    }

});


/*$.fn.autoscroll.defaults = {
    start: {
        step: 50,
        scroll: true,
        direction: "down"
    },
    delay: 5000,
    ffrw: { speed: "slow", step: 100 }
};*/

function startAutoscroll() {

    //destroy if active
    /*setTimeout(function () {
        $("#scrollable").autoscroll('destroy');
        //$("#scrollable").autoscroll('addpausesource', 180000);
        $('#scrollable').autoscroll();
        $('#scrollable').autoscroll('reverse');
    }, 1000);*/

    $("#scrollable").autoscroll('destroy');
    $('#scrollable').autoscroll();
    $('#scrollable').autoscroll('reverse');
  

    //start new
    //$('#scrollable').autoscroll();
    //$('#scrollable').autoscroll([{ onEdge: function (edge) { alert('ads'); } }]);


    //$('#scrollable').autoscroll([{ direction: 'left', step: 50, scroll: true, onEvaluate: function () { /* code */ }, onEdge: function (edge) { alert('konec'); } }]);


    //$('#scrollable').autoscroll('rewind', [settings]);

    //$("#scrollable").autoscroll("delay", 2000);
    //$('#scrollable').autoscroll([{'delay': 2000}]);
    //$('#scrollable').autoscroll([{ onEdge: function (edge) { alert('ads'); } }]);

     //$('#carousel_ul li:first').before($('#carousel_ul li:last'));

    //$('#scrollable').autoscroll('reverse');

    //$("scrollable").autoscroll("rewind");

  /*      if (direction = 'right') {
            $('#scrollable').autoscroll('reverse', [{ onEdge: function (edge) { startAutoscroll("left") } }]);
            //$('#scrollable').autoscroll([{ onEdge: function (edge) { startAutoscroll("left") } }]);
        }
        else {
            $('#scrollable').autoscroll([{ onEdge: function (edge) { startAutoscroll("right") } }]);
        }*/

    //$('#scrollable').autoscroll([{ direction: 'left', step: 50, scroll: true, onEvaluate: function () { /* code */ }, onEdge: function (edge) { /* code */ } }]);
   
    
   //alert('test');
}

//ajaxmailing
function ajaxMailing(mailingid, email) {
    $.ajax({
        url: 'http://www.buyitc.si/ajaxmailing.aspx',
        data: ({ mailingid: mailingid, email: email }),
        success: function (data) {
            $('#ajaxmailing').html(data);
        }
    });
};

//get banner link
function getBannerLink(position) {

    if (BannerUrlOpenType[position] = 1)
    {
        window.location = BannerUrl[position];
    }
    else //new window
    {
        window.open(BannerUrl[position]);
    }
}

/* show hide news months */ 
function showMonths(year){

    $('.month').hide();
    $('.' + year).show();
    $('.leftyear a').addClass('arialblack11');
    $('.leftyear a').removeClass('arial11orange');
    $('#year' + year + ' a').addClass('arial11orange');
}

//ajaxcustomer
function getAjaxCustomer(docid, firstload) {
    //loader image
    $('#ajaxcustomer').html($('#loader').html());

    $.ajax({
        url: 'http://www.buyitc.si/ajaxcustomer.aspx',
        data: ({ docid: docid, firstload: firstload }),
        success: function (data) {
            $('#ajaxcustomer').html(data);
        }
    });
};

// show content image popup
function showAjaxLargeImage(position, contenttypeid, contentid) {

    //set window width and height
    $('#modalwindow').css({ width: 687, height:350 });
    $('#modalwindow').addClass('modalwindowlargeimage');

    //call ajax
    $.ajax({
        url: 'http://www.buyitc.si/ajaxlargeimage.aspx',
        data: ({ position: position, contenttypeid: contenttypeid, contentid: contentid }),
        success: function (data) {

            $('#modalwindow').html(data);
            openPopup();

            $('#largeimage').hide();
            $('#largeimage').fadeIn(2000);
        }
    });
}

/* POPUP */
function showPopup(contentdivid) {
    $('#modalwindow').html($('#' + contentdivid).html());
    openPopup();
}

//0 = disabled; 1 = enabled;  
var popupStatus = 0;

//open popup
function openPopup() {
    if (popupStatus == 0) {
        //set that popup is open
        popupStatus = 1;

        //check for IE - show modal window
//        if ($.browser.msie) {
//            $('#modalwindowbackground').css({ 'opacity': '0.0' });
//            $('#modalwindowbackground').css('display', 'block');
//            $('#modalwindow').css('display', 'block');
//        }
//        else {
            $('#modalwindowbackground').css({ 'opacity': '0.0' });
            $('#modalwindowbackground').fadeIn('fast');
            $('#modalwindow').fadeIn('fast');
//        }

        //popup - center
        centerPopup();
    }
}

//position popup in center of window
function centerPopup() {
    //request data for centering
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();

    var popupWidth = $("#modalwindow").width();
    var popupHeight = $("#modalwindow").height();

    var newWidth = windowHeight / 2 - popupHeight / 2;
    var newHeight = windowWidth / 2 - popupWidth / 2;

    //centering
    $('#modalwindow').css({ top: newWidth - 70, left: newHeight });
}

//dispose popup
function disposePopup() {
    //disables popup only if it is enabled
    if (popupStatus == 1) {
        //mozilla
        if ($.browser == "mozilla" && $.browser.version.substr(0, 3) == "1.9") {
            $('#modalwindowbackground').fadeOut('fast');
            $('#modalwindow').fadeOut('fast');
            $('#adseldiv').fadeOut('fast');
        } else {
            $('#modalwindowbackground').css('display', 'none');
            $('#modalwindow').css('display', 'none');
            $('#adseldiv').css('display', 'none');
        }

        //set that popup is closed
        popupStatus = 0;
    }
}

//close popup window
function closePopup() {
    //popup - dispose
    disposePopup();
}

/* CONTENT, LOCATION */

//show selected item icon
function showSelector(docid) {

    $('#selector_' + docid).show();
}

//hide selected item icon
function hideSelector(docid) {
    $('#selector_' + docid).hide();
}


/* SOLUTION.ASPX */
//show/hide section
function showHideSection(divid) {

    if ($('#' + divid).is(':visible')) {

        //hide all answers/change icons (added 2.3.2011)
        $('.answer').hide();
        $('.arrowlink').attr('src', $('#' + divid + '-arrowlink').attr('src').replace('open', 'closed'));
        $('.question').removeClass('maincolorfont3');

        /*//hide content
        $('#' + divid).hide();
        //change icon
        $('#' + divid + '-arrowlink').attr('src', $('#' + divid + '-arrowlink').attr('src').replace('open', 'closed'));
        */
    }
    else {

        //hide all answers/change icons (added 2.3.2011)
        $('.answer').hide();
        $('.arrowlink').attr('src', $('#' + divid + '-arrowlink').attr('src').replace('open', 'closed'));
        $('.question').removeClass('maincolorfont3');

        //paint question orange
        $('#question_' + divid).addClass('maincolorfont3');
        //show content        
        $('#' + divid).show();
        //change icon
        $('#' + divid + '-arrowlink').attr('src', $('#' + divid + '-arrowlink').attr('src').replace('closed', 'open'));
    }

   
}

//show modulepopup
function showModulePopup(docid) {

    //hide all popups
    $('.modulepopup').hide();

    //get icon position
    var pos = $('#moduleimage_' + docid).position();
    //var pos = $('#moduleimage_' + docid).offset();

    //move popup over icon
    $('#modulepopup_' + docid).css({ "left": (pos.left) + "px", "top": pos.top + "px" });
    
    //if IE7 - 
    //??? if EI7: if ((document.all && !window.opera && window.XMLHttpRequest) ? true : false)
    //show popup
    $('#modulepopup_' + docid).show();
}

//show modulepopup
function hideModulePopup(docid) {
    //$('#modulepopup_' + docid).hide();

    //hide all popups
    $('.modulepopup').hide();
}


/* SOLUTIONS.ASPX */
var popup_shown = "";

//show solution popup
function showSolutionPopup(docid) {
    $('#solutionpopup_' + docid).show();
    //$('#solutionpopup_' + docid).css('z-index', '1000');
    //$('#solution_' + docid).css('z-index', '0');
}

//hide solution popup
function hideSolutionPopup(docid) {
    $('#solutionpopup_' + docid).hide();
    //$('#solutionpopup_' + docid).css('z-index', '0');
    //$('#solution_' + docid).css('z-index', '1000');
}


/* FIX ON MOUSEOUT */
function is_child_of(parent, child) {
    if (child != null) {
        while (child.parentNode) {
            if ((child = child.parentNode) == parent) {
                return true;
            }
        }
    }
    return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
    var current_mouse_target = null;
    if (event.toElement) {
        current_mouse_target = event.toElement;
    } else if (event.relatedTarget) {
        current_mouse_target = event.relatedTarget;
    }
    if (!is_child_of(element, current_mouse_target) && element != current_mouse_target) {
        eval(JavaScript_code);
    }
}

/* SEARCH.ASPX */
//set search page
function setSearchPage(page) {
    $('#page').val(page);
    $('#sitesearchform').submit();
}

//show upper contact box (popup)
function showContactBox() {
    $('#box-open').show();
}

//hide upper contact box (popup)
function hideContactBox() {
    $('#box-open').hide();
}

