var GenEffects = {
    
    setInterval_1: 5, // interval of dissapearing icons after the page loads
    setInterval_2: 3, // interval of dissapearing icons after you mouseover
    
    init: function() 
    {
        $(window).load(function(){
            GenEffects.timeoutInterval(GenEffects.setInterval_1);           
        });
        
        zindexBoxes0 = 990;
        zindexBoxes1 = 991;
        
        GenEffects.slideRightCompanies();
        GenEffects.mouseoveMainPic();
        
        //GenEffects.showImageSlide();
        
        //GenEffects.showSocialFeed();
        GenEffects.overSocialIcon();
        
        GenEffects.overCompanyLogo();
        //GenEffects.overNewsThumb();
        //GenEffects.overBigThumbs();
        
        GenEffects.goToMenu();
        GenEffects.overMenu();
        
        
        GenEffects.clickSubmenu();
        
    },
    
    timeoutInterval: function(interval) 
    {
        time = setTimeout(function(){
				                        GenEffects.slideLeftCompanies();           
				                        GenEffects.slideLeftIcons();           
				                        GenEffects.fadeOutShowImage();           
				                    }, interval * 1000);
    },
    
    // timeOutFacebook: function(interval)
    // {
    	// time = setTimeout(function(){
//     
				                    // }, interval * 1000);
    // },
    
    slideLeftCompanies: function() 
    {
        $('#left_logos').animate({
						            left: "-45px"
						        }, 500, "linear"); 
    },
    
    slideRightCompanies: function() 
    {
        $('#left_logos').hover(function(){
            clearTimeout(time); 
            $(this).stop(true,true).animate({
                left:"0"
            },500,"linear");   
        },function(){
            GenEffects.timeoutInterval(GenEffects.setInterval_2);    
        }).stop(true,true);
    },
    
    slideLeftIcons: function() 
    {
        $('.icons_fw, .small_thumbs').css({'z-index':'-2'}).animate({
															            right: "0"
															        }, 500, "linear", function(){$('.small_thumbs').css({bottom:"40px"})});    
    },
    
    fadeOutShowImage: function() 
    {
        $('.se_bare_bildet').fadeOut(500);
    },
    
    clickSubmenu: function() 
    {
    	
        $('.submenu .mp_black_box_325 li h4 a').click(function(){
            GenEffects.switchContent('subpages_'+$(this).attr('id'));    
        });    
    },
    
    mouseoveMainPic: function() 
    {
        $('#main_picture').hover(function(){ 
									            clearTimeout(time);   
									            $('.icons_fw').stop(true,true)
									                          .animate({right:"-41px"},500,"linear",function(){
									                              $(this).css({'z-index':'1'})
									                          });       
									            $('.small_thumbs').css({bottom:"-13px"})
									                              .stop(true,true)
									                              .animate({right:"-58px"},500,"linear",function(){
																					                                  $(this).css({'z-index':'1'})
																					                              });
									            $('.se_bare_bildet').stop(true,true).fadeIn(500);   
                
									        }, 
						        function()	{
						            			GenEffects.timeoutInterval(GenEffects.setInterval_2);      
						        			}
									); 
									
		// $('.icons_fw').hover(function()	{
											// GenEffects.timeOutFacebook(GenEffects.setInterval_2);
										// },
							 // function()	{
								 			// GenEffects.timeoutInterval(GenEffects.setInterval_2);
							 			// }
							// ); 
    },
    
    showSocialFeed: function() 
    {
        $('.socialMedia').click(function(){
                    
            // check what box is opened
            GenEffects.closeOpenBoxes(); 
             
            media = $(this).attr('id');
            f = $('#'+media+'_feed'); 
            f_img = $('#'+media).children('img'); 

            if(f_img.hasClass('active')) {
                f.stop().animate({'marginLeft':'280px'},500,"linear"); 
                f_img.removeClass('active');   
            } else {
                $('.socialMedia').children('img').removeClass('active');
                f_img.addClass('active');
                f.parent().css({'z-index':zindexBoxes1}).children().stop().animate({'marginLeft':'21px'},500,"linear");
            } 
            // remove all the active boxes
            /*
            $('.f_container_325').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'380px'},500,'linear', function(){
                $('.f_container').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'280px'},500,'linear');
                f.parent().siblings('.socialFeed').children().animate({'marginLeft':'280px'},500,'linear', function(){
                     
                    if(f_img.hasClass('active')) {
                        f.stop().animate({'marginLeft':'280px'},500,"linear"); 
                        f_img.removeClass('active');   
                    } else {
                        $('.socialMedia').children('img').removeClass('active');
                        f_img.addClass('active');
                        f.parent().css({'z-index':zindexBoxes1}).children().stop().animate({'marginLeft':'21px'},500,"linear");
                    }      
                });  
            });*/
            
            
        });    
    },
    
    overSocialIcon: function() 
    {
        $('.socialMedia').hover(function(){
            media_text = $(this).attr('id');
            $('.'+media_text+'_text').show();        
        }, function(){
            $('.'+media_text+'_text').hide(); 
        });
    },
    
    overCompanyLogo: function() 
    {
        $('.leftLogoIcon').hover(function(){
            
            $(this).css({opacity:1});
            //get logo text widh
            logoText = $(this).parent().children('.leftLogoImg');
            leftLogoWidth = logoText.width();
            
            // put it in the right place and hide it then fade in
            logoText.parent().stop(true,true).animate({width:leftLogoWidth+50},500,'linear',function(){
                       logoText.css({opacity:'1',display:'block'});
                       //logoText.stop(true,true).animate({opacity:'1',display:'block'},500,'linear');
                   });
            
        }, function(){
            leftLogoIcon = $(this);
            
            if($(this).parent().parent().hasClass('current') == false) {
                noOpac = '0.7';   
            } else {
                noOpac = '1';
            }
            //logoText.css({opacity:'0'});
            logoText.stop(true,true).animate({opacity:0},500, function(){
                logoText.css({display:'none'});
                leftLogoIcon.stop(true,true).animate({opacity:noOpac},500,'linear');
                leftLogoIcon.parent().stop(true,true).animate({width:'40px'},500,'linear');    
            });             
        });
        //$('#left_logos li a').hover(function(){
//            $(this).siblings('.show_logo').show();    
//        }, function(){
//            $(this).siblings('.show_logo').hide();
//        });
    },
    
    overNewsThumb: function() 
    {
        $('.thumb').click(function(){  
            
            var newsId = $(this).children('a').attr('id');  
            GenEffects.switchContent('page_'+newsId);
            
            var newsNb = newsId.substr((newsId.length-1), newsId.length); 
             $('.list_news li').each(function(){
                if($(this).hasClass('current')) {
                    $(this).removeClass('current').children('.arrow').remove();        
                }                      
            });        
            $('.list_news li:eq('+newsNb+')').addClass('current').append('<div class="arrow"></div>');
            GenEffects.getNewsBox(); 
        });
        
        th_title_width = $('.th_title').width();
        $('.thumb').hover(function(){
            th_title = $(this).children('.th_title');
            pattern_dots = $(this).children('.pattern_dots');
            
            th_title.stop().animate({left:'-'+th_title_width+'px'},500,'linear');
            pattern_dots.stop(true,true).fadeOut(500);    
        }, function(){
            th_title.stop().animate({left:'0'},500,'linear');
            pattern_dots.stop(true,true).fadeIn(500);      
        });
    },
    
//    overBigThumbs: function() {
//        $('.big_thumb').hover(function(){
//            $(this).children('.title').stop().animate({right:'-185px'},500,'linear');    
//        }, function(){
//            $(this).children('.title').stop().animate({right:'0'},500,'linear');
//        });
//    },
    
    goToMenu: function() 
	{
        $('.menu li a').click(function()
		{
            // trying to fade the current bar - NOTE but not working
            liTag = $(this).parent();
            var menu = $(this).text();
			var hr = $(this).attr('href');
            
            $('.pos_current_overlay').animate({marginTop:'0px'},500,'linear', function()
			{
                liTag.siblings('.menu li').removeClass('current');
                liTag.addClass('current'); 
				
                $(this).animate({marginTop:'34px'},500,'linear');  
				
				if(menu == 'KONTAKTER' || menu == 'English')
				{
					$("html, body").animate({scrollTop: 625}, 1500);
				}
				
				if(hr)
				{
					//if an extra menu with content of a different category has one submenu only slide down to content:
					
					hr = hr.toString().substring((hr.indexOf('/') + 1), hr.lastIndexOf('/'));
					
					if(!(hr == 1 || hr == 2 || hr == 5 || hr == 6 || hr == 9 || hr == 10 || hr == 7 || hr == 3 || hr == 4))
					{
						setTimeout(function()	{
													// console.log('atatea chestii: ' + $('div.submenu ul li').length);
													if($('div.submenu').length == 0)
													{
														//console.log('am trecut testul!');
														$("html, body").animate({scrollTop: 625}, 1500);
													}
												}, 1000);
												
						// $('#container[class="submenu"]').load(function()	{
						// 													});
					}
				}
            });   
                   
            //var str_func = $(this).attr('id')+'Page';
            //var page_func = "GenEffects."+str_func + "()";
        
            //call the page function
            //var ret = eval(page_func);
        });  
    },
    
    overMenu: function() 
    {
        $('.menu li').hover(function(){
            if (navigator.userAgent.match(/MSIE (\d+(?:\.\d+)+(?:b\d*)?)/) == "MSIE 7.0,7.0") {
                bottomMenuLine = '4px';    
            } else {
                bottomMenuLine = '2px';
            }
            $(this).children('a').stop(true,true).animate({marginTop:'-5px',paddingBottom:'5px'},500)
                   .append('<div class="bottom_red_line"></div>')
                   .children('div.bottom_red_line').stop(true,true).animate({opacity:1, bottom: bottomMenuLine},500);               
        }, function() {  
            $(this).children('a').stop(true,true).animate({marginTop:'0',paddingBottom:'0'},500)
                   .children('div.bottom_red_line').stop(true,true).animate({opacity:0, bottom:'0px'},500,'linear', function(){ 
                       $(this).remove(); 
                   });                                                                                         
        });    
    },
    
    closeOpenBoxes: function() 
    {
        /*
        $('.f_container').each(function(){
            var marLeft = $(this).children().css('margin-left');
            var marLeftInt = marLeft.substr(0,(marLeft.length-2));
            if(marLeftInt < 50) {
                $(this).children().animate({marginLeft:'280px'},500,'linear');
            }
        });
        $('.f_container_325').each(function(){
            var marLeft = $(this).children().css('margin-left');
            var marLeftInt = marLeft.substr(0,(marLeft.length-2));
            if(marLeftInt < 50) {
                $(this).children().animate({marginLeft:'380px'},500,'linear');
            }
        });   */ 
    },
    
    switchContent: function(pageClass) {
        // fade out the content
    	
        $('#content .columns').each(function(){
            if($(this).css('display') == 'block') {
                $(this).animate({opacity:0},500,'',function(){
                    $(this).hide();
                    $('#content .'+pageClass).show().animate({opacity:'1.0'},500);        
                });
            }    
        });    
    },
    
    projectSelected: function(getClass) {
    	
        $(getClass+' li').each(function(){
            if($(this).hasClass('current')) {  
                index = $(this).children('a').attr('id');
            }    
        });  
        return index;  
    },
    
    projectSelected2: function(getClass) {
    	
        $(getClass+' li').each(function(){
            if($(this).hasClass('current')) {  
                index = $(this).children('a').attr('id');
            }    
        });  
        return index;  
    },
    
    changeListProjects: function() {
        
        $('.in_progress_projects').click(function() {
            console.log('test');
            $(this).removeClass('inactiv_button').siblings('.active_projects').addClass('inactiv_button');
            $('.ap_list').fadeOut(500, function(){
                $('.ipp_list').fadeIn(500, function(){
                    scrollbar('ipp_list');
                });    
            }); 
            
           // projectSelectedVar =  GenEffects.projectSelected('.ipp_list');
//            if(projectSelectedVar == 'undefined') {
//                projectSelectedVar = 0;
//            }                             
            //GenEffects.switchContent('projectsPage_ipp_'+projectSelectedVar);
             
        }); 
        
        $('.active_projects').click(function() {
            console.log('tes22t');
            $(this).removeClass('inactiv_button').siblings('.in_progress_projects').addClass('inactiv_button');
            $('.ipp_list').fadeOut(500, function(){
                $('.ap_list').fadeIn(500, function() {
                    scrollbar('ap_list');
                });     
            });
            
//            projectSelectedVar =  GenEffects.projectSelected('.ap_list');
//            if(projectSelectedVar == 'undefined') {
//                projectSelectedVar = 0;
//            }                   
            //GenEffects.switchContent('projectsPage_ap_'+projectSelectedVar);       
        }); 
    },
    
    liCurrentProject: function(getThis, getClass) {
        $(getClass+' li').each(function(){
            if($(this).hasClass('current')) {
                $(this).removeClass('current').children('.arrow').remove();        
            }                      
        });        
        $(getThis).parent().addClass('current').append('<div class="arrow"></div>');
    },
    
    getNewsBox: function() { 
            GenEffects.closeOpenBoxes(); 
            
            console.log('getNewsBox');
            
            // get the news box
            $('.news').parent().css({'z-index':zindexBoxes1}).children().animate({marginLeft:'21px'},500,'linear'); 

            $('.list_news li a').click(function(){
                GenEffects.liCurrentProject($(this),'.list_news');
                newsSelectVar =  GenEffects.projectSelected('.list_news');
                if(newsSelectVar == 'undefined') {
                    newsSelectVar = 0;
                }
                console.log(newsSelectVar);
                GenEffects.switchContent('page_news_0'+newsSelectVar);            
            });         
    },
    
    homePage: function() {
        $('.f_container_325').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'380px'},500,'linear',function(){
            // remove the active class for the social media icons
            $('.socialMedia img').removeClass('active');    
            
            // slide out the twitter/facebook feeds
            $('.f_container').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'280px'},500,'linear');
        });
        
        // switch the content
        GenEffects.switchContent('homePage');   
    },
    
    about_usPage: function() {
        // check what box is opened
        GenEffects.closeOpenBoxes();
        
        // switch the content
        GenEffects.switchContent('subpages_4'); 

        $('.f_container_325').each(function(){$(this).css({'z-index':zindexBoxes0});});
        // show the service box
        $('.about_us_submenu').parent().css({'z-index':zindexBoxes1}).children().animate({marginLeft:'21px'},500,'linear');    
    },
    
    servicesPage: function() {
        
        // check what box is opened
        GenEffects.closeOpenBoxes();          
        // slide out all the boxes opened
        $('.f_container').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'280px'},500,'linear', function(){
            // remove the active class for the social media icons
            $('.socialMedia img').removeClass('active');
            
            // show the service box
            $('.services_submenu').parent().css({'z-index':zindexBoxes1}).children().animate({marginLeft:'21px'},500,'linear');            
        });
        
        // switch the content
        GenEffects.switchContent('servicesPage');
        
        $('.f_container_325').each(function(){$(this).css({'z-index':zindexBoxes0});});
    },
    
    projectsPage: function() {
        
        // check what box is opened
        GenEffects.closeOpenBoxes();
        
        // slide out all the boxes opened
        $('.f_container').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'280px'},500,'linear', function(){
            // remove the active class for the social media icons
            $('.socialMedia img').removeClass('active');
            
            // show the service box
            $('.projects').parent().css({'z-index':zindexBoxes1}).children().animate({marginLeft:'21px'},500,'linear');            
        });
        
        // switch the content
        var list_displayed = 'ap_7';
        $('.list_projects').each(function(){
            if($(this).css('display') == 'block' && $(this).hasClass('ipp_list')) {
                list_displayed = 'ipp_7';
            }    
        });                     
        GenEffects.switchContent('projectsPage_'+list_displayed);  
        
        //change to active/in progress projects list
        GenEffects.changeListProjects(); 
        
        // change content of the active projects
        $('.ap_list li a').click(function(){
            //get the li a number 
            GenEffects.switchContent('projectsPage_ap_'+$(this).attr('id'));
            
            // make it current project
            GenEffects.liCurrentProject($(this), '.ap_list');
        });
        
        // change content of the in progress projects
        $('.ipp_list li a').click(function(){
            //get the li number  
            GenEffects.switchContent('projectsPage_ipp_'+$(this).attr('id'));
            
            // make it current project
            GenEffects.liCurrentProject($(this), '.ipp_list');
        });
        
        $('.f_container_325').each(function(){$(this).css({'z-index':zindexBoxes0});});
    },
    
    pressPage: function() {
        // check what box is opened
        GenEffects.closeOpenBoxes();
        // show the service box
        $('.f_container_325').each(function(){$(this).css({'z-index':zindexBoxes0});});
        $('.presse_submenu').parent().css({'z-index':zindexBoxes1}).children().animate({marginLeft:'21px'},500,'linear');
        
        GenEffects.switchContent('subpages_15');     
    },
    
    carriersPage: function() {
        // check what box is opened
        GenEffects.closeOpenBoxes();
        // show the service box
        $('.f_container_325').each(function(){$(this).css({'z-index':zindexBoxes0});});
        $('.jobs_submenu').parent().css({'z-index':zindexBoxes1}).children().animate({marginLeft:'21px'},500,'linear');
        GenEffects.switchContent('subpages_23');      
    },
    
    equipmentPage: function() {
        
    },
    
    contactPage: function() {
                
        // check what box is opened
        GenEffects.closeOpenBoxes();
        
        // remove the active class for the social media icons
        $('.socialMedia img').removeClass('active');
        
        $('.f_container').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'280px'},500,'linear',function(){
            $('.f_container_325').css({'z-index':zindexBoxes0}).children('div').animate({marginLeft:'380px'},500,'linear',function(){
                $('#contact_form').parent().css({'z-index':zindexBoxes1}).children().animate({marginLeft:'21px'},500,'linear');    
            });    
        });
        
        // switch the content
        GenEffects.switchContent('contactPage');        
    }
    
};

$('document').ready(function()	
{
	$('div.dropedImageBox').live('hover',	function(ev)
											{
												var span = $('span', this);
												
												if(ev.type == 'mouseover' || ev.type == 'mouseenter')
												{
													span.stop(true, true).animate({marginRight: -(span.width() + 49)}, 500);
												}
												else
												{
													span.stop(true, true).animate({marginRight: 0}, 500);
												}
											}
								);
});

var opened_news_box = false;

function loadBox(href) 
{
    if(opened_news_box)
    {
    	closeOpenBoxes();
    	opened_news_box = false;
    }
    else
    {
    	opened_news_box = true;
	    $('.f_container_325').load(href,{},function() {
													        Cufon.refresh();
													        $(this).css({'z-index':'991'});
													        $('#container').animate({marginLeft:'21px'},500,'linear', function(){
																														            loagAgain();
																														            scrollbar();    
																														        });
													    });
	 }
}

