$(function(){
	//write the empty ULs keep it valid!
	$('.discipline-container:eq(0)').prepend('<div class="mywork-pager margin-include pager-web"></div>');
});


var webcurslide = 0;
var bracurslide = 0;
var pricurslide = 0;

//array of associations between slides and reviews
var webassoc = new Array();
var braassoc = new Array();
var priassoc = new Array();

//starting slide for testimonials
var startslide = 0;

//this swaps the review when the project is changed
function webswapreview(curr,next,opts){	
	rotatereview('web', opts.nextSlide);
	webcurslide = opts.nextSlide;
}


//this defines the slide we're on after its slided for the review slide when changing between disciplines
function webafter(curr,next,opts){
	webcurslide = opts.currSlide;
}

//this actions the data stored by the after functions to set the review slide when discipline is changed
function discswapper(curr,next,opts){
	switch(opts.nextSlide){
	case 1:
		rotatereview('bra', bracurslide);
	break;
	case 2:
		rotatereview('pri', pricurslide);
	break;
	default:
		rotatereview('web', webcurslide);
	break;
	}
}

//this function rotates the review part
function rotatereview(discipline, slideclicked){
	switch(discipline){
	case 'bra':
		var assoc = braassoc[slideclicked];
	break;
	case 'pri':
		var assoc = priassoc[slideclicked];
	break;
	default:
		var assoc = webassoc[slideclicked];
	break;
	}
	if(assoc == undefined){var i = 0;}else{var i = assoc;}	
	$('.review-container').cycle(i);
}


//init all the cycles
$('.work-cycle').cycle({ 
    fx: 'scrollHorz',
    timeout: 0,
	cleartype: 1,
	containerResize: 1,
	before: discswapper
});


// Ucitavam XML parametar

$(function()
{
  $.ajax({
    type: "GET",
    url: "param.xml",
    dataType: "xml",
    success: parseXml
  });


function parseXml(xml)
{
 $(xml).find("Records").each(function()
{
  var efekt = $(this).find("SliderParam").text()
  var brzina = $(this).find("SliderSpeed").text()
  $('.discipline-web').cycle({ 
    fx: efekt,
	speed:  1000, // fast
	pager: '.pager-web',
	pagerAnchorBuilder: function(idx, slide) {idx=idx+1; return '<a href="#">' + idx + '</a>';}, 
    timeout: brzina,
	cleartype: 1,
	before: webswapreview,
	after: webafter
});
});
}
});

// Kraj ucitavanja


//on load
$(function(){
	//navigation for the 3 disciplines
	$('.disciplinenav li a').each(function(i){
		$(this).click(function() { 
			$('.work-cycle').cycle(i);
			$('.disciplinenav li a').removeClass('on');
			$(this).addClass('on');
			return false; 
		});
	});	
	
	
});


