$(document).ready(function(){
   
   /* 
   resizeWrapper();
    
    $(window).resize(function(){
       
        resizeWrapper();
        
    });
    */
    
    
    /*
    $(document).mousemove(function(e){
        
        var offset = $("#container").offset();
        $("#debug").val(e.pageX+'('+offset.top+') - '+e.pageY+'('+offset.left+')');
    });
    */
    
    
    
    var url = location.href;
    var t = new Array();
    t = url.split('.hu/');    
    //alert(t[1]);
    
    var page = 'menu-0';
    
    switch(t[1]) {
        
        case 'fooldal':
            page = 'menu-0';
            break;
            
        case 'kompetenciak':        
            page = 'menu-1';
            break;
            
        case 'munkaink':
            page = 'menu-2';
            break;
            
        case 'barataink':
            page = 'menu-3';
            break;
            
        case 'karrier':
            page = 'menu-4';
            break;
            
        case 'kapcsolat':
            page = 'menu-5';
            break;        
        
        
        case 'teszt':
            page = 'menu-10';
            break;
            
        case 'teszt2':
            page = 'menu-11';
            break;
        
        default:
            page = 'menu-0';
            break;
    }
    
    loadContent(page, '');
    
});

function resizeWrapper() {
    
    var s_height = $(document).height();
    var s_width = $(document).width();
    
    $('#header').html(s_width+' x '+s_height+' - '+$('#wrapper').height());
    
    
    $('#wrapper').height(s_height-40);    
}

function removeStyleAttribute(element, name) {
    
    if(jQuery.browser.msie)
				element.style.removeAttribute(name);

    return true;
}

function loadContent(pagetitle, params) {
	
    if(pagetitle == 'menu-2') { //munkainkhoz atadjuk
        params += '&pos='+$('#container').offset().top;         
    } 


    changeMenu(pagetitle);
    
   
    
   // getDataContent(pagetitle, params);
    
    
   	$('#fader .jScrollPaneDrag').fadeOut('slow', function() {
   	    removeStyleAttribute(this, 'filter');
   	});    
    $('#fader #container').fadeOut('slow', function() {
        removeStyleAttribute(this, 'filter');
    });
    $('#fader').fadeOut('slow', function() { 
        removeStyleAttribute(this, 'filter');
		getDataContent(pagetitle, params);                
    });

    //setTimeout('showContent()', 450);


/*
    $('#fader .jScrollPaneDrag').show('fast', function() {
        removeStyleAttribute(this, 'filter');
    });
    $('#fader #container').show('fast', function() {
        removeStyleAttribute(this, 'filter');
    });
    $('#fader').fadeIn('slow', function() {            
        removeStyleAttribute(this, 'filter');
    });
 */
    
    
    //return true;
    
}


function showContent() {
    $('#fader').fadeIn('slow', function() {            
        //removeStyleAttribute(this, 'filter');
    });
    //$('#fader').show();
    //alert('showcontent');
    /*
    $('#fader .jScrollPaneDrag').fadeIn('slow', function() {
        removeStyleAttribute(this, 'filter');
    });
    $('#fader #container').fadeIn('slow', function() {
        removeStyleAttribute(this, 'filter');
    });
    $('#fader').fadeIn('slow', function() {            
        removeStyleAttribute(this, 'filter');
    });
    */
    
}


function getDataContent(pagetitle, params) {
	
	var param = "p="+pagetitle+params;
	
	$.ajax({
	      type: "POST",
	      url: 'ajax/loadcontent.php',
	      data: param,
	      async: true,
	      success: function(data) {
	            
                
                $('#container').html(data);                
                initPane('container');
                $('#container')[0].scrollTo(0);

                initContent();       
                initAllVideo();
                 
                $('#fader .jScrollPaneDrag').fadeIn('slow', function() {
                    removeStyleAttribute(this, 'filter');
                }); 
                $('#fader #container').fadeIn('slow', function() {
                    removeStyleAttribute(this, 'filter');
                });
                $('#fader').fadeIn('slow', function() {            
                    removeStyleAttribute(this, 'filter');
                });
                
               
                                        
	      }
	});
	showContent();
	
}


function initPane(id, stay_scroll) {
     
     $('#'+id).jScrollPane(
                {   
                    scrollbarWidth: 18,
                    dragMinHeight: 86,
                    dragMaxHeight: 86
                }
     );
     
     setTimeout('scrollToPos()', 100);
     
    return true;
} 




function scrollToPos() {
     
    var pos = $("#scrollto").val();
    if(pos != undefined) {
        var to = 14 - pos;        
        $('#container')[0].scrollTo(to);
        $("#debug").val('scrollozás... '+to);
            
    }
    return true;
     
}



function changeMenu(id) {
    $(".menuitems").removeClass('selected');
    $("#kisnyil").removeClass('kisnyil_selected');
    
    
    /*
    var i = 0;
    var name = '';
    for(i; i <= 5; i++) {
        name = 'menu-'+i;
        if(name == id) continue;
        $("#rightside").removeClass('rightside_menu-'+i);
        
    }*/
    //$("#rightside").attr('class', '');

    //$("#rightside").addClass('rightside_'+id);
    
    $("#right_bg").attr('class', '');
    $("#right_bg").addClass('right_'+id);

    
    if(id == 'menu-0') {
        $("#kisnyil").addClass('kisnyil_selected');
    } else {
        $("#item_"+id).addClass('selected');
    }
    
    
    
    
    
}


function initContent() {
    
    resizeImages();
    initColorbox();
    
}


function initColorbox() {
    
        /*
    $('#container .colorbox_a').fancybox({
            'type'          :   'image',
            'transitionIn'	:	'elastic',
    		'transitionOut'	:	'elastic',
    		'speedIn'		:	600, 
    		'speedOut'		:	200,
            'titleShow'     :   'true',
            'showCloseButton':  'true',            
            'autoDimensions':   'true',
            'enableEscapeButton': 'true'
            
    		
        }                
    ); */
    /*
    $(".ikontent_html").fancybox({
            'type'          :   'iframe',
            'transitionIn'	:	'elastic',
    		'transitionOut'	:	'elastic',
    		'speedIn'		:	600, 
    		'speedOut'		:	200,
            'titleShow'     :   'true',
            'showCloseButton':  'true',
            'scrolling'     :   'auto',
            'autoDimensions':   'true',            
            'width'         :   510,
            'height'        :   490,
            'enableEscapeButton': 'true',
            'onComplete' : function() { initAllVideo(); }
        }                        
    ); 
    */
    
    $(".ikontent_html").fancybox({  
            //'type'          :   'iframe',
            'transitionIn'	:	'elastic',
    		'transitionOut'	:	'elastic',
    		'speedIn'		:	600, 
    		'speedOut'		:	200,
            'titleShow'     :   'true',
            'showCloseButton':  'true',
            'scrolling'     :   'auto',
            'autoDimensions':   'true',
            'enableEscapeButton': 'true',
            onComplete : function() {
                initAllVideo();
            } 
           
        }                        
    );
    
    
    
}


function initAllVideo() {
    
    $('#box_wrapper .videosname').each(function() {
        
        //alert($(this).val());
        initVideoPlayer($(this).val());
        
        
    });
    
    $('#fancybox-content-holder').bind('resize',function(){
		height = $('#fancybox-content-holder').height()+25;
		$('#fancybox-wrap').height(height);
	});

    
    
    return true;
    
}


 /* kep atmeretezese */
function resizeImages() {
    
    var maxwidth = 350;
    
   	
    
	$('#container img:not(.title)').each(function() { 	
		
        
        
		if(this.width > maxwidth) {
			
            
    			var ratio =  maxwidth / this.width;
    			//alert(maxwidth+' - '+this.width+'    '+ratio);
    			this.width = maxwidth;
    			var a = this.height * ratio;
    			this.height = a; 
           
			
		}
	});  
    
    return true;
}

/*
function resizeContentWindow() {    
    var max = 605;  
    var height = $("#container").height();    
    if(height > 605) $("#container").height(max);    
    return true;    
}
*/



function openCloseDiv(id) {
	
    
    
    
	if( $('#'+id).hasClass('active') ) {
	
        $('#'+id).slideUp('slow', function() {
            // Animation complete.
            initPane('container');
          });
        $('#'+id).removeClass('active')
        
        
    } else {
        $('.data').slideUp('slow', function() {});
        $('.data').removeClass('active');
        
        $('#'+id).slideDown('slow', function() {
            // Animation complete.
            initPane('container');
            
            //ha az utolso elem a rákattintott, akkor teljesen legördíti
            //isLastCompany(id);
            getdivdata(id);
          });
        $('#'+id).addClass('active')
       	
    }

}


function closeDiv(id) {
    $('#'+id).removeClass('active');
    $('#'+id).hide(); 
}


function getdivdata(id) {
    
    var height = $('#'+id).height();
    var offset = $('#'+id).offset();
    
    var bottom = offset.top + height;
    
    
    var heightc = $('.jScrollPaneContainer').height();
    var offsetc = $('.jScrollPaneContainer').offset();
    
    var bottomc = offsetc.top + heightc;
    
    //alert(bottom+' - '+bottomc);
    //alert(id+' - height: '+height+' - offset.top'+offset.top);
    if(bottom > bottomc) {
        
        var diff = bottom - bottomc; //ennyivel kell lejjebb scrollozni
        $('#container')[0].scrollBy(diff + 30);       
        
    }
    
}

function isLastCompany(id) {
    
    var last;
    $('.data').each(function(){       
        last = this;        
    });
    if(id == last.id) {
        $('#container')[0].scrollTo($('#container').data('jScrollPaneMaxScroll'));        
    }    
    
}


function chromeSpecificInit() {
    
    if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
    {
         var chromeCss = document.createElement("link");
    
         chromeCss.rel = "stylesheet";
         chromeCss.href = "css/ChromeStyle.css";
        
         document.getElementsByTagName("head")[0].appendChild(chromeCss);
        
    }

}





function initVideoPlayer(file) {
    
   // alert('initVideoPlayer('+file+')');
    var flashvars = {};
			
			//////////////////////////////////////////////////////////////////////////////////////////////////////
			// CUSTUMIZABLE PARAMETERS ///////////////////////////////////////////////////////////////////////
			//////////////////////////////////////////////////////////////////////////////////////////////////////
			
			// video width
			var stageW = 500;
			
			// video height		NOTE: you should include the control bar height
			var stageH = 350;
			
			///////////////////////////////////////////////////////////////////////
			// PATHS //////////////////////////////////////////////////////////////
			///////////////////////////////////////////////////////////////////////

			// image path
			flashvars.imagePath			= "images/logo.png";

			// video path
			// flashvars.videoPath 		= "upload/media/metallica_-_disappear.flv";
            flashvars.videoPath 		= "../../upload/media/"+file+'.flv';

			// video title
			flashvars.title 			= "";

			// video description
			flashvars.description 		= "";
						
			///////////////////////////////////////////////////////////////////////
			// VIEW CONTROLS ////////////////////////////////////////////////////
			///////////////////////////////////////////////////////////////////////

			// view information button 		 NOTE: this will display the title and description of the video
			flashvars.viewInfoButton 		=	"false";

			// view fullscreen button		( true / false )
			flashvars.viewFullscreenButton 	=	"true";

			// view scale button			( true / false )
			flashvars.viewScaleButton 		=	"true";

			// view volume controls			( true / false )
			flashvars.viewVolumeControls 	=	"true";

			// view video time				( true / false )
			flashvars.viewTime				=	"true";

			// view big middle button		( true / false )
			flashvars.viewBigPlayButton 	=	"true";
			
			// view right click menu		( true / false )
			flashvars.viewRightClickMenu 	=	"false";
			
			////////////////////////////////////////////////////////////////////////
			// MOUSE FUNCTIONS //////////////////////////////////////////////////
			////////////////////////////////////////////////////////////////////////

			// mouse hide							( true / false )
			flashvars.mouseHide				=	"true";

			// mouse hide after # (seconds)		NOTE : Must be a hole number !
			flashvars.mouseHideTime			=	"3";

			// double click for toggle size view	( true / false )
			flashvars.doubleClick			=	"false";

			// click the video for play/pause		( true / false )
			flashvars.oneClick				=	"true";
			
			////////////////////////////////////////////////////////////////////////
			// KEYBOARD FUNCTIONS ///////////////////////////////////////////////
			////////////////////////////////////////////////////////////////////////

			// play/pause on SPACE key 		( true / false )
			flashvars.spaceKey				=	"true";
			
			////////////////////////////////////////////////////////////////////////
			// VIDEO FUNCTIONS ///////////////////////////////////////////////////
			////////////////////////////////////////////////////////////////////////

			// video loop				( true / false )
			flashvars.videoLoop			=	"false";

			// video auto play			( true / false )
			flashvars.videoAutoPlay		=	"false";
			
			// video buffer time		( seconds )
			flashvars.videoBufferTime	=	"0.1";
			
			// timeline interval	
			flashvars.tlInterval		=	"100000";

			// sound volume at start 		NOTE :	1=Max	0=Min
			flashvars.soundVolume		=	"0.8";

			// size the video starts at
			// can be set to 1, 2 and 3
			// 1 for narmol size view
			// 2 for aspect view 
			// 3 for full size view
			flashvars.fullSizeView		=	"1";
			
			////////////////////////////////////////////////////////////////////////
			// VISUAL APPEARANCE  /////////////////////////////////////////////////
			////////////////////////////////////////////////////////////////////////
			
			// spacing between the controls
			flashvars.spacing 			=	"10";
			
			// control bar height		( height )
			flashvars.controlHeight		=	"25";
			
			// vulume scrub lenght 		( lenght )
			flashvars.volumeLengthW		= 	"50";
			
			// controls background		( colors / alphas )
			flashvars.color1 			= 	"0x2e2e2e";
			flashvars.color2 			= 	"0x000000";
			flashvars.alpha1 			= 	"1";
			flashvars.alpha2 			= 	"1";
			
			// controls border			( color / alpha )
			flashvars.borderColor 		= 	"0x555555";
			flashvars.borderAlpha		= 	"1";
			
			// time view ////////////////////////////////////
			// time view background		( colors / alphas )
			flashvars.timeColor1		= 	"0x333333";
			flashvars.timeColor2		= 	"0x111111";
			flashvars.timeAlpha1		= 	"1";
			flashvars.timeAlpha2		= 	"1";

			// time view text color		( color )
			flashvars.timeTextColor1	= 	"0xffffff";
			flashvars.timeTextColor2	= 	"0x888888";

			
			// scrubber /////////////////////////////////////////////////////
			// scrubber height			( height )
			flashvars.scrubberHeight 	=	"3";

			// scrubber background 		( color / alpha )
			flashvars.scrubberColor1	= 	"0x333333";
			flashvars.scrubberAlpha1	= 	"1";

			// scrubber					( color / alpha )
			flashvars.scrubberColor2	= 	"0x47d2ff";
			flashvars.scrubberAlpha2	= 	"1";

			// scrubber glow filter		( color / alpha )
			flashvars.filterColor		= 	"0x0066ff";
			flashvars.filterAlpha		= 	"1";
			
			// control buttons	///////////////////////////////////////////////
			// control buttons color	( color )
			//flashvars.buttonColor		= 	"0x000000";
			
			// info view /////////////////////////////////////////////////////
			// title color					( color )
			flashvars.titleColor			=	"0x47d2ff";

			// description color			( color )
			flashvars.descriptionColor		=	"0xD3D3D3";

			// info background				( color / alpha )
			flashvars.infoBackgroundColor	=	"0x000000";
			flashvars.infoBackgroundAlpha	=	"0.5";
			
			//////////////////////////////////////////////////////////////////////////////////////////////////////
			//////////////////////////////////////////////////////////////////////////////////////////////////////
			//////////////////////////////////////////////////////////////////////////////////////////////////////
			
			var params = {};
			params.scale = "noscale";
			params.allowfullscreen = "true";
			params.salign = "tl";
			params.bgcolor = "000000";
			
			var attributes = {};
			swfobject.embedSWF("js/videoplayer/video-player.swf", file, stageW, stageH, "9.0.0", false, flashvars, params, attributes);
}






function checkFlashContent() {
    
    
      //alert('check flash plugin');
          
      
        // -----------------------------------------------------------------------------
        // Globals
        // Major version of Flash required
        var requiredMajorVersion = 8;
        // Minor version of Flash required
        var requiredMinorVersion = 0;
        // Minor version of Flash required
        var requiredRevision = 0;
        // -----------------------------------------------------------------------------
        // 
   
        // Version check based upon the values entered above in "Globals"
        var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
        
        //alert(hasReqestedVersion);
       
        var alternateContent = 'Az oldalon flash tartalom található.<BR>'
        	+ 'Kérjük töltse le legutóbbi Adobe Flash Player plugin-t '
        	+ '<a href="http://www.adobe.com/go/getflash/" style="text-decoration: underline; " target="_blank">INNEN</a>!';
        	//document.write(alternateContent);  // insert non-flash content
            //alert(alternateContent);
        
        // Check to see if the version meets the requirements for playback
        if (hasReqestedVersion) {
        	
            
            
        } else {  
        	
            $('#flasherror').html(alternateContent);
            
            
        }
        
    
}



function showWithTag(tag_id) {
    
    var show_all = false;
    if(tag_id == 'all') {
        show_all = true;
    }
    
    
    $(".tag_container .item").removeClass('selected');
    $(".tag_sel_"+tag_id).addClass('selected');
    
    $('.munka_item .tag_item').each(function(){
       removeStyleAttribute(this, 'filter');
        if(show_all || $(this).hasClass('tag_'+tag_id)) {
            //$(this).show();            
            $(this).removeClass('hide');
            
            
        } else {
            //$(this).hide();
            $(this).addClass('hide');
            
        }
        
    });
    
    checkTagCompany();
}


function checkTagCompany() {
    
    var size = $('.company_ids').size();    
    var company_ids = new Array(size);
    
    var szaml = 0;
    $('.company_ids').each(function(){        
        company_ids[szaml] = this.value;        
        szaml++;        
    });
    
    var i = 0;
    
    for(i; i < size; i++) {        
        var company_id = company_ids[i];
        var to_hide_company = true;
        $('.company_tag_'+company_id).each(function() {
            
            if(!$(this).hasClass('hide')) {
                to_hide_company = false;
            }
            
        });
        
        if(to_hide_company) {
            
            $('.company_'+company_id).addClass('hide');
            //$('.company_'+company_id).hide();
            
        } else {
            
            $('.company_'+company_id).removeClass('hide');
            //$('.company_'+company_id).show();
                        
        }
        closeDiv('data_'+company_id);
    }
   initPane('container');
    
}



function changeTagMunkaink(tag_id) {
    //alert(tag_id);
    $("#scrollto").val($('#container').offset().top);
    
    $("#munkalist").fadeOut('slow', function(){
        removeStyleAttribute(this, 'filter');
        loadMunkainkAjax(tag_id);
        
    });
    
    
}



function loadMunkainkAjax(tag_id) {
    
    var param = 'ajax=1';
    param += '&tag_id='+tag_id;
    
    $.ajax({
      url: '/ajax/loadmunkaink.php',
      data: param,
      success: function(data) {
            $("#munkalist").html(data);            
            $("#munkalist").fadeIn('slow', function(){
                removeStyleAttribute(this, 'filter');
                $('#container').jScrollPane(
                    {   
                        scrollbarWidth: 18,
                        dragMinHeight: 86,
                        dragMaxHeight: 86
                    }
                );
                initContent();
             });   
        }
    });
    
    
    
}


