$(document).ready(function() {
// Don't run these on iPhone, iPod
if ($('.ipod,.iphone').length == 0) {
//MATCH HEIGHTS AND BOTTOMS
if ($('.matchheight').length != 0) {
// Make all .matchheight elements have the same height (matches tallest)
// $('article').equalHeights('.matchheight');
$('.matchheight').height($.reduce($('.matchheight'), 0,
function(value, index, element) {
return ($(this).height() > value) ? $(this).height() : value;
}));
};
if ($('.matchbottom').length != 0 && $('.ie6').length == 0) {
// Make all .matchbottom elements end at the same place (matches lowest edge)
$('article').matchBottoms('.matchbottom');
};
if ($('.tips .tip').length != 0) {
var expandButton = '
+
';
$('.tip').each(function() {
$(this).prepend(expandButton);
$(this).addClass('closed');
});
}
if ($('.infoboxes .tip').length != 0) {
var discloseButton = '+
';
$('.tip').each(function() {
$(this).prepend(discloseButton);
$(this).addClass('closed');
});
$('.tip .disclose').click(function() {
if ($(this).parent().hasClass('closed')) {
$(this).parents('.infoboxes').children('.tip').addClass("closed");
$('.disclose').text('+');
$(this).parent().removeClass("closed");
$(this).text('-');
var target = $(this).parent().attr('id');
var imgdir = '/img/treatment/medication/how-different-medicines-work/';
$('figure img').attr('src', imgdir + target + '.png');
} else {
$(this).parent().addClass("closed");
$(this).text('+');
if ($(".closed").length == 3) {
$('figure img').attr('src', '/img/treatment/medication/how-different-medicines-work/default.png');
}
};
});
}
// Disclosure buttons for info boxes
$('.expand_button').toggle(
function() {
$(this).parent().removeClass("closed");
$(this).text('-');
},
function() {
$(this).parent().addClass("closed");
$(this).text('+');
}
);
// Interactive rollovers for Risks, Exercise
$('map area')
.mouseover(function() {
var el = $($(this).attr('href'));
$('.risk_popup:visible, .exercise_popup:visible').hide();
el.show()
.find(".risk_pulse")
.mouseout(function() {
el.hide();
});;
});
}
// Exit-site interstitial
if ($('a.exit_check').length != 0) {
$('body').prepend('');
};
$('a.exit_check')
.click(function(e) {
e.preventDefault();
myURL = $(this).attr('href');
$('#mask').load('/js/' + $(this).attr('exittype'),
function() {
$('.continue', $('#mask')).attr('href', myURL);
$('.iphone body,.ipod body').height(window.innerHeight).css('overflow','hidden');
}).show();
return false;
});
// Checks if Mask is visible; if orientation changes, asjusts body height and width
//if close button is clicked
$('.interstitial .cancel').click(function(e) {
//Cancel the link behavior
$('body').height('auto');
$('#mask, .interstitial').hide();
});
//if mask is clicked
$('#mask').click(function() {
$('body').height('auto');
$(this).hide();
$('.interstitial').hide();
});
// Open 'pop' links in a new window.
$('a.pop').click(function(e) {
e.preventDefault();
window.open(this.href);
return false;
});
// Open commercial in fancybox
$('a.watch_commercial').fancybox({
width: 788,
height: 500,
// autoDimensions: false,
type: 'iframe'
});
// Helper for using images in place of radio buttons
$("input + span")
.click(function() {
$(this).prev("input").click();
});
//SLIDESHOW
if ($('#sliderShell').length != 0 && $('.ie6').length == 0) {
var $slides = $('#sliderShell .scrollContainer > .slide');
var $container = $('#sliderShell .scrollContainer');
var horizontal = true;
if (horizontal) {
$slides.css({
'float': 'left',
'position': 'relative'
});
$container.css('width', $slides[0].offsetWidth * $slides.length);
}
var $scroll = $('#sliderShell .scroll').css('overflow', 'hidden');
$scroll.after('');
var offset = parseInt((horizontal ?
$container.css('paddingTop') :
$container.css('paddingLeft'))
|| 0) * -1;
var scrollContainerWidth = $('.scrollContainer').width();
var slideWidth = $('.slide:eq(0)').width();
var numberOfSlides = scrollContainerWidth / slideWidth;
$('.slide_number').html("1/" + numberOfSlides);
var updateSlideNumber = function() {
var slideNumber = (($('.scrollContainer').position()['left'] * -1) / slideWidth) + 1;
$('.slide_number').html(Math.round(slideNumber) + "/" + numberOfSlides);
};
var scrollOptions = {
target: $scroll,
items: $slides,
prev: 'img.left',
next: 'img.right',
axis: 'xy',
offset: offset,
duration: 500,
easing: 'swing',
onAfter: updateSlideNumber
};
$('#sliderShell').serialScroll(scrollOptions);
$.localScroll(scrollOptions);
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);
};
if ($("#video-js").length > 0) {
$f("video-js",
{
src: "http://releases.flowplayer.org/swf/flowplayer-3.2.7.swf",
wmode: 'opaque'
},
{
"playlist": ["/video/learn/yiadom_friedman.png", {
"url": "http://resources.novartis.com/1in3people/video/learn/yiadom_friedman.mp4",
"autoPlay": false,
wmode: 'opaque',
"autoBuffering": true
}]
});
}
var videoTimeline = {
'#facts': 0,
'#factors': 73,
'#risks': 123,
'#treatment': 174,
'#wisdom': 248
};
$('.chapter').bind(
'click',
function() {
var time = videoTimeline[$(this).attr('href')];
var video = document.getElementById('video_learn');
if (! ($.browser.msie && $.browser.version < 9)) {
video.currentTime = time;
} else {
video = $f();
video.seek(time);
}
if (video.getState && video.getState() <= 2) {
throw "Not ready";
}
if ((video.getState && video.getState() == 4) || video.paused) {
video.play();
window.setTimeout(function() {
video.pause();
},
2000);
}
location.hash = $(this).attr('href');
return false;
}
);
if (videoTimeline[location.hash]) {
var checkLoaded = function() {
window.setTimeout(function() {
try {
$("a[href=" + location.hash + "]").click();
} catch(x) {
checkLoaded();
}
},
250);
};
checkLoaded();
}
// Social
$(".facebook").live("click",
function() {
var url = location.href;
var title = document.title;
window.open("http://www.facebook.com/sharer.php?u=" + encodeURIComponent(url.replace("#!", "")) + "&t=" + encodeURIComponent(title), "sharer", "toolbar=0,status=0,width=626,height=436");
return false;
});
$(".twitter").live("click",
function() {
var url = location.href;
var title = document.title;
window.open("http://twitter.com/home?status=Check out 1in3people.com to find useful information about high blood pressure, including risks and treatment options. " + encodeURIComponent(url), "sharer", "toolbar=0,status=0,width=626,height=436");
return false;
});
// Non-Flash homepage interactive
var FACTS;
var processFacesClick = function(e) {
if (!FACTS) {
$.ajax({
type: "GET",
url: "/media/xml/flash_homepage.xml",
dataType: "xml",
success: function(xml) {
FACTS = $("facts", xml);
processFacesClick(e);
}
});
} else {
var random = Math.floor(Math.random() * $("fact", FACTS).length);
var fact = $("fact:eq(" + random + ")", FACTS).text();
var popup = $("#home-page-popup").html("" + fact + "");
var left,
top;
if (e.pageX > window.innerWidth / 2) {
left = e.pageX - 325;
} else {
left = e.pageX + 25;
}
if (e.pageY > 562) {
top = 562;
} else {
top = e.pageY;
}
popup.css({
top: top,
left: left
});
popup.click(function() {
location = ($("fact:eq(" + random + ")", FACTS).attr("link"));
});
popup.show();
}
};
$("#faces div").click(processFacesClick);
});