$(document).ready(function() {

    if(typeof sIFR == "function"){
        sIFR.replaceElement("h2", named({sFlashSrc: "/Common/Flash/skia.swf", sColor: "#336633"}));
        sIFR.replaceElement(".panelSide h3", named({sFlashSrc: "/Common/Flash/skia.swf", sColor: "#336633", sWmode: "transparent"}));
        sIFR.replaceElement("h3.hdrLinks", named({sFlashSrc: "/Common/Flash/skia.swf", sColor: "#336633"}));
    };
    
	$('.btnPanels').each(function(){
		if($.browser.msie && parseInt($.browser.version)==6 && $('img', this).attr('src').indexOf('.png')!=-1) {
			var imgPng = $('img', this).attr('src');
			var imgPngW = $('img', this).width();
			var imgPngH = $('img', this).height();
			$('h3', this).css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgPng+"',sizingMethod='crop')").click(function(){
				location.href = $('a', this).attr('href');
			});
		} else {
			$('h3', this).css('background','url('+$('img', this).attr('src')+') 0 0 no-repeat');
		}
	});
	$('#NewsList li').each(function(){
		$(this).click(function(){
			location.href = $('h3 a', this).attr('href');
			return false;
		});
	});
    $('.rollover').rollover();
 
    $('.navigation div').each(function(){
        $(this).data('width',0);
        $('img',this).each(function(){
            $(this).parent().parent().parent().parent().data('width', $(this).parent().parent().parent().parent().data('width')+10+$(this).width())
        });
        $(this).width($(this).data('width'))
    });
    if($('.navigation > li.selected').length > 0){
        $('.navigation > li:not(.selected)').hover(function(){
            $(this).addClass('hover');
            $('.navigation').data('selectedPosition',$('.navigation > li.selected div').css('left'));
            $('.navigation > li.selected div').css('left','-9999px');
        },function(){
            $(this).removeClass('hover');
            $('.navigation > li.selected div').css('left',$('.navigation').data('selectedPosition'));
        });
    }
    
    $('.shareThis #btn').click(function(){$('.shareThis p, .shareThis ul').toggle();});
    $('.shareThis li a').click(function(){
        var h = $(this).attr('href');
        var t = document.title;
        var u = location.href;
        h = h.replace(/#url/,u);
        h = h.replace(/#title/,t);
        h = encodeURI(h);
        window.open(h);
        return false;
    });
    
    $("#terms-popup a").click(function(e) {
        e.preventDefault();
        window.open ("/DavidJonesSurvey/Terms.aspx", "tandc","scrollbars=1,menubar=0,resizable=1,location=0,width=700,height=700"); 
    });
    
    var moreButton = $('<a id="recipes-more" href="#">More</a>'),    
        minRecipeHeight = 150,
        maxRecipeHeight = '100%';
    
    $('#recipes-more-nav').css('height', minRecipeHeight).append(moreButton);
    
    $(moreButton).click(function() {
        if($('#recipes-more-nav').hasClass('open')){
            $('#recipes-more-nav').animate({
                height: minRecipeHeight
            }, 500).removeClass('open');
        }
        else{
            $('#recipes-more-nav').animate({
                height: maxRecipeHeight
            }, 500).addClass('open');
        }
        
        return false;
    });

	
});

function ValidateSurveyCheckList(source, args) {
    args.IsValid = false;
    console.log('error handling: Check Lists');
    $('.check-list input').each(function() {
        if ($(this).attr('checked') == true) {
            args.IsValid = true;
        }
    });
    return;    
}
function ValidateSurveyRadioList(source, args) {
    args.IsValid = false;
    console.log('error handling: Radio Lists');
    $('.radio-list input, .rating-list input').each(function() {
        if ($(this).attr('checked') == true) {
            args.IsValid = true;
        }
    });
    return;
}
