﻿/*
Index Page JS
Copyright (c) 2010 by Absolute IT
http://www.absoluteit.rs
*/

var areao = 0;
var cateo = 0;

function openArea() {

    if (areao == 0) {
        $('#drzac').css('visibility', 'visible');
        document.getElementById('drzac2').style.visibility = 'hidden';
        areao = areao + 1;
    }
    else {
        document.getElementById('drzac').style.visibility = 'hidden';
        areao = areao - 1;
    }
}

function confirmArea() {
    document.getElementById('drzac').style.visibility = 'hidden';
    areao = areao - 1;
}

//za velicinu stanova
function openCategory() {
    if (cateo == 0) {
        document.getElementById('drzac2').style.visibility = 'visible';
        document.getElementById('drzac').style.visibility = 'hidden';
        cateo = cateo + 1;
    }
    else {
        document.getElementById('drzac2').style.visibility = 'hidden';
        cateo = cateo - 1;
    }
}

function confirmCategory() {
    document.getElementById('drzac2').style.visibility = 'hidden';
    cateo = cateo - 1;
}

//selektuj sve chekboxove
function selectArea() {

    $(".area").each(function (i, el) {
        if ($(el).is('input:checkbox')) {
            $(el).attr('checked', true)
        }
    })

}

function selectCategory() {

    $(".category").each(function (i, el) {
        if ($(el).is('input:checkbox')) {
            $(el).attr('checked', true)
        }
    })

}

function salji() {

    //Prag Area
    var area = "";

    $(".area").each(function (i, el) {
        if ($(el).is('input:checkbox')) {
            if ($(el).is(':checked')) {
                area = area + $(el).attr('value') + "@@";
            }
        }
    })

    if (area != "") {
        //area = area.substr(0, area.length - 2);
        $('#zipovi').val(area);
    } else {
        $('#zipovi').val('');
    }

    //Prag Category
    var category = "";

    $(".category").each(function (i, el) {
        if ($(el).is('input:checkbox')) {
            if ($(el).is(':checked')) {
                category = category + $(el).attr('id') + "@@";
            }
        }
    })

    if (category != "") {
        //category = category.substr(0, category.length - 2);
        $('#kategorije').val(category);
    } else {
        $('#kategorije').val('');
    }

    document.getElementById("forma").submit();
}


//slider

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ($active.length == 0) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next = $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order

    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
        .addClass('active')
        .animate({ opacity: 1.0 }, 1000, function () {
            $active.removeClass('active last-active');
        });
}

$(function () {
    setInterval("slideSwitch()", 5000);
});

$(document).ready(function () {

    var first = 0;
    var speed = 700;
    var pause = 6000;

    function removeFirst() {
        first = $('ul#listticker li:first').html();
        $('ul#listticker li:first')
			.animate({ opacity: 0 }, speed)
			.fadeOut('slow', function () { $(this).remove(); });
        addLast(first);
    }

    function addLast(first) {
        last = '<li style="display:none">' + first + '</li>';
        $('ul#listticker').append(last)
        $('ul#listticker li:last')
			.animate({ opacity: 1 }, speed)
			.fadeIn('slow')
    }

    interval = setInterval(removeFirst, pause);
});
