/* selectPage - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*
    combobox-szal megvalositott oldal navigacio

    selectElement: id vagy referencia
*/
function selectPage(selectElement) {
    if($(selectElement).value != "#"){
        window.location = $(selectElement).value;
    }
}
/* selectPage - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */


/* selectBox - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function selectBox(selectElement) {
    jQuery('div.showHideBox').css('display', 'none');
    jQuery('#' + selectElement.value).css('display', 'block');
    
}
/* selectBox - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */


function setContentLayer( element, tabNum ) {
    var selectBox = $(element);
    var selectedOptionValue = $(selectBox.options[selectBox.selectedIndex]).value;
    var container = selectBox.up("div.TabbedPanelsContent");
    
    var contentId = "detailsCont_" + tabNum + "_" + selectedOptionValue; 
    var allContents = $(container).select("div.innerDetailsCont");
    
    allContents.each(function( content ) {
        $(content).hide();
        if ( content.id == contentId ) $(content).show();
    });
}

function setFootNote(num) {
    if ( num == 3 ) {
        if ($("footNote")) $("footNote").show();
    } else {
        if ($("footNote")) $("footNote").hide();
    }
    
}

/* yearCarousel - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function initYearCarousel(){
    (function($){
    	$(document).ready(function(){
            function setAllYearSlider (yearList) {
            	jQuery.each(yearList, function(index, element) {
            		$(element).hover(
            			function () {
            				$(this).addClass('hover');
            			},
            			function () {
            				$(this).removeClass('hover');
            			}
            		);
            
            		$(element).click(
            			function (e) {
            				if ($(element).hasClass('active') || $(element).is(':animated')) {
            					return false;
            				}
            				else {
            					allYearSliderMove(yearList, index);
            				}
                            e.preventDefault();
            			}
            		);
            	});
            }
            
            function allYearSliderMove(yearList, toIndex){
            	for (var i = 0; i < yearList.length; i++) {
            		if ($(yearList[i]).hasClass('active')) {
            			var activeYear = i;
            			break;
            		}
            	}
            	
            	var slideFrom = ($('div.selectorSquare').position().left);
            	if (toIndex > activeYear) {
            		$('div.selectorSquare').animate({
            			"left": "+=" + (toIndex - activeYear) * 34 + "px"
            		}, "slow");
            	}
            	else {
            		$('div.selectorSquare').animate({
            			"left": "-=" + (activeYear - toIndex) * 34 + "px"
            		}, "slow");
            	}
            	$(yearList[activeYear]).removeClass('active');
            	$(yearList[toIndex]).addClass('active');
            
            	setYearCarouselMove(toIndex, yearList);
            }
            
            function setYearCarousel(yearList) {
            	$('img.scrollLeft').click(
            		function (e) {
            			setYearCarouselMove('left', yearList);
                        e.preventDefault();
            		}
            	);
            	
            	$('img.scrollRight').click(
            		function (e) {
            			setYearCarouselMove('right', yearList);
                        e.preventDefault();
            		}
            	);
            
            	jQuery.each($('img.yearLink'), function(index, element) {
            		$(element).click(
            			function (e) {
            				selectYearFromCarouselByClick(index, yearList);
                            e.preventDefault();
            			}
            		);
            	});
            }
            
            var selectedIndex = 0;
            
            function selectYearFromCarouselByClick(index, yearList) {
            	if (index == selectedIndex) {
            		return false;
            	}
            	setYearCarouselMove(index, yearList);
            	allYearSliderMove (yearList, index);
            }
            
            function setYearCarouselMove(whereTo, yearList) {
            	var yearCount = 15; //16
            	if (whereTo == 'left' && selectedIndex != 0) {
            		$('div.innerScrollContainer').animate({'left': '+=87px'}, 'slow');
            		imageCrossFade (selectedIndex, selectedIndex - 1);
            		selectedIndex--;
            		allYearSliderMove (yearList, selectedIndex);
            	}
            	else if (whereTo == 'right' && selectedIndex != yearCount) {
            		$(".innerScrollContainer").animate({'left': '-=87px'}, 'slow');
            		imageCrossFade (selectedIndex, selectedIndex + 1); 
            		selectedIndex++;
            		allYearSliderMove (yearList, selectedIndex);
            	}
            	else {
            		if (selectedIndex == whereTo) {
            			return false;
            		}
            		else {
            			if (whereTo < selectedIndex && whereTo >= 0) {
            				$('div.innerScrollContainer').animate({'left': '+=' + 87 * (selectedIndex - whereTo) + 'px'}, 'slow');
            				imageCrossFade (selectedIndex, whereTo);
            				selectedIndex = whereTo;
            			}
            			else if (whereTo > selectedIndex && whereTo <= yearCount) {
            				$('div.innerScrollContainer').animate({'left': '-=' + 87 * (whereTo - selectedIndex) + 'px'}, 'slow');
            				imageCrossFade (selectedIndex, whereTo);
            				selectedIndex = whereTo;
            			}
            		}
            	}
            	showYearBox(selectedIndex);
            }
            
            function imageCrossFade (fadeOutIndex, fadeInIndex) {
            	var scrollContainerElements = $('div.innerScrollContainer').children('div');
            	$(scrollContainerElements[fadeOutIndex]).children('img.seletedState').fadeOut(500);
            	$(scrollContainerElements[fadeInIndex]).children('img.seletedState').fadeIn(500);
            	$(scrollContainerElements[fadeOutIndex]).removeClass('selectedItem');
            	$(scrollContainerElements[fadeInIndex]).addClass('selectedItem');
            }
            
            function showYearBox(index) {
            	$('div.companyHistory_' + (1994 + index)).toggle();
                $('div.actualCompanyHistory').toggle();
            	$('div.actualCompanyHistory').removeClass('actualCompanyHistory');
            	$('div.companyHistory_' + (1994 + index)).addClass('actualCompanyHistory');
            }            
            
    		var yearList = $('div.allYearListing').children('ul').children('li');
    		setAllYearSlider(yearList);
    		setYearCarousel(yearList);
    	});
    })(jQuery);
}

/* yearCarousel - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
