/*

	Global page javascript
	-----------------------

	@file 		page.js
	@version 	1.0.0b
	@date 		2009-12-27 12:28:48 +0100 (Sun, 27 Dec 2009)
	@author 	Aleksandar Markovic <mikikg@gmail.com>

	Copyright (c) 2009 Netsector <http://www.netsector.biz>

*/

$(document).ready(function(){

	//=========== gallery ===========
	if ($("#gallery").length > 0) {
		$("#gal_thumbs a").overlay({
		    target: "#gallery",
		 	fadeInSpeed: "100",
		 	expose: "#f1f1f1"

		}).gallery({
		    speed: 300,
		    imgId: "gal_img",
		    next: ".gal_next",
		    prev: ".gal_prev",
		    progress: ".gal_progress",
		    info: ".gal_info",
		    disabledClass: "gal_disabled",
		    template: "<strong>${title}</strong> <span>Slika ${index} od ${total}</span>"

		});

	}

	//============ scrollable ===========
	if ($("#idscrollable").length > 0) {
		$(".scrollable").scrollable({
			size: 1,
			loop: 0,
			speed: 400,
			clickable: false
		// use mousewheel plugin
		}).mousewheel().autoscroll({autoplay: false}).navigator(".navi");
	}

	//============ scrollable ===========
	if ($("#idscrollable2").length > 0) {
		$(".scrollable2").scrollable({
			size: 1,
			loop: 0,
			speed: 400,
			clickable: false
		// use mousewheel plugin
		}).mousewheel().autoscroll({autoplay: false}).navigator(".navi2");
	}

	//=========== rotator ===========
	if ($("#rotator1").length > 0) {
		$("#rotator1").rotator({ms:6000});
	}
	if ($("#rotator2").length > 0) {
		$("#rotator2").rotator({ms:6000});
	}
	if ($("#rotator3").length > 0) {
		$("#rotator3").rotator({ms:6000});
	}
	if ($("#rotator4").length > 0) {
		$("#rotator4").rotator({ms:6000});
	}
	if ($("#rotator5").length > 0) {
		$("#rotator5").rotator({ms:6000});
	}
	if ($("#rotator6").length > 0) {
		$("#rotator6").rotator({ms:6000});
	}
	if ($("#rotator7").length > 0) {
		$("#rotator7").rotator({ms:6000});
	}
	if ($("#rotator8").length > 0) {
		$("#rotator8").rotator({ms:6000});
	}
	if ($("#rotator9").length > 0) {
		$("#rotator9").rotator({ms:6000});
	}


	// ============ ticker =============
	var ticker_still_time = 3000;
	var ticker_animation_time = 5500;
	var ticker_items_count = 0;
	var ticker_curr_pos = 0;
	var ticker_mem = [];

	function ticker_anim() {

		ticker_swap();

		var tblock_with = 1050 - $('#ticker_block').width();

		$("#ticker_mask").animate({
			width: tblock_with + "px",
		}, ticker_animation_time, "swing", function() {
    		// next scene
			setTimeout(function() {
				$("#ticker_block").fadeOut(
					'slow', function() {
						//reset
						ticker_rst();
					}
				);
			}, ticker_still_time);
  		});
	}

	function ticker_rst() {
		$("#ticker_mask").css('width', '960px');
		$('#ticker_block').fadeIn(
			'slow', function() {
				//start again
				//return;
				ticker_anim();
			}
		);
	}

	function ticker_swap() {
		if ((ticker_curr_pos + 1) == ticker_items_count) {
			$('#ticker_text').text(ticker_mem[ticker_curr_pos][1]).attr('href',ticker_mem[ticker_curr_pos][0]);
			ticker_curr_pos = 0;
		} else {
			$('#ticker_text').text(ticker_mem[ticker_curr_pos][1]).attr('href',ticker_mem[ticker_curr_pos][0]);
			ticker_curr_pos ++;
		}
	}


	$('.ticker_memory').each(function(idx) {
    	ticker_mem[ticker_items_count] = [$(this).attr('title'), $(this).text()];
    	ticker_items_count++;
  	});

	//alert($.dump(ticker_mem));

	if ($(".ticker_data").length > 0) {
		ticker_anim();
	}




});

