/// <reference path="jquery uncompress/jquery-1.2.3-intellisense.js" />
/*<![CDATA[*/


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
		jQuery DOM ready functions
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

//jQuery(function() {
$(document).ready(function(){

    // striped tables on table class stripedTable
    $('.stripedTable tr:even').addClass('coloredRow');

    
    //add class to define the frontpage
    if( $('#frontpage').is(':visible')){
        $('#page').addClass('home');
    }

    //focus on searchfield
    if($('#searchResult').is(':visible')){
        $('.searchField').focus(); 
    }
    $('.frontpage .searchField').focus(); 

    //odd even on StaticContentPage.aspx
    $('#staticPage table tr:odd').addClass('odd')

    //rounded corner
     $('.c').corner("round 3px");
     $('.cb').corner("3px bl br");

    //Show tell a friend popup
     $('.close').click(function(){
        $('.status').hide();
        $('.result').show();
    });
    var hide = $('.close');
   
   $('.jqmWindow')
    .jqm({toTop: true})
    //.jqDrag()
    .jqmAddClose(hide);

    //Show hide article toolbox     
    winH = $(window).height();
    var articleH = $('#article').height()
    if(articleH > winH){
         $('.toolboxBottom').show();
	}
	
	//ResearchTeaser innerfade
	$('#researchTeaser ul li:first').show();
	$('#researchContent').innerfade({
		animationtype: 'fade',
		speed: 750,
		timeout: 4000,
		type: 'random'
	});

    //sifr font replace
    var mode = document.location.toString();
    if (mode.match('idkeep')) { 
    } 
    else {
     $.sifr({
	    font: '/js/DAXRegular'
     });
     $('h1').sifr();
	 $('#footer h4').sifr();
     //$('#nutritionTeaser .nutritionContent h2').sifr({offsetTop: 0, offsetLeft: 0});
    }
    
    //latest content hover 
     $('#latestContent dl').hover(function() {
          $(this).addClass('hover');
        }, function() {
          $(this).removeClass('hover');
        });
        
    //latest content truncate
    $("#latestContent .trunc").truncate( 50,{trail: [ "", "" ]} );    
    $(".mediaPackageItem .summaryShort").truncate( 180 );
    
    //Mediapackage hover
    $('ul.media li:odd').addClass('odd');
    
    $('.mediaPackageItem').hover(function() {
          $(this).addClass('hover');
        }, function() {
          $(this).removeClass('hover');
        }
    );
    
    // Remove vr on every third element 
    $('.mediaPackageItem:third').addClass('third'); 
    $("<div class='hr clear'><hr /></div").insertAfter('.mediaPackageItem:third');

    //remove link on nutritionteaser
    if($('.vr .nutrition').is(':visible')){$('#nutritionTeaser a').remove();}
    
    //set a class for internal linking
    //jQuery('.staticContent a[@href^="http://"]').addClass('external');
    //jQuery('.staticContent a[@href^="../"]').addClass('internal');
    jQuery('.staticContent a[href*=.pdf]').attr('rel','external');
    jQuery('.staticContent a[href*=.doc]').attr('rel','external');
    jQuery('.staticContent a[href*=.img]').attr('rel','external');
    
    
    //external link
    $('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });
    
    // "selected" class on front page link when on frontpage
    if ($('.home').is(':visible')) { $('#nav ul li:first').addClass('selected'); }
    


    
});

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
		Functions
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

//function to toggle text 
function textToggle(element,text1,text2){
    if( jQuery.trim($(element).text()) == text1 )
        $(element).text(text2);
    else $(element).text(text1);
}

/** Validation methods **/
function ValReqEmail(ctrlId,msg,valsum)
{
  return Val(ctrlId,/^[A-Za-z0-9](([\_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/,msg,valsum)
}
   
function ValReqDigits(ctrlId,msg,valsum)
{
  return Val(ctrlId,/^\d+$/,msg,valsum)
}
    
function ValReq(ctrlId,msg,valsum)
{
  return Val(ctrlId,/^.+$/,msg,valsum)
}

function Val(ctrlId,regex,msg,valsum)
{
  var val = jQuery.trim($(ctrlId).val());
  if (!val.match(regex))
  {
    // TODO: insert into valsum
    alert(msg);
    $(ctrlId).focus();
    return false;
  }
  return true;
}

/*]]>*/
