var $j =  jQuery.noConflict();
var popup = false;

(function ($j) {
// VERTICALLY ALIGN FUNCTION
$j.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $j(this).height();
	var ph = $j("#pageWrap").height();
	var mh = (ph - ah) / 2;
	$j(this).css('margin-top', mh);
	});
};
})(jQuery);

function ajaxPopClose(){
	$j(".indsList select").css("display", "block");
	$j(".ajaxPopWeb").fadeOut(400);
	$j(".overflow").remove();
	$j("#video").remove();
	popup = false;
	return false;	
}

function ajaxPopup(){
		
		$j("a[rel='webMain']").each(function(i){ 
			//alert("add event");
			$j(this).click(function(){return changePopup(i, 'webMain')});
		});

		$j("a[rel='webIndustry']").each(function(i){ 
			$j(this).click(function(){ return changePopup(i, 'webIndustry') });
		});
		
		
}

function changePopup(i, block){

	rev = $j("a[rel='"+block+"']")[i].rev;

	var obj = { blockName: block, entryIndex: i };

	new Request({
		url: "http://www.lifelinedesign.ca/Portfolio/includes/popup_block.php",
		method: 'post',
		data: { entry: rev },
		async: false,
		onSuccess: function(responseText){ 

			//alert("el - "+this.entryIndex+" of " + ($j("a[rel='"+this.blockName+"']").length - 1));
			$('ajaxPop').innerHTML = responseText;


			if(!popup){
				$j("body").prepend("<div class='overflow'> </div>");
				
				$j(".indsList select").css("display", "none");
				$j(".content").css("z-index", "1");
				
				$j(".overflow").css("height", $j("body").height()).css("width", $j("body").width());
				$j(".overflow").css("margin-left", "0");
				
				//$j(".overflow").css("position", "absolute").css("z-index", "90");
				
				$j(".ajaxPopWeb").vAlign();
				$j(".ajaxPopWeb").fadeIn(400).css("z-index", "100");
				popup = true;
			}

			if(this.entryIndex < ($j("a[rel='"+this.blockName+"']").length - 1)){ 
				$('nextButton').style.display = "block";
				$('nextButton').addEvent("click", function(){ changePopup((this.entryIndex+1), this.blockName)}.bind(this) );  
			}else $('nextButton').style.display = "none";

			if(this.entryIndex > 0){ 
				$('prevButton').style.display = "block";
				$('prevButton').addEvent("click", function(){ changePopup((this.entryIndex-1), this.blockName)}.bind(this) );  
			}else $('prevButton').style.display = "none";

		}.bind(obj)

	}).send();



	return false;
}

function updateLinks(i, block){
	alert("update links");
	/*
	*/
}

$j(document).ready(ajaxPopup);

function ajaxPopupTestimonial(){
	
		$j("a[rel='testimonial']").click(function(){

			rev = this.rev

			new Request({
				url: "http://www.lifelinedesign.ca/Portfolio/includes/testimonial_popup_block.php",
				method: 'post',
				data: { entry: rev },
				async: false,
				onSuccess: function(responseText){ 
					$('ajaxPop').innerHTML = responseText;
				}
			}).send();

			$j("body").prepend("<div class='overflow'> </div>");
			$j(".indsList select").css("display", "none");
			$j(".content").css("z-index", "1");
			$j(".overflow").css("height", $j("body").height()).css("width", $j("body").width());
			$j(".overflow").css("margin-left", "0");
			$j(".ajaxPopWeb").vAlign();
			$j(".ajaxPopWeb").fadeIn(400).css("z-index", "100");
		
			return false;
		})
}

$j(document).ready(ajaxPopupTestimonial);


function ajaxPopupSeo(){
	
		$j(".indvBox a[rel='seo']").click(function(){
			$j("body").prepend("<div class='overflow'> </div>");
			$j(".indsList select").css("display", "none");
			$j(".content").css("z-index", "1");
			$j(".overflow").css("height", $j("body").height()).css("width", $j("body").width());
			$j(".overflow").css("position", "absolute").css("z-index", "90");
			$j(".ajaxPopSeo").vAlign();
			$j(".ajaxPopSeo").fadeIn(400).css("z-index", "100");
			return false;
		})
		$j("a.close").click(function(){
			$j(".indsList select").css("display", "block");
			$j(".ajaxPopSeo").fadeOut(400);
			$j(".overflow").remove();
			return false;
		})
}

//$j(document).ready(ajaxPopupSeo);

function ajaxPopupPrint(){

		$j(".indvBox a[rel='print']").click(function(){
			$j("body").prepend("<div class='overflow'> </div>");
			$j(".indsList select").css("display", "none");
			$j(".content").css("z-index", "1");
			$j(".overflow").css("height", $j("body").height()).css("width", $j("body").width());
			$j(".overflow").css("position", "absolute").css("z-index", "90");
			$j(".ajaxPopPrint").vAlign();
			$j(".ajaxPopPrint").fadeIn(400).css("z-index", "100");
			return false;
		})
		$j("a.close").click(function(){
			$j(".indsList select").css("display", "block");
			$j(".ajaxPopPrint").fadeOut(400);
			$j(".overflow").remove();
			return false;
		})	
}
//$j(document).ready(ajaxPopupPrint);

function equalH(group){
	tallest = 0;
	group.each(function(){
		thisHeight = $j(this).height();
		if(thisHeight > tallest){
				tallest = thisHeight;
		}
	});
	group.height(tallest);
}

$j(document).ready(function(){
	$j(".contentZone > div:lt(2)").css("marginTop", "0px");
	equalH($j(".contentZone .box"));
})



	
function viewExtended(newSrc, curSrc) {
	
	$('video').innerHTML = '<embed src="'+newSrc+'" type="application/x-shockwave-flash"  width="300" height="240" allowscriptaccess="always" allowfullscreen="true"></embed>';
	$('video').innerHTML = $('video').innerHTML + '<a class="extendedLink" href="javascript:;" onclick="viewOriginal(\''+curSrc+'\', \''+newSrc+'\');">View Original Clip</a>';
	
}

function viewOriginal(newSrc, curSrc) {
	
	$('video').innerHTML = '<embed src="'+newSrc+'" type="application/x-shockwave-flash"  width="300" height="240" allowscriptaccess="always" allowfullscreen="true"></embed>';
	$('video').innerHTML = $('video').innerHTML + '<a class="extendedLink" href="javascript:;" onclick="viewExtended(\''+curSrc+'\', \''+newSrc+'\');">View Full Video</a>';
	
}