/* 
NIJE STANDARDNI DIO CODA

Fumkcija preloader učitava slike prije klika kako se ne bi stvorila rupa
Funkcija izb_klik klikom na element izbornka mijenja stil sa m1 down na m1 down2

 */
 
function preloader(){
slika1= new Image();
slika1.src="img/izb_back_4.jpg";
}

function izb_klik(bla){
	var bla='izb'+bla;
	document.getElementById('izb1').className='m1 down';
	document.getElementById('izb2').className='m1 down';
	document.getElementById('izb3').className='m1 down';
	document.getElementById('izb4').className='m1 down';
	document.getElementById('izb5').className='m1 down';
	document.getElementById(bla).className='m1 down2';	
}

/* ================================================================ 
This copyright notice must be untouched at all times.
Copyright (c) 2009 Stu Nicholls - stunicholls.com - all rights reserved.
=================================================================== */
$(document).ready(function(){
cur = 1;
button = 1;
images = 3;
width = 580;

$('#p1').animate({"left": "0px"}, 400, "swing");
$('#b1').css("backgroundPosition", "left bottom")
$('#b1 b').css("color","#fff");
$('#loading').css("display","none");


$("#next").click(function() {
		button = cur;
		cur++
	if (cur == (images+1) ) {cur = 1}
animateLeft(cur,button)
});

$("#prev").click(function() {
		button = cur;
		cur--
	if (cur == 0 ) {cur = images}
animateRight(cur,button)
});

$("#buttons div").click(function() {
	button=cur;
	clickButton = $(this).attr('id');
	cur = parseInt(clickButton.slice(1));
	if (cur > button) {animateLeft(cur,button)}
	if (cur < button) {animateRight(cur,button)}
});

$("#buttons div b").mouseover(function() {
	if (($(this).css("color")) == "#16a" || ($(this).css("color")) == "rgb(17, 102, 170)") {$(this).css("color","#000");}
});

$("#buttons div b").mouseout(function() {
	if (($(this).css("color")) == "#000" || ($(this).css("color")) == "rgb(0, 0, 0)") {$(this).css("color","#16a");}
});

function animateLeft(cur,button) {
	$('#p'+cur).css("left",width +"px");
	$('#p'+cur).animate({"left": "0px"}, 400, "swing");
	$('#p'+button).animate({"left": -width+"px"}, 400, "swing");
	setbutton()
}

function animateRight(cur,button) {
	$('#p'+cur).css("left",-width+"px");
	$('#p'+cur).animate({"left": "0px"}, 400, "swing");
	$('#p'+button).animate({"left": width+"px"}, 400, "swing");
	setbutton()
}

function setbutton () {
	$('#b'+button).css("backgroundPosition", "left top")
	$('#b'+button+' b').css("color","#16a");
	$('#b'+cur).css("backgroundPosition", "left bottom")
	$('#b'+cur+' b').css("color","#fff");
}


$('ul#nav ul').hide();
$('ul#nav li:has(ul)').each(function(i) {
$(this).children().slideUp(400);
});



$('li.m1:has(ul)').click(function(event){
		if (this == event.target) {
		current = this;
		$('ul#nav li:has(ul)').each(function(i) {
		if (this != current) {$(this).children().slideUp(400);}
		});
		$(this).children("ul:eq(0)").slideToggle(400);


		}
	});

$('li.m2:has(ul)').click(function(event){
		if (this == event.target) {
		current = this;
		$('li.p2:has(ul)').each(function(i) {
		if (this != current) {$(this).children().slideUp(400);}
		});
		$('li.p3:has(ul)').each(function(i) {
		if (this != current) {$(this).children().slideUp(400);}
		});
		$(this).children("ul:eq(0)").slideToggle(400); 


		}
	});




});


