/***************************************************
	     SCROLL TO TOP JAVASCRIPT
***************************************************/	
jQuery(document).ready(function($){
    $('a[href=#top]').click(function() {
	    $('html,body').animate({scrollTop: 0}, 500);
        return false;
    });
});

/***************************************************
	     SCROLL TO OTHER AREAS
***************************************************/	
jQuery(document).ready(function($){
	$('a[href=#jump_to_news_feed]').click(function() {
	    $('html,body').animate({scrollTop: ($(".jump_to_news_feed").offset().top - 90)}, 500);
        return false;
    });
	$('a[href=#jump_to_special_offers]').click(function() {
	    $('html,body').animate({scrollTop: ($('.jump_to_special_offers').offset().top - 50)}, 500);
        return false;
    });
	$('a[href=#jump_to_doctor_listings]').click(function() {
	    $('html,body').animate({scrollTop: ($(".jump_to_doctor_listings").offset().top - 50)}, 500);
        return false;
    });
});

/***************************************************
	     STYLESWITCH JAVASCRIPT
***************************************************/
jQuery(document).ready(function($){
	$('a[rel="chooseStyle"]').click(function() {
	    var color_theme = $(this).attr("href");
		$("head").append("<link>");
    	css = $("head").children(":last");
    	css.attr({
      		rel:  "stylesheet",
      		type: "text/css",
      		href: color_theme
    	});
        return false;
    });
});



/***************************************************
		  DROPDOWN MENU
***************************************************/
	/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);





/***************************************************
	     ADDITIONAL CODE FOR DROPDOWN MENU
***************************************************/
    jQuery(document).ready(function($) { 
        $('ul.menu').superfish({ 
            delay:       100,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  true                           // disable generation of arrow mark-up 
        });
		
		$("ul#primary-menu li ul li:last-child a").addClass("last");
    }); 





/***************************************************
	    THUMB PORTFOLIO HOVER
***************************************************/
jQuery(document).ready(function($) {
	$(".portfolio-item-thumb").hover(function(){
		$(this).find(".item-links").stop(true, true).animate({ opacity: 'show' }, 400);
	}, function() {
		$(this).find(".item-links").stop(true, true).animate({ opacity: 'hide' }, 400);		
	});
});
 




/***************************************************
		CUSTOM FORM ELEMENTS JAVASCRIPT
***************************************************/
/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only things you may need to change in this file are the following
variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

The numbers you set for checkboxHeight and radioHeight should be one quarter
of the total height of the image want to use for checkboxes and radio
buttons. Both images should contain the four stages of both inputs stacked
on top of each other in this order: unchecked, unchecked-clicked, checked,
checked-clicked.

You may need to adjust your images a bit if there is a slight vertical
movement during the different stages of the button activation.

The value of selectWidth should be the width of your select list image.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";


/* No need to change anything after this */


document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				if(!inputs[a].getAttribute("disabled")) {
					span[a].onmousedown = Custom.pushed;
					span[a].onmouseup = Custom.check;
				} else {
					span[a].className = span[a].className += " disabled";
				}
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				if(!inputs[a].getAttribute("disabled")) {
					inputs[a].onchange = Custom.choose;
				} else {
					inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
				}
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;







/***************************************************
             Info box by Brankic1979
***************************************************/
jQuery(document).ready(function($) {	
	$(".info-box").each(function (i) {	
	var info_box_height = $(this).height();
	//alert(info_box_height);
	//var this_el = $(this);
	var left_height = $(this).children('div.left').height();
	var right_height = $(this).children('div.right').height();
	//alert(info_box_height + " " + left_height + " " + right_height);
	var margin_top = (parseInt(info_box_height / 2) - parseInt(left_height / 2)) - 20;
	margin_top = margin_top + "px";
	$(this).children('div.left').css({ 
		marginTop: function(index) {
			//alert(margin_left)
        return margin_top},
		//display: "block",
      });	
	var margin_top = (parseInt(info_box_height / 2) - parseInt(right_height / 2)) - 20;
	margin_top = margin_top + "px";
	$(this).children('div.right').css({ 
		marginTop: function(index) {
			//alert(margin_left)
        return margin_top},
		//display: "block",
      });
	var padding_top_bottom = parseInt(((parseInt(info_box_height / 2) - parseInt(right_height / 2))) / 1);
	padding_top_bottom = padding_top_bottom + "px";
	$(this).children('div.colored').css({ 
		paddingTop: function(index) {
			//alert(margin_left)
        return padding_top_bottom},
		paddingBottom: function(index) {
			//alert(margin_left)
        return padding_top_bottom},
		marginTop: function(index) {
			//alert(margin_left)
        return '0px'},
      });						
 })						
})


jQuery(document).ready(function($) {				
	var intro_holder_height = $("#intro-holder").height();
	var intro_right_height = $('#intro_right').height();
	var margin_top = parseInt(intro_holder_height / 2) - parseInt(intro_right_height / 2) + 0;
	margin_top = margin_top + "px";
	$('#intro_right').css({ 
		marginTop: function(index) {
        return margin_top},
      });						
})


jQuery(document).ready(function($) {	
	var tempic = "";
	$(".portfolio-item-thumb a").each(function (i) {	
	
	var rel_value = $(this).attr("rel");
	
	//alert(rel_value + " | " + tempic);
	
	//alert($(this));
	
	if (rel_value != "") { 
	
	//alert(rel_value + " | " + tempic);
	
	if (tempic == rel_value) {
	// remove this a element
	//alert(rel_value);
	//$(this).remove();
	}
	
	tempic = rel_value;

	}

					
 })						
})

/***************************************************
	 SOMETHING ADDITIONAL
***************************************************/	
jQuery(document).ready(function($){
	//$("img.attachment-post-thumbnail").addClass("icon-left");
	$("#sidebar div.block ul").addClass("list");
	$("img.avatar").addClass("shadow");
	$("img.avatar").addClass("border");
	$("ol.commentlist li:last-child").addClass("last");
	$(".block ul li:last-child").addClass("last");
	$("#footer div.one-fourth ul.details").addClass("latest-posts");
	$('div#navigation ul li a[rel="next"]').addClass("next");
	$('div#navigation ul li a[rel="prev"]').addClass("prev");
	

var post_entry_width = $(".post-entry").width();
//resize image if it is wider than post-entry
$('.post-entry img').each(function() {
    var imgSrc = $(this).attr("src");
	var w = $(this).width();
	var h = $(this).height();
	
	if (w > post_entry_width)
	{
		var new_w = post_entry_width;
		var new_h = parseInt((post_entry_width * h) / w); 
		$(this).width(new_w);
		$(this).height(new_h);
	}
	
	
  });

});


/***************************************************
	 PRELOAD BUTTON HOVER STATE IMAGES
***************************************************/
var buttonImages = new Array();
function preloadButtonImages() {
	for (i = 0; i < preloadButtonImages.arguments.length; i++) {
		buttonImages[i] = new Image();
		buttonImages[i].src = preloadButtonImages.arguments[i];
	}
};
preloadButtonImages(
	"http://www.medsoup.org/wpdev/wp-content/themes/medsouptheme/images/Button_About_Hover.png",
	"http://www.medsoup.org/wpdev/wp-content/themes/medsouptheme/images/Button_Explore_Hover.png",
	"http://www.medsoup.org/wpdev/wp-content/themes/medsouptheme/images/Button_Signup_Hover.png",
	"http://www.medsoup.org/wpdev/wp-content/themes/medsouptheme/images/Button_News_Hover.png",
	"http://www.medsoup.org/wpdev/wp-content/themes/medsouptheme/images/Button_Offers_Hover.png",
	"http://www.medsoup.org/wpdev/wp-content/themes/medsouptheme/images/Button_Doctors_Hover.png"
);
