grWP = $('#wbPath').html();

$(function(){
    overNewsThumb();
    loadFeed();
    showImageSlide(); 
    removeDivsNews();  
    checkHash(); 
});

function checkHash() {
    
    var hashes = window.location.hash;  
        hashes = hashes.substr(1);  
    var hash = hashes.split('index.html');
    
    if(typeof(hashes) != 'undefined' && typeof(hash[0]) != 'undefined' && hash[0] != '') {
        
        if(hash[0] == 7) 
        {
            typePage = 'contacts';
            setTimeout(function()	{
						            	$("html, body").animate({ scrollTop: 625 }, 1500);
						            }, 2500
					  );
        } 
        else 
        {
            typePage = 'pages/'+hash[0];
        }
        
        // check to see if we have submenu
        if(hash[1] != '' && typeof(hash[1]) != 'undefined') 
        {
            submenu = grWP+'/get_submenu/'+hash[1]+'/ #container';
        }
        else 
        {
            submenu = 'hideSub';
        }
        
        
         // load the content
        loadPiece(grWP+'/'+typePage+'/ #container', submenu, hash[2]);   
        
        // set the current menu
        $('.menu li').removeClass('current');
        $('.menu').find('a[href="#'+hash[0]+'/'+hash[1]+'/"]').parents('li').addClass('current');
        
        // this is for the thid param
        if(hash[2] != '') {
            $('.list_projects li').removeClass('current');
            //$('.list_projects').find('a[id="'+hash[2]+'"]').parents('li').addClass('current').prepend('<div class="arrow"></div>');
        }
    }
}

function overNewsThumb() {
    $('.thumb').click(function(){  
        
        var newsId = $('ul.home li').index($(this).parent());  
     
        $('.list_news li:eq('+newsId+')').addClass('current').append('<div class="arrow"></div>'); 
    });
    
    item_title_width = $('.item_title').width()+100;
    $('.thumb').hover(function(){
        item_title = $(this).children().children('.item_title');
        pattern_dots = $(this).children().children().children('img');
        
        item_title.stop().animate({left:'-'+item_title_width +'px'},500,'linear');
        pattern_dots.stop().animate({opacity:'1'},500,'linear');    
    }, function(){
        item_title.stop().animate({left:'0'},500,'linear');
        pattern_dots.stop().animate({opacity:'0.5'},500,'linear');      
    });
}

function overPictures() {
    $('.dImageBox').hover(function(){
        item_titleR = $(this).find('.item_titleR');
        item_titleR.stop().animate({right:'-'+item_titleR.width()+'px'},500,'linear');    
    }, function(){
        item_titleR.stop().animate({right:'0'},500,'linear');
    });
}

function clickNewsItem() 
{
//	console.log('clickNewsItem()');
	
    $('.list_news li a').click(function(){
        $('.list_news li').each(function(){
            if($(this).hasClass('current')) {
                $(this).removeClass('current').children('.arrow').remove();        
            }                      
        });        
        $(this).parent().addClass('current').append('<div class="arrow"></div>');
//        scrollDownBody();         
    });
}



    
function loadFeed() {
    
    $('.f_container_t').load('socialmedia/twitter/index.html',{},function(){
        Cufon.refresh();
    });
    $('.f_container_f').load('socialmedia/facebook/index.html',{},function(){
        Cufon.refresh();
    });    
}

function showImageSlide() {

    $('.se_bare_bildet a').click(function(){
        
        thisSeBare = $(this);
        closeOpenBoxes();
        aId = $(this).attr('class');
        if($(this).hasClass('activate')) {     
            $('.mp_right_bg').stop(true,true).animate({opacity:0},500,'linear');
            $(this).removeClass('activate').addClass('inactivate').stop(true,true).fadeOut(500, function(){
                $(this).hide();
                thisSeBare.html('<img src="'+grWP+'/img/frontend/se_bare_bildet_icon_activ.png" alt="STILBAKE" /> TILBAKE');
                Cufon.refresh();    
                thisSeBare.fadeIn(500);
                clearInterval(intervalID);
            })
        } else {
            $('.mp_right_bg').stop(true,true).animate({opacity:1},500,'linear');
            $(this).removeClass('inactivate').addClass('activate').stop(true,true).fadeOut(500, function(){
                $(this).hide();
                thisSeBare.html('<img src="'+grWP+'/img/frontend/se_bare_bildet_icon.png" alt="SE BARE BILDET" /> SE BARE BILDET');
                Cufon.refresh();
                thisSeBare.fadeIn(500); 
                intervalID = setInterval(slideImage, timeoutInterval);   
            })
                   
        }  
    });
}

function removeDivsNews() {

}
(jQuery);
