function shuffle(array) {
    var tmp, current, top = array.length;

    if(top) while(--top) {
        current = Math.floor(Math.random() * (top + 1));
        tmp = array[current];
        array[current] = array[top];
        array[top] = tmp;
    }

    return array;
}


		
		var banner_szam = 18;            //Bannerek száma
        var bannerek = new Array();
        var akt_banner = 1;
        
        var j;
        for(var i=0;i<banner_szam;i++) {
        	j = i+1;
            bannerek[i]="#b"+(j);
        }
	//	alert(bannerek.toString());
		var socialMediaYLoc=null;        
        
		$(document).ready(function() {
           
		   /*socialMediaYLoc = parseInt($(".socialMediaMobile").css("top").substring(0,$(".socialMediaMobile").css("top").indexOf("px")))
			$(window).scroll(function () {
				var offset = socialMediaYLoc+$(document).scrollTop()+"px"; 
				$(".socialMediaMobile").animate({top:offset},{duration:500,queue:false});
			})*/
		   
			shuffle(bannerek);
			bannerek.unshift("#b19");
			$(bannerek[akt_banner]).fadeIn(1500);
			text_slide(Math.floor(Math.random()*5));
           
           function text_slide(type) {
           	 switch(type) {
                    case 1:
                        $('#cimke').html("<nobr>"+$(bannerek[akt_banner]).attr('alt')+"</nobr>");
                        $('#cimke').attr('style','margin-top:80px;margin-left:-'+$("#cimke").outerWidth()+'px;');
                        $('#cimke').animate({opacity:0.7},1);
                        $('#cimke').delay(2000).animate({"margin-left":"+="+$('#cimke').outerWidth()+"px"},1500).delay(6000).animate({"margin-left":"-="+$('#cimke').outerWidth()+"px"},1500,function(){});
                        $('#cimke2').html("<nobr>"+$(bannerek[akt_banner]).attr('title')+"</nobr>");
                        $('#cimke2').attr('style','margin-top:200px;margin-left:638px;');
                        $('#cimke2').delay(1000).animate({opacity:0.7},1);
                        $('#cimke2').delay(3000).animate({"margin-left":"-="+$('#cimke2').outerWidth()+"px"},1500).delay(5000).animate({"margin-left":"+="+$('#cimke2').outerWidth()+"px"},1500,function(){banner_csere()});
                        break;
                    case 2:
                        $('#cimke').html("<nobr>"+$(bannerek[akt_banner]).attr('alt')+"</nobr>");
                        $('#cimke').attr('style','margin-top:210px;margin-left:-'+$("#cimke").outerWidth()+'px;');
                        $('#cimke').animate({opacity:0.7},1);
                        $('#cimke').delay(2000).animate({"margin-left":"+="+$('#cimke').outerWidth()+"px"},1500).delay(6000).animate({"margin-left":"-="+$('#cimke').outerWidth()+"px"},1500,function(){});
                        $('#cimke2').html("<nobr>"+$(bannerek[akt_banner]).attr('title')+"</nobr>");
                        $('#cimke2').attr('style','margin-top:80px;margin-left:638px;');
                        $('#cimke2').delay(1000).animate({opacity:0.7},1);
                        $('#cimke2').delay(3000).animate({"margin-left":"-="+$('#cimke2').outerWidth()+"px"},1500).delay(5000).animate({"margin-left":"+="+$('#cimke2').outerWidth()+"px"},1500,function(){banner_csere()});
                        break;
                    case 3:
                        $('#cimke').html("<nobr>"+$(bannerek[akt_banner]).attr('alt')+"</nobr>");
                        $('#cimke').attr('style','margin-top:80px;margin-left:638px;');
                        $('#cimke').animate({opacity:0.7},1);
                        $('#cimke').delay(2000).animate({"margin-left":"-="+$('#cimke').outerWidth()+"px"},1500).delay(6000).animate({"margin-left":"+="+$('#cimke').outerWidth()+"px"},1500,function(){});
                        $('#cimke2').html("<nobr>"+$(bannerek[akt_banner]).attr('title')+"</nobr>");
                        $('#cimke2').attr('style','margin-top:200px;margin-left:-'+$("#cimke2").outerWidth()+'px;');
                        $('#cimke2').delay(1000).animate({opacity:0.7},1);
                        $('#cimke2').delay(3000).animate({"margin-left":"+="+$('#cimke2').outerWidth()+"px"},1500).delay(5000).animate({"margin-left":"-="+$('#cimke2').outerWidth()+"px"},1500,function(){banner_csere()});
                        break;
                    case 4:
                        $('#cimke').html("<nobr>"+$(bannerek[akt_banner]).attr('alt')+"</nobr>");
                        $('#cimke').attr('style','margin-top:210px;margin-left:638px;');
                        $('#cimke').animate({opacity:0.7},1);
                        $('#cimke').delay(2000).animate({"margin-left":"-="+$('#cimke').outerWidth()+"px"},1500).delay(6000).animate({"margin-left":"+="+$('#cimke').outerWidth()+"px"},1500,function(){});
                        $('#cimke2').html("<nobr>"+$(bannerek[akt_banner]).attr('title')+"</nobr>");
                        $('#cimke2').attr('style','margin-top:80px;margin-left:-'+$("#cimke2").outerWidth()+'px;');
                        $('#cimke2').delay(1000).animate({opacity:0.7},1);
                        $('#cimke2').delay(3000).animate({"margin-left":"+="+$('#cimke2').outerWidth()+"px"},1500).delay(5000).animate({"margin-left":"-="+$('#cimke2').outerWidth()+"px"},1500,function(){banner_csere()});
                        break;
                    case 5:
                        $('#cimke').html("<nobr>"+$(bannerek[akt_banner]).attr('alt')+"</nobr>");
                        $('#cimke').attr('style','margin-top:-'+$('#cimke').outerHeight()+'px;margin-left:'+(319-($('#cimke').outerWidth()/2))+'px;');
                        $('#cimke').animate({opacity:0.7},1);
                        $('#cimke').delay(2000).animate({"margin-top":"+="+$('#cimke').outerHeight()+"px"},1500).delay(6000).animate({"margin-top":"-="+$('#cimke').outerHeight()+"px"},1500,function(){});
                        $('#cimke2').html("<nobr>"+$(bannerek[akt_banner]).attr('title')+"</nobr>");
                        $('#cimke2').attr('style','margin-top:316px;margin-left:'+(319-($('#cimke2').outerWidth()/2))+'px;');
                        $('#cimke2').animate({opacity:0.7},1);
                        $('#cimke2').delay(3000).animate({"margin-top":"-="+$('#cimke2').outerHeight()+"px"},1500).delay(5000).animate({"margin-top":"+="+$('#cimke2').outerHeight()+"px"},1500,function(){banner_csere()});
                        break;
                    default:
                       $('#cimke').html("<nobr>"+$(bannerek[akt_banner]).attr('alt')+"</nobr>");
                        $('#cimke').attr('style','margin-top:316px;margin-left:'+(319-($('#cimke').outerWidth()/2))+'px;');
                        $('#cimke').animate({opacity:0.7},1);
                        $('#cimke').delay(2000).animate({"margin-top":"-="+$('#cimke').outerHeight()+"px"},1500).delay(6000).animate({"margin-top":"+="+$('#cimke').outerHeight()+"px"},1500,function(){});
           				$('#cimke2').html("<nobr>"+$(bannerek[akt_banner]).attr('title')+"</nobr>");
                        $('#cimke2').attr('style','margin-top:-'+$('#cimke2').outerHeight()+'px;margin-left:'+(319-($('#cimke2').outerWidth()/2))+'px;');
                        $('#cimke2').animate({opacity:0.7},1);
                        $('#cimke2').delay(3000).animate({"margin-top":"+="+$('#cimke2').outerHeight()+"px"},1500).delay(5000).animate({"margin-top":"-="+$('#cimke2').outerHeight()+"px"},1500,function(){banner_csere()});
                }
                
           } 
           function banner_csere() {
                $(bannerek[akt_banner]).fadeOut(1500);
                if(akt_banner == banner_szam-1){akt_banner = 0}
                $(bannerek[akt_banner+1]).fadeIn(1500);
                akt_banner++;
                text_slide(Math.floor(Math.random()*5));  
            }
            /* tartalomra ugrik
            if(!$('.container').hasClass('front')) {
            	$.scrollTo($('.contentCont'), 0);
            }
            */
        /*    $('a[rel*=scrollTo]').click(function() {
			    var $target = $(this.hash);
			    $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			    if ($target.length) {
			    	$.scrollTo($target, 400);
			    	return false;
			    }
			});
			
			$('.menuCont a.menu-3-link').click(function(){
				if($('.container').hasClass('front')) {
					$.scrollTo($('.contentCont'), 400);
				} else if ($('.container').hasClass('inside')) {
					window.location = CalcunConfig.basePath + '#bravogroup';
				}
				return false;	
			}); */
			
			$('.menuCont a.menu-38-link').click(function(){
				window.location = CalcunConfig.basePath + 'menu/a_vallalatcsoportrol/tulajdonosi_szerkezet';
				return false;
			});
			
			$('.menuCont a.menu-39-link').click(function(){
				window.location = CalcunConfig.basePath + 'menu/a_vallalatcsoportrol/tulajdonosi_szerkezet';
				return false;
			});
			
			$('.menuCont a.menu-40-link').click(function(){
				window.location = CalcunConfig.basePath + 'menu/a_vallalatcsoportrol/tulajdonosi_szerkezet';	
				return false;
			});
			
			/*
			if(window.location.hash == '#bravogroup') {
				$(window).load(function(){
					$.scrollTo($('.contentCont'), 400);
				});
			} else if(window.location.hash.length > 1) {
				$(window).load(function(){
					$.scrollTo($('.InternalApp_position-' + window.location.hash.substring(1)), 0);
				});
			}
			*/
			$('.menuCont li li').hover(function(){ 
						if($('.left', this).offset().top+$('.left', this).height()>$(window).height())
							{
								var szam = $(window).height() - $('.left', this).height() - 10; 
								if(szam<10) {
									szam=10;
								}
								$('.left', this).offset({top: szam});
							}
					});
			
            
            
        });
$(function() {
	$('.socialMediaImg').tipTip();
	
	
	$flashMessage = $('.calcun-error, .calcun-info');
	if($flashMessage.length) {
		var messages = '';
		var sep = '';
		$flashMessage.each(function(){
			messages += sep + $(this).text();	
			sep = '<br />';
		});
		$flashMessage.first().html(messages);
		$flashMessage.not(':first').remove();
		Calcun.showFlashMessage($flashMessage.html());
		$flashMessage.remove();
	}
	
	$('.formToValidate').validate();
})

var Calcun = {
		
		sessionId : '',
		
		showFlashMessage: function(message) {
			var $flashMessage = $('<div class="flash-message">' + message + '</div>');
			$('body').prepend($flashMessage);
			var wWidth = $(window).width();
			var wHeight = $(window).height();
			var wrap = '<div id="flashMessage"></div>';
			$flashMessage.wrap(wrap);
			var $container = $('#flashMessage');
			if($container.width() > 500) {
				$container.width(500);
			}
			$container.css({
				position: 'fixed',
				left: parseInt((wWidth - $container.outerWidth())/2),
				top: parseInt((wHeight - $container.outerHeight())/2 - 60),
				'z-index': 3999
			});
			$close = $('<a class="close" href="#">X</a>').click(function(){
				$container.remove();
				$shadow.fadeOut(function(){
					$(this).remove();
				});	
				return false;
			});
			var $shadow = $('<div id="flashMessageShadow">').css({
				position: 'fixed',
				top: 0,
				left: 0,
				width: '100%',
				height: '100%',
				opacity: 0.6,
				'z-index': 3998
			}).click(function() {
				$close.click();
			});
			
			
			$container
				.before($shadow)
				.append('<div class="info-foot"></div>');
				;
			$container.prepend($close);
		},
	
		resetAlertButtons: function() {
			$.calcunalerts.okButton = 'OK';
			$.calcunalerts.cancelButton = 'cancel';
		}
		
		
		
	}
