/**
 * @author Greg
 */


var Navigation = {
    init: function(){
	   $("a[rel='lightbox']").colorbox();
    }
};

$(document).ready(function(){
	
	Navigation.init();
	
	$('section#newsBlock ul').cycle({
		timeout:5000
	});
	
	$('.rounded').each(function(){
		var round = $('<div></div>').attr('class','roundedWrapper');
		$(round).css({ height: $(this).height(),width:$(this).width() });
        $(this).wrap(round);
        $(this).parent('div.roundedWrapper').append('<span class="tl"></span>');
        $(this).parent('div.roundedWrapper').append('<span class="tr"></span>');
        $(this).parent('div.roundedWrapper').append('<span class="bl"></span>');
        $(this).parent('div.roundedWrapper').append('<span class="br"></span>');		
	});
    
  if ( $.browser.msie ) 
  {
      $('div#header ul.navigation>li:first-child').hover(function(e){$(this).addClass('hover');},function(e){$(this).removeClass('hover');});
  }

	$('div#share').VisibleShare({buttons : 'facebook,twitter,email'});
	
	
	
	if($('#newsletternav').length>0){
		
		$('#newsletternav>ul').append('<div id="newsletternavsubmenu"/>');
		$('#newsletternav>ul>li, #newsletternav>ul>li>a').bind('click',function(e){
			e.preventDefault();
			$('a.newsletter-active').removeClass('newsletter-active');
			$(this).addClass('newsletter-active');
			li = $(this).parent("li").html();
			$("#newsletternavsubmenu").html(li);
			$("#newsletternavsubmenu").show();
			return false;
		});
	}
	
	
	
});


function lightBoxNewsletter(  ){
	$('.page img').each(function(){
		var link = $('<a>').attr('href', $(this).attr('src') ).attr( 'rel' , 'lightbox' )  ;
		$(this).wrap( link )
	});
	$("a[rel='lightbox']").colorbox();
}

function labelImage(){
			
	$('.page img').each( function(){
			
			var parent = $(this).parent('a');
			console.log(parent);
			if(parent.length==0){
			
				var wrapblock = $('<div class="wrapimg">');
				$(wrapblock).attr('style' , $(this).attr('style') );
				var des = $(this).attr('alt');
				
				if($(this).attr('style') ){
					
				
				$.grep( $(this).attr('style').split(';') , function(cssmark){
					var cssinfo = cssmark.split(':') ;
					$(this).css(cssinfo[0], '');			
			    });
				$(this).attr('style',''); 
				
				
				$(this).css({display:'block'});
				$(this).wrap(wrapblock);
						
				
				wrapblock = $(this).parent('.wrapimg');
				var legend = $('<p>').html( des );
				$(wrapblock).append(legend)	;
				$(legend).addClass( 'imglegend' );
				$(legend).width( $(this).width() );
				
				$(wrapblock).height( $(wrapblock).height() + $(legend).height() )
				}
			}
			
			
			
	})	;	
}

