// JavaScript Document

// Colorbox
$(document).ready(function(){
	$("a[rel='gallery']").colorbox({
	transition : "elastic",
	next : "naprej",
	previous : "nazaj",
	current : "Slika {current} od {total}"
	});
});

// Tab switch
function tabSelect(x)
{
	for (i=1;i<4;i++)
	{
		if (i != x) { 
			document.getElementById("t"+i).className=''
	    	$('#tab'+i).css("display", "none");
	} else {
			document.getElementById("t"+x).className='selected'
		    $('#tab'+x).css("display", "block");
		}
	}
}

$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'slideInRight', //Specify sets like: 'fold,fade,sliceDown'
		slices:4,
		animSpeed:1000,
		pauseTime:4000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:true, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.7, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});

//Kontrole za prikaz
var arr = new Array(28);
var hideAll = 0;

for (var i = 0; i < arr.length; i++) {
	arr[i] = 0;
}


$(document).ready(function(){

// Item hover
$(".item").hover(function(){
        $(this).find('.item-name').css('background-color', '#e2e2e2');
    },function(){
        $(this).find('.item-name').css('background-color', '');
});


$('#loc01').mouseover(function() { showOverlay(this, 'PIAGGIO CENTER LJUBLJANA, <br />Ljubljana', 220); });
$('#loc02').mouseover(function() { showOverlay(this, 'AC ORMOŽ, <br />Ormož', 110); });
$('#loc03').mouseover(function() { showOverlay(this, 'A SERVIS d.o.o. Pomurski <br />Avtocenter, Murska Sobota', 200); });
$('#loc04').mouseover(function() { showOverlay(this, 'AVTOSTIL d.o.o., <br />Rakek', 140); });
$('#loc05').mouseover(function() { showOverlay(this, 'AVTO MOTO HIŠA VOMBERGER, <br />Kranj', 224); });
$('#loc06').mouseover(function() { showOverlay(this, 'CAST d.o.o., <br />PE POLZELA', 116); });
$('#loc07').mouseover(function() { showOverlay(this, 'CAST d.o.o., <br />PE SLOVENJ GRADEC', 160); });
$('#loc08').mouseover(function() { showOverlay(this, 'JESIX d.o.o., <br />Slovenske Konjice', 140); });
$('#loc09').mouseover(function() { showOverlay(this, 'KMC, <br />Murska Sobota', 120); });
$('#loc10').mouseover(function() { showOverlay(this, 'KOLESARSKI CENTER GERM, <br />Slovenska Bistrica', 220); });
$('#loc11').mouseover(function() { showOverlay(this, 'PIAGGIO CENTER KOPER, <br />Koper', 200); });
$('#loc12').mouseover(function() { showOverlay(this, 'LIPNIK MST, <br />Žirovnica', 114); });
$('#loc13').mouseover(function() { showOverlay(this, 'MOTO CENTER BOŽIČ d.o.o., <br />Celje', 210); });
$('#loc14').mouseover(function() { showOverlay(this, 'MOTOCENTER PTUJ, <br />Ptuj', 164); });
$('#loc15').mouseover(function() { showOverlay(this, 'MOTO M, <br />Maribor', 96); });
$('#loc16').mouseover(function() { showOverlay(this, 'MOTO MARIO, <br />Velenje', 126); });
$('#loc17').mouseover(function() { showOverlay(this, 'MOTOMAXX, <br />Izola', 120); });
$('#loc18').mouseover(function() { showOverlay(this, 'MOTOMEHANIKA HERVATIN, <br />Kromberk, Nova Gorica', 210); });
$('#loc19').mouseover(function() { showOverlay(this, 'LANGUS MOTOCENTER, <br />Podnart', 186); });
$('#loc20').mouseover(function() { showOverlay(this, 'MOTOCENTER CELJE, <br />Celje', 170); });
$('#loc21').mouseover(function() { showOverlay(this, 'MOTOR JET d.o.o., <br />Maribor', 150); });
$('#loc22').mouseover(function() { showOverlay(this, 'MOTOVOGAL, <br />Maribor', 124); });
$('#loc23').mouseover(function() { showOverlay(this, 'PETOVIA AVTO Trgovina in <br />storitve d.o.o., Maribor', 200); });
$('#loc24').mouseover(function() { showOverlay(this, 'PIRKER JANEZ s.p., <br />Ribnica', 156); });
$('#loc25').mouseover(function() { showOverlay(this, 'SERVISNO PRODAJNI CENTER LUČKA, <br />Ljubljana', 274); });
$('#loc26').mouseover(function() { showOverlay(this, 'SMOLE d.o.o., <br />Novo Mesto', 126); });
$('#loc27').mouseover(function() { showOverlay(this, 'TIM mg d.o.o., <br />Ljubljana', 126); });
$('#loc28').mouseover(function() { showOverlay(this, 'TRGOMOTO d.o.o., <br />Krško', 160); });

$(".location").mouseover(overBubble);
$(".location").mouseout(outBubble);
$(".location").mouseout(hideOverlay);
$(".location").click(clickBubble);
$("#hideAll").click(clickBubble);
updateButtons();
});

function showOverlay(obj, text, width) {
	var x = $('#'+obj.id).css('left');
	var y = $('#'+obj.id).css('top');
	
	x = Number(x.split("px")[0]);
	y = Number(y.split("px")[0]);
	
	$("#loc-dealer-name").html(text);
	$("#loc-dealer-name").css({'left': (x - Math.round(width/2) + 13)+'px', 'top': (y - 50)+'px', 'width' : width+'px', 'display' : 'block'});
}

function hideOverlay() {
	$("#loc-dealer-name").css('display', 'none');
}

function clickBubble() {
	var id = $(this).attr('id');
	if (id != 'hideAll') {
		id = id.substring(3,5);
		var st = Number(id)-1;
		
		arr[st] = (arr[st] == 0 ? 1 : 0);
		hideAll = 1;
	} else {
		resetAll();
	}
	checkSelected();
	showHide();
	updateButtons();
}

function checkSelected() {
	var s = false;
	for (var i = 0; i < arr.length; i++) {
		s = s | (arr[i] == 1);
	}
	
	if (!s)
		hideAll = 0;
}

function overBubble() {
	var id = $(this).attr('id');
	if (id != 'hideAll') {
		id = id.substring(3,5);
		var st = Number(id)-1;
		
		if (arr[st] != 1) {
			$(this).css('background-position', '0px -26px');
		}
	} else {
		if (hideAll == 1) {
			$(this).css('background-position', '0px -26px');
		}
	}
}

function outBubble() {
	var id = $(this).attr('id');
	if (id != 'hideAll') {
		id = id.substring(3,5);
		var st = Number(id)-1;
		
		if (arr[st] != 1) {
			$(this).css('background-position', '');
		}
	} else {
		if (hideAll == 1) {
			$(this).css('background-position', '');
		}
	}
}

function resetAll() {
	hideAll = 0;
	for (var i = 0; i < arr.length; i++) {
		arr[i] = 0;
	}
}

function showHide() {
	for (var i = 0; i < arr.length; i++) {
		var nText = (i+1 < 10 ? "0"+(i+1) : ""+(i+1));
		
		if (hideAll == 1) {
			if (arr[i] == 0) {
				$('#dealer'+nText).removeClass('dselected');
				$('#dealer'+nText).css('display', 'none');
			} else {
				$('#dealer'+nText).addClass('dselected');
				$('#dealer'+nText).css('display', 'block');
			}
		} else {
			$('#dealer'+nText).removeClass('dselected');
			$('#dealer'+nText).css('display', 'block');
		}
	}
}

function updateButtons() {
	for (var i = 0; i < arr.length; i++) {
		var nText = (i+1 < 10 ? "0"+(i+1) : ""+(i+1));
		
		if (hideAll == 1) {
			$('#hideAll').css('display', 'block');
			if (arr[i] == 0) {
				$('#loc'+nText).css('background-position', '');
			} else {
				$('#loc'+nText).css('background-position', '0px -52px');
			}
		} else {
			$('#hideAll').css('display', 'none');
			$('#loc'+nText).css('background-position', '');
		}
	}
}
