﻿var $j = jQuery.noConflict();
var theWidth = 980;
var theHeight = 286;
var currentContent = 0;


$j(window).resize(function () {
    SsizeContent();
});

$j(window).ready(function () {
    SsizeContent();
});

function SsizeContent() {
    //theWidth = $j(window).width();
    //theHeight = $j(window).height();
//     theWidth = 800;
//     theHeight = 500;
    SsizeContentItems();
    SsetLeftOnContentItems();
    SsizeContentWrapper(theWidth, theHeight);
    SmoveContent(currentContent, theWidth);
   	SchangeSelected(currentContent);
}

function SsizeContentItems() {
    $j(".contentItem").css('width', theWidth);
    $j(".contentItem").css('height', theHeight);
}

function SsetLeftOnContentItems() {
    var contentCount = 0;
    $j(".contentItem").each(function (i) {
        contentCount += i;
        $j(this).css('left', i * theWidth);
    });
}

function SsizeContentWrapper(width, height) {
    $j("#contentWrapper").css('width', width);
    $j("#contentWrapper").css('height', height);
}

function SmoveContent(i, width) {
    //$j("#contentWrapper").scrollLeft(i * width);
}

function SchangeSelected(i) {
    var j = 0;
    for (j; j<=4; j++) {
        $j(".selected_" + j).removeClass("selected_" + j);
    }
    
    $j("li:eq(" + i + ") a").addClass("selected_" + i);
}

function SscrollContentNext() {
    SscrollContent(currentContent + 1);
}

function SscrollContentPrev() {
    SscrollContent(currentContent - 1);
}

function SscrollContent(i) {
    i = checkMax(i);
    SscrollMidLayer(i);
    SscrollBackLayer(i);
    SchangeSelected(i)
    currentContent = i;
    $j("#contentWrapper").stop().animate({ scrollLeft: i * theWidth }, 1000);
}

function SfullStop() {
    $j("#contentWrapper").stop(true,false);
    $j("#midlayer").stop(true,false);
    $j("#backlayer").stop(true,false);
    return false;
}

function fader(i) {
    //checkMax(i);
    //alert(i);
    //if (i == 2) {
    //$j("#contentPicture2").fadeOut("slow");
    //}
}

function SscrollMidLayer(i) {
    var left = (i * -740);
    $j("#midlayer").stop().animate({ left: left }, 1000);
}

function SscrollBackLayer(i) {
    var left = (i * -510);
    $j("#backlayer").stop().animate({ left: left }, 1000);
}

function checkMax(i) {
    // var maxItems = $j("li").length;
    var maxItems = 5;
    if (i >= maxItems || i < 0) {
        return 0;  
    }
    //alert(i);
    return i;
}


