﻿function openSite(url) {
    if (window.opener && !window.opener.closed) {
	    try {
		    window.opener.location = url;
	    } catch(err) { 
    		
	    }
        window.close();
    }
    else { 
        document.location = url;
    }
}

function popUp(theURL, winName, features, myWidth, myHeight, isCenter) {
	if (window.screen) {
		if (isCenter) {
			if (isCenter == "true") {
				var myLeft = ((screen.width-myWidth) / 2);
				var myTop = ((screen.height-myHeight) / 2);
				features += (features!='')?',':'';
				features += ',left=' + myLeft + ',top=' + myTop;
			}
		}
	}
	window.open(theURL, winName, features + ((features!='')?',':'') + 'width=' + myWidth + ',height=' + myHeight);
}

$(function() {
	//homepage i'd like to join button
	var height_homepage_offers = $(".homepage-offers").height();
	var marginTop_homepage_offers = $(".homepage-offers").css("margin-top");
	var height_IdLikeToJoin = $(".IdLikeToJoin").height();

	if (typeof (marginTop_homepage_offers) !== "undefined") {
		var marginTop_IdLikeToJoin = ((height_homepage_offers - height_IdLikeToJoin) / 2) + parseInt(marginTop_homepage_offers.replace("px", ""));
		$(".IdLikeToJoin").css("margin-top", marginTop_IdLikeToJoin);
	}


	//bottom right beige tape
	if (typeof ($(".taped-element").position()) !== "undefined") {
		var positionTop_taped_image = $(".taped-element").position().top;

		if ($(".taped-element").attr("class").indexOf("loft-forum") > -1) {
			positionTop_taped_image = positionTop_taped_image + 20;
		}

		var positionBottom_taped_image = positionTop_taped_image + $(".taped-element").height() + parseInt($(".taped-element").css("padding-top").replace("px", ""));
		$(".beige-tape-bottom").css("top", positionBottom_taped_image - 41);
	}


	$(".loft-forum .entry p:last").addClass("last");


	//set height of comments and sidebar divs on forum page
	var height_comments = $("#comments").height();
	var height_sidebar = $("#sidebar").height();

	if (height_comments > height_sidebar) {
		$("#sidebar").height(height_comments);
	}
	else {
		$("#comments").height(height_sidebar);
	}
});