/* */
/* Layer to close all modals */
/* */
function com_srausc_modal(param) {
	if( $('#modalBackground').length > 0 ){
		$('#modalBackground').remove();
	}
	else {
	    if (! ($.browser.msie && $.browser.version == 7) ) {
		   $('body').append('<div id="modalBackground"></div>');
	    }
		if(param == "ie6") {
		    $('#modalBackground').addClass('modalBackgroundOverride-ie6');
		}
		$('#modalBackground').unbind().click(function() {
			$('#myHealthLogin').animate({top: "-110px"}, 750).removeClass('expanded');
			com_srausc_searchForm_close();
			$('#modalBackground').remove();
			return false;
		});
	}
}

/* */
/* Builds jNice formatted buttons */
/* */
function com_srausc_button(obj) {
	var href = $(obj).attr('href');
	var text = $(obj).text();
	var btnClass = $(obj).attr('class');
	if( $(obj).attr('onclick') ) {
	    var onclick = ' onclick="' + $(obj).attr('onclick') + '"';
	}
	else {
	    var onclick = '';
	}
	if(btnClass == "button")
	    btnClass = "button positive";

	var html = '<button href="'+ href +'" class="'+ btnClass + '"' +
	           onclick + '><span><span>'+ text + '</span></span></button>';
	return html;
}

/* */
/* My Health Login */
/* */
function com_srausc_myhealth() {
    if( $('#myHealthLogin form').length>0 ) {
        $('#myHealthLogin a.panel').unbind('click').click(function() {
            var param = false;
            if( $.browser.msie && parseInt($.browser.version) == 6) {
                var param = "ie6";
            }
            com_srausc_modal(param);
            if( $('#myHealthLogin').attr('class').indexOf('expanded')!=-1 )
                $('#myHealthLogin').removeClass('expanded').animate({top: "-110px"}, 750);
            else
                $('#myHealthLogin').addClass('expanded').animate({top: "5px"}, 500);
            return false;
        }).hover(function() {
            $(this).addClass('hover');
        },function() {
            $(this).removeClass('hover');
        });
        var loginButton = $('<a href="#" class="login">Login</a>').click(function() {
            $('#myHealthLogin').removeClass('expanded').animate({top: "-110px"}, 750);
            $('#user-login-form')[0].submit();
        });
        $('#myHealthLogin a.noAccount').before(loginButton);
    }
}

/* */
/* Search form and drop-down tabs */
/* */
function com_srausc_searchForm_init() {
	// Search form
	$('#search input').val('search').addClass('empty').focus(function() {
		if( $(this).val()=='search' ) $(this).val('').removeClass('empty');
	}).blur(function() {
		if( $(this).val()=='' ) $(this).val('search').addClass('empty');
	});
	$('#searchForm').submit(com_srausc_searchForm);
	$('#search #query')
		.keyup(com_srausc_searchForm_timerStart)
		.after('<a href="#" class="submit"><a/>')
		.after('<a href="#" class="cancel"></a>');
	$('#searchForm a.submit').click(function() {
		$('#searchForm').trigger('submit');
	});
	$('#searchForm a.cancel').click(function() {
		$('#searchForm #query').val('search').addClass('empty');
	});
}

function com_srausc_searchForm_tab(tab) {
	$('#ajaxSearchResults ul.tabs > li').removeClass('active');
	$(tab).parent().addClass('active');

	// Build the URI and stop quickly if another request is on its way.
    var q = $('#query').val(),
        uri = $(tab).attr('href') + encodeURI(q);
    if (_com_srausc_searchForm_uri == uri || q != _com_srausc_searchForm_q) return;
    _com_srausc_searchForm_uri = uri;

	// clear and show loading animation... replacewith to cancel any pending loads.
	$('#ajaxSearchResults ul.results').replaceWith('<ul class="results loading" />');
	$('#ajaxSearchResults ul.results').load(
	   uri,
	   {},
	   function() { //callback
	       $('#ajaxSearchResults ul.results > li').unbind().hover(function() {
        		$(this).addClass('hover');
        	},function() {
        		$(this).removeClass('hover');
        	}).click(function() {
        	    window.location.href = $(this).find('a').attr('href');
        	});
        	if( $('#ajaxSearchResults ul.results').children().length==0 ) {
        	    $('#ajaxSearchResults ul.results').append('<li class="error">Error</li>');
        	}
	       $('#ajaxSearchResults ul.results').removeClass('loading');
	   }
	);

	//change the 'results' link at the bottom accordingly
	$('#ajaxSearchResults div.bottom a').attr('href', '/search?search='+ q);
}
var _com_srausc_searchForm_q = '';
var _com_srausc_searchForm_uri = '';
function com_srausc_searchForm_timerStart() {
    var q = $('#query').val();
    if (q == _com_srausc_searchForm_q || q.length <= 3 || q == "search") {
        return;
    }
    _com_srausc_searchForm_q = q;
    setTimeout("com_srausc_searchForm_timerEnd('" + _com_srausc_searchForm_q + "')", 500);
}
function com_srausc_searchForm_timerEnd(q) {
    if (_com_srausc_searchForm_q != q) return;
    if ($('#ajaxSearchResults ul.tabs').length == 0) {
        com_srausc_searchForm();
    } else {
        com_srausc_searchForm_tab($('#ajaxSearchResults ul.tabs li.active a'));
    }
}
function com_srausc_searchForm_close() {
	com_srausc_modal();
	_com_srausc_searchForm_q = '';
	$('#searchForm #query').val('search').addClass('empty');
	$('#ajaxSearchResults').attr('id','search');
	$('#search div.bottom').remove();
	$('#search ul , #search span.tabsPrefix , #search div.top h4').remove();
}

// Full-page search results
function com_srausc_search_results() {
    $('#content div.searchList').each(function() {
        if( $(this).children('ul').children().length > 3 ) {
            $(this).find('h3').addClass('expandable').prepend('<a href="#" class="hit">Expand</a>');
        }
    });
    $('#content div.searchList h3.expandable a.hit').click(function() {
        if( $(this).parents('div.searchList').hasClass('searchListCollapsed') ) {
            $(this).parents('div.searchList').removeClass('searchListCollapsed');
        }
        else {
            $(this).parents('div.searchList').addClass('searchListCollapsed');
        }
        return false;
    });
}

// Quick Links
function com_srausc_quickLinks() {
	var newValue = $('#quickLinksUri').find('option:selected').val();
	if(newValue != "#") {
		window.location.href=newValue;
	}
}

/* */
/* My Profile */
/* */
function com_srausc_myhealth_profile() {
    // Sections
	$('div.section dl dd:not(.extra)').filter(':last').addClass('extra-last-child');
	$('div.section dl dd.extra-last-child , div.section dl dd:last-child').addClass('last-child');
	// Profile form
	$('#user-edit .form-item .form-item:last').addClass('form-item-last');
	$('#user-edit #edit-profile-address-2').parents('div.form-item').addClass('form-item-offset');

	// Load events from calendar via AJAX
	$('#boxEvents a.close').click(function() {
	    $('body').removeClass('showAllEvents');
	    $('#boxEvents .section ul.list , #boxEvents .section p').remove();
	    $('#boxEvents dl').show();
	    return false;
	});
	$('#boxCalendar .month-view caption > a').attr('href','#');
	$('#boxCalendar .month-view table.event-block td a').each(function() {
	    $(this).click(function() {
	        $('#boxCalendar').css('height',$('#boxCalendar').height()-2).addClass('loading');
	        var date = $(this).attr('href').replace(/^\/event\/(\d+)\/(\d+)\/(\d+)\/.*$/, '$1-$2-$3');
	        $.ajax({
	            url: "/my/health/event?start=" + date + "T00:00:00&end=" + date + "T23:59:59",
	            success: function(data) {
	                $('body').addClass('showAllEvents');
	                $('#boxEvents dl').hide();
	                $('#boxEvents .section').append(data);
	                com_srausc_myHealth_events();
	                $('#boxCalendar').removeClass('loading').css('height','');
	            }
	        });
	        return false;
	    });
	});
}

/* */
/* My Doctors and My News */
/* */
function com_srausc_browse_buttons() {
	// Edit My Account AJAX actions
	$('#body a.button:not(.noAjax)').each(function() {
		var html = com_srausc_button( $(this) );
		var button = $(html).click(function() {
			var thisObj = $(this);
			var href = $(thisObj).attr('href');
			var btnClass = $(thisObj).attr('class');
			if( $(thisObj).hasClass('confirmDel') ) {
			    var confirmDel = confirm('Are you sure you want to delete this item? This action cannot be reversed.');
			    if(!confirmDel) {
			        return;
			    }
			}
			$.ajax({
				url: href,
				success: function(data) {
					if(href.indexOf('/ajax/add/')!=-1) {
						href = href.replace(/ajax\/add/,'ajax/del');
						text = "Remove";
						btnClass = btnClass.replace(/ positive/,' negative');
					}
					else {
						href = href.replace(/ajax\/del/,'ajax/add');
						text = "Add";
						btnClass = btnClass.replace(/ negative/,' positive');
					}
					var json = eval('(' + data + ')');
					if(json['status'] == "ok") {
						if( document.location.href.indexOf('doctor/bio/browseadmin') != -1 ||
							document.location.href.indexOf('my/health/doctor/browse/for') != -1 ||
							document.location.href.indexOf('my/health/news/browse/for') != -1 ) {
					        window.location.reload();
					    }
					    else {
					        $(thisObj).after('<a href="'+ href +'" class="'+ btnClass +'">'+text+'</a>');
					    }
						$(thisObj).remove();
						com_srausc_browse_buttons();
						com_srausc_reapply();
					} else {
						window.alert("There was an error with your request");
					}
				}
			});
			return false;
		});
		$(this).after(button);
		$(this).remove();
	});
}
// for: /doctor/bio/browseadmin
function com_srausc_browse_admin() {
	$('ul.admin a.showMore').click(function() {
		$(this).siblings('dl.desc').toggleClass('expanded');
		return false;
	});
	$('ul.admin dd ul').each(function() {
	    if( $(this).children().length == 1) {
	        $(this).addClass('only-child');
	    }
	});
}

/* */
/* My Groups */
/* */
function com_srausc_myHealth_groups() {
	$('#body a.button:not(.noAjax)').each(function() {
		var html = com_srausc_button( $(this) );
		var button = $(html).click(function() {
			var thisObj = $(this);
			var href = $(thisObj).attr('href');
			var btnClass = $(thisObj).attr('class');
			if( $(thisObj).hasClass('confirmDel') ) {
			    var confirmDel = confirm('Are you sure you want to delete this item? This action cannot be reversed.');
			    if(!confirmDel) {
			        return;
			    }
			}
			$.ajax({
			    url: href,
			    success: function(data) {
			        if(href.indexOf('/ajax/subscribe/')!=-1) {
        				href = href.replace(/ajax\/subscribe/,'ajax/unsubscribe');
        				text = "Leave";
        				btnClass = btnClass.replace(/ positive/,' negative');
        			}
        			else {
        				href = href.replace(/ajax\/unsubscribe/,'ajax/subscribe');
        			    text = "Join";
        				btnClass = btnClass.replace(/ negative/,' positive');
        			}
			        var json = eval('(' + data + ')');
			        if(json['status'] == "ok") {
					    $(thisObj).after('<a href="'+ href +'" class="'+ btnClass +'">'+text+'</a>');
						$(thisObj).remove();
						com_srausc_myHealth_groups();
						com_srausc_reapply();
			        }
			    }
			});
			return false;
		});
	    $(this).after(button);
	    $(this).remove();
	});
}
function com_srausc_myHealth_groups_quickView() {
	var groupSel = $('#groupQuickSelect').children('option:selected').val();
	$('#boxGroups .section , #boxGroups .followup').hide();
	$('#groupPostSection-'+groupSel+' , #groupPostFollowup-'+groupSel).show();
}

/* */
/* My Events */
/* */
function com_srausc_myHealth_events() {
    $('#body a.button:not(.noAjax)').each(function() {
		var html = com_srausc_button( $(this) );
		var button = $(html).click(function() {
			var thisObj = $(this);
			var href = $(thisObj).attr('href');
			var btnClass = $(thisObj).attr('class');
			if( $(thisObj).hasClass('confirmDel') ) {
			    var confirmDel = confirm('Are you sure you want to delete this item? This action cannot be reversed.');
			    if(!confirmDel) {
			        return;
			    }
			}
			$.ajax({
			    url: href,
			    success: function(data) {
			        if(href.indexOf('/ajax/subscribe/')!=-1) {
        				href = href.replace(/ajax\/subscribe/,'ajax/unsubscribe');
        				text = "Unregister";
        				btnClass = btnClass.replace(/ positive/,' negative');
        			}
        			else {
        				href = href.replace(/ajax\/unsubscribe/,'ajax/subscribe');
        			    text = "Register";
        				btnClass = btnClass.replace(/ negative/,' positive');
        			}
			        var json = eval('(' + data + ')');
			        if(json['status'] == "ok") {
			            $(thisObj).after('<a href="'+ href +'" class="'+ btnClass +'">'+text+'</a>');
						$(thisObj).remove();
						com_srausc_myHealth_events();
						com_srausc_reapply();
			        }
			    }
			});
			return false;
		});
	    $(this).after(button);
	    $(this).remove();
	});
}

/* */
/* My Bookmarks */
/* */

// Buttons
function com_srausc_myHealth_bookmarks() {
    if( $('.browseBookmarks ul.list li').length > 0 ) {
        // Bookmarks exist, transform to buttons
    	$('.browseBookmarks a.button:not(.noAjax)').each(function() {
    		var html = com_srausc_button( $(this) );
    		var button = $(html).click(function() {
    			var thisObj = $(this);
    			var href = $(thisObj).attr('href');
    			var btnClass = $(thisObj).attr('class');
    			if( $(thisObj).hasClass('confirmDel') ) {
    			    var confirmDel = confirm('Are you sure you want to delete this item? This action cannot be reversed.');
    			    if(!confirmDel) {
    			        return;
    			    }
    			}
    			$.ajax({
    				url: href,
    				success: function(data) {
    					var json = eval('(' + data + ')');
    					if(json['status'] == "ok") {
    						$(thisObj).parents('li').remove();
    						com_srausc_myHealth_bookmarks();
    					} else {
    						window.alert("There was an error with your request");
    					}
    				}
    			});
    			return false;
    		});
    		$(this).after(button);
    		$(this).remove();
    	});
    }
    else {
        // No bookmarks remaining
        if( $('.browseBookmarks p.nodata').length == 0 ) {
            $('.browseBookmarks div.pagination, .browseBookmarks ul.list').remove();
            $('.browseBookmarks h3').after('<p class="nodata">You have not saved any bookmarks.</p>');
        }
    }
}
// Create bookmark
function com_srausc_bookmarks() {
    $('#bookmark').click(function() {
        $(this).parent().addClass('loading');
        var thisUri = window.location.pathname;
        var ajaxUri = "/createbookmark?uri=" + thisUri;
        var thisObj = $(this);
        $.getJSON(ajaxUri, function(json) {
            $(thisObj).parent().removeClass('loading');
            if(json.status=="ok") {
                window.alert("Bookmark successfully added.");
            }
            else {
                window.alert("Failed to add bookmark. Error code: " + json.status);
            }
        });
        return false;
    });
}

/* */
/* SMF */
/* */
function com_srausc_smf() {
	$('#forumBody a.button').each(function() {
		var html = com_srausc_button( $(this) );
		var button = $(html).click(function() {
			window.location.href = $(this).attr('href');
			return false;
		});
		$(this).after(button);
		$(this).remove();
	});
}

/* */
/* Font Sizer */
/* */
function com_srausc_fontSizer(obj) {
    var newSize = $(obj).attr('id').replace(/fontSizer-/,'');
    $('body').removeClass('fontSize-small , fontSize-normal , fontSize-large').addClass('fontSize-'+newSize);
}

/* */
/* Call functions for various sections of the site */
/* */
function com_srausc_pages() {
	var thisUrl = document.location.href;

	// Find a Doctor
	if(thisUrl.indexOf("/doctor/bio") != -1 ) {
		com_srausc_browse_buttons();
	}
	if(thisUrl.indexOf("/doctor/bio/browseadmin") != -1) {
		com_srausc_browse_admin();
	}
	// My Doctors
	if(thisUrl.indexOf("/my/health/doctor") != -1) {
		com_srausc_browse_buttons();
		$('.block-find-doctors form a.searchButton').click(function() {
		    // Remove previous results
		    $('#body .browseInterface').find('.ajax-list').remove();

		    // Prepare for new results
		    $('#body .browseInterface').addClass('loading');
		    $('#body .browseInterface ul.list').after('<h3 class="ajax-list">Search Results:</h3><ul class="list ajax-list"></ul>');
		    var uri = '/doctor/bio/browse?' +
		              '&specialty=' + encodeURI($('#doctorSearchForm [name=specialty]').val()) +
		              '&location=' + encodeURI($('#doctorSearchForm [name=location]').val()) +
		              '&language=' + encodeURI($('#doctorSearchForm [name=language]').val()) +
		              '&department=' + encodeURI($('#doctorSearchForm [name=department]').val());

		    // Load results
		    $('#body .browseInterface ul.ajax-list').load(uri,{},
		        function() {
		            com_srausc_browse_buttons();
		            var resultCount = $('#body .browseInterface ul.ajax-list').children().length;
		            $('#body .browseInterface ul.ajax-list').before('<div class="pagination ajax-list"><div class="curent">'+ resultCount +' doctors found</div></div>');
		            $('#body .browseInterface').removeClass('loading');
		        }
		    );
			return false;
		});
		$('#body a.showSearch').click(function() {
			$('#body .browseInterface #doctorSearchForm').toggle();
			return false;
		});
	}
	// My Doctors (not)
	if( thisUrl.indexOf("/my/health/doctor") == -1) {
    	$('.block-find-doctors form a.searchButton').click(function() {
    		$(this).parents('form').submit();
    		return false;
    	});
	}
	// My News
	if(thisUrl.indexOf("/my/health/news") != -1) {
		com_srausc_browse_buttons();
	}
	// My Groups
	if(thisUrl.indexOf("/my/health/group") != -1) {
	    com_srausc_myHealth_groups();
	}
	// My Bookmarks
	if(thisUrl.indexOf("/my/health/bookmark") != -1 ||
	   thisUrl.indexOf("/user/") != -1) {
	    com_srausc_myHealth_bookmarks();
	}
	// My Events
	if(thisUrl.indexOf("/my/health/event") != -1) {
	    com_srausc_myHealth_events();
	}
	// My Profile
	if(thisUrl.indexOf("/user") != -1) {
		com_srausc_myhealth_profile();
	}
	// SMF
	if(thisUrl.indexOf("/smf") != -1) {
		com_srausc_smf();
	}
    // Search
    if(thisUrl.indexOf("/search") != -1) {
        com_srausc_search_results();
    }
}

/* Fix buttons after ajax re-builds them */
function com_srausc_reapply() {
    $('#body button').unbind('hover').hover(function() {
		$(this).children('span').addClass('hover');
	},function() {
		$(this).children('span').removeClass('hover');
	});
}

/* Re-size RSS images */
function com_srausc_rss_images() {
	$('#block-pressrelease img').each(function() {
		if( $(this).width() > 188 ) {
			$(this).css('width','188px');
		}
		if( $(this).width() > 0 ) {
			$('#pressReleaseCheck').val('true');
		}
	}).load(function() {
		if( $(this).width() > 188 ) {
			$(this).css('width','188px');
		}
		if( $(this).width() > 0 ) {
			$('#pressReleaseCheck').val('true');
		}
	});
	if( $('#pressReleaseCheck').val() == "false" ) {
		setTimeout("com_srausc_rss_images()", 5000);
	}
}

/* */
/* onLoad() */
/* */
function com_srausc_ready() {
	// Navigation
	$('#nav div.content > ul > li:gt(3)').remove();
	$('#nav div.content > ul > li')
		.each(function() {
		    var id = 'nav_'+$(this).children('a').text().toLowerCase();
		    id = id.replace(/ /g, '_').replace(/\&/g, '_').replace(/&amp;/g, '_');
		    $(this).attr('id', id);

		    $(this).children('a').addClass('parent');
		})
		.hover(function() {
			$(this).addClass('hover');
		},function() {
			$(this).removeClass('hover');
		});
	$('#nav div.content > ul ul.menu li:first-child').addClass('first-child');
	$('#nav div.content > ul ul.menu').append('<li class="last-child"></li>');

	// Login Form, only visible if logged out
	$('#myHealthLogin h4').click(function() {
		window.location.href='/my/health';
	}).hover(function() {
		$(this).addClass('hover');
	},function() {
		$(this).removeClass('hover');
	});
	com_srausc_myhealth();

	// Search
    com_srausc_searchForm_init();

    // Bookmarks
    com_srausc_bookmarks();

	// Pretty forms
	$('#quickLinks').jNice();
	$('#content form')
		.not('#user-admin-account, #block-admin-display, #node-form, #frmTriviaRegister, #frmTriviaLogin, .noJnice')
		.jNice();
	$('#node-form div.container-inline .time .form-item .jNiceSelectWrapper').addClass('jNiceSelectWrapperSmall');
	$('.jNiceInputWrapper input.dp-applied').parents('.jNiceInputWrapper').addClass('jNice-dp-applied');

	// Other buttons
	$('#body a.button').filter('.noAjax').each(function() {
		var html = com_srausc_button( $(this) );
		var button = $(html).click(function() {
    		window.location.href = $(this).attr('href');
    		return false;
    	});
		$(this).after(button);
		$(this).remove();
	});
	$('#body a.button').filter('.inlineAjax').each(function() {
	    var html = com_srausc_button( $(this) );
	    var button = $(html);
	    $(this).after(button);
	    $(this).remove();
	});

	// Font sizer
	$('#foot .innerWrap').append('<div id="fontSizer"><span id="fontSizer-small"></span><span id="fontSizer-normal"></span><span id="fontSizer-large"></span></div>');
	$('#fontSizer span').hover(function() {
	    $(this).addClass('hover');
    },function() {
        $(this).removeClass('hover');
    }).click(function() {
        com_srausc_fontSizer( $(this) );
        return false;
    });

	// Collapsible menus
	if( $('#block-user-1').length > 0 ) {
    	$('#block-user-1 div.content > ul.menu')
    		.removeClass('menu')
    		.find('li').removeClass().end()
    		.find('ul.menu').removeClass('menu');
    	$('#block-user-1 div.content > ul').treeview({
    		collapsed: true,
    		unqiue: true,
    		persist: "location"
    	});
    	$('#block-user-1 div.content').addClass('treeview-applied');
	}

	// Miscellaneous
	$('#sidebar ul.menu a.active').parent().addClass('active');
	$('#sidebar ul.menu ul.menu a.active').parent().parents('li.expanded').addClass('active');
	$('div.event-calendar table tr :last-child').addClass('last-child');
	$('.browseIndex h2.IndexSectionHeader').next('li').addClass('azList');
	$('#node-admin-nodes div.jNiceSelectWrapper').css('z-index','80');
	if( $('#block-pressrelease .rssViewMedia').length ) {
		$('#block-pressrelease').append('<input id="pressReleaseCheck" type="hidden" value="false" />');
		com_srausc_rss_images();
	}
	$('.rssMenuFilterYear').addClass('rssFloatApplied').after('<div class="clear"></div>');

	// Misc: Contact Us thickbox
	$('a[@href="/contactus"]').click(function() {
	    tb_show("", "/contactus?KeepThis=true&TB_iframe=true&height=500&width=480", false);
	    return false;
	});

	// Misc: IE7
	if( $.browser.msie && parseInt($.browser.version) == 7 ) {
	    $('#query').css('paddingTop','4px').css('paddingBottom','1px');
	}
}

function check_page_height() {
    var h = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.offsetHeight);
    if( $('#wrap').height() < h ) {
	    $('#content').css('minHeight', h-195 );
	}
	setTimeout("check_page_height()", 2500);
}

/* ---------------
 * THICKBOX
 * --------------- */

function srausc_thickbox_static_show(title, rel) {
    if(!title) var title = '';
    if(!rel) return;
    var tb_static_id = rel.replace(/.*inlineId=(.*).*/, '$1');

    // Chrome login
    if (tb_static_id == 'tb_login') {
        $('#tb_login *').show();
    }

    // Show thickbox
    var tb_static_html = $('#'+ tb_static_id).children().clone(true);
    //$('#'+ tb_static_id).hide();
    tb_show(title, '#TB_inline?'+ rel, false);
    $('#'+ tb_static_id).append(tb_static_html);

    // Mac FF hack
    //if(tb_detectMacXFF2()) {
    //    $('html, body').animate({scrollTop:0}, 'slow');
    //}
}

function srausc_tb_closeAndGo(url) {
	tb_remove();
	window.location = url;
}


// Load
$(document).ready(function() {
	com_srausc_ready();

	com_srausc_pages();

	com_srausc_reapply();

	// Check page height
	check_page_height();

	// Replace _media images with SWF
	var i = 0;
    $('img[src*=/_images/_media/]').each(function(){
        var uri = $(this)[0].src, id='swf_'+(i++), flashvars={};
        $(this).wrap('<div class="swfAutoload loading" id="' + id + '"></div>');
        uri = uri.substring(uri.indexOf('/_media/'), uri.lastIndexOf('.'))+'.swf';
        swfobject.embedSWF(uri, id, $(this).width(), $(this).height(), "8.0", "/jsx/ext/swfobject/expressInstall.swf", flashvars,
            {quality: "high", scale: "noscale", wmode: "transparent"});
    });

    	// Make related videos open in thickbox
    $('div.other-related-info li.list_spacing.video a, #homeCol2 .videos-wrap .video a').click(function(){
    	var title = $(this).text();

    	if (! title) {
    		title = $('h4.title', $(this).parent()).text();
    	}

    	var url = $(this).attr('href')+'?noWrap=1&KeepThis=true&TB_iframe=true&height=337&width=852';
    	tb_show(title, url);
    	$('#TB_window').addClass('relatedVideo');
    	return false;
    });

    $('body.video form#node-form').submit(function(){
    	var val = $('#edit-taxonomy-20003').val();
    	if (!val || (val.length===1 && val[0]==="")) {
    		alert("At least 1 'Site Settings' category must be selected, though you may choose as many as necessary.");
    		$('#edit-taxonomy-20003').focus();
    		return false;
    	}
    });

     // External links
     var activeDomain = window.location.href.replace(/\.(com|org|net)\/.*/,'.$1').replace(/http:\/\//,'');
     $("#content a[@href^=http]").not("[@href*='"+activeDomain+"']").not('.no-ext-link').addClass('extLink').attr('target','_blank');
     $("#nav a[@href^=http]").not("[@href*='"+activeDomain+"']").attr('target','_blank');

     // PDF Links
     $('#content a[@href*=.pdf]').not('.iconFile_pdf').removeClass('extLink').addClass('fileIcon_pdf');
});

