/*
 * Build by: Vojtech Srutek - 9-10-2010
 * Copyright: OTYS Recruiting Technology
 *
 * Useage: JQueryAccordion('unique parent element pointer','array of hover handles', default closed width /optional/, height measurring /optional 'autoHeight'(default) || 'styledHeight'/, default preopened slide /zero-indexed,optional, random if not set/);
 *
 * Change log:
 * -------------------------
 * 
 */
 
function JQueryAccordion(parentElem,handleClass,autoHeight,normalWidth,openedSlide) {
$(document).ready(function(){
$(parentElem+' > *:not('+handleClass+')').css('position', 'absolute');

if(autoHeight != "styledHeight"){
highestSlide = 0;

$(parentElem+' > *').each(function(c){
if( $(parentElem+' > *').eq(c).outerHeight() > highestSlide ){
highestSlide = $(parentElem+' > *').eq(c).outerHeight();
}
});

parentCss = {
'position' : 'relative',
'overflow' : 'hidden',
'height' : highestSlide
}

}

else{
parentCss = {
'position' : 'relative',
'overflow' : 'hidden'
}
}
$(parentElem).css(parentCss);
extendedWidth = $(parentElem+' > *:not('+handleClass+')').eq(0).outerWidth();
if(normalWidth == null || normalWidth == 'auto'){
normalWidth = ($(parentElem).width() - $(parentElem+' > *:not('+handleClass+')').eq(0).outerWidth()) / ($(parentElem+' > *:not('+handleClass+')').length - 1);
}
if(openedSlide == null){
openedSlide = Math.floor($(parentElem+' > *:not('+handleClass+')').length*Math.random());
}
$(parentElem+' > *:not('+handleClass+')').eq(openedSlide).addClass('activated');
$(handleClass).eq(openedSlide).addClass('activated');
	$(parentElem+' > *:not('+handleClass+')').each(function(a){
		if (a <= openedSlide) {
		compCss = normalWidth * a;
			$(parentElem+' > *:not('+handleClass+')').eq(a).css('left', compCss);
		} else {
		compCss = (normalWidth * a) + ($(parentElem+' > *:not('+handleClass+')').eq(0).outerWidth() - normalWidth);
			$(parentElem+' > *:not('+handleClass+')').eq(a).css('left', compCss);
		}
	});
	
	$(handleClass).each(function(i, hand){
		$(hand).hover(function(){
		$(parentElem+' *').removeClass('activated');
		$(parentElem+' > *:not('+handleClass+')').eq(i).addClass('activated');
		$(handleClass).eq(i).addClass('activated');
		if(i > openedSlide){
		star_t = openedSlide+1;
		en_d = i+1;
		te = '-='+($(parentElem+' > *:not('+handleClass+')').eq(0).outerWidth() - normalWidth);
    $(parentElem+' > *:not('+handleClass+')').slice(star_t,en_d).animate({
    left:te
    });
    openedSlide=i;
    }
    else if(i < openedSlide){
    star_t = i+1;
		en_d = openedSlide+1;
		te = '+='+($(parentElem+' > *:not('+handleClass+')').eq(0).outerWidth() - normalWidth);
    $(parentElem+' > *:not('+handleClass+')').slice(star_t,en_d).animate({
    left:te
    });
    openedSlide=i;
    }
		});
	});
});
}

