/*
 * koodos template javascript methods - requires jquery 1.2.2
 */

// adds corners to specified image object
function applyPhotoBorder( imobj , idnum ){
                var offset = imobj.offset({ border: true, padding: true });

                // apply top left corner
                var idname = "photo_tl" + idnum;
                $("body").append( "<div id=\"" + idname + "\" class=\"photo_tl\"></div>");
                $("#"+idname).css({position:'absolute',top: offset['top'] + 'px', left: offset['left'] + 'px'});

                // apply top right corner
                var idname = "photo_tr" + idnum;
                $("body").append( "<div id=\"" + idname + "\" class=\"photo_tr\"></div>");
                $("#"+idname).css({position:'absolute',top: offset['top'] + 'px', left: ( offset['left'] + 28 + imobj.width() ) + 'px'});

                // apply left edge
                var idname = "photo_left" + idnum;
                $("body").append( "<div id=\"" + idname + "\" class=\"photo_left\"></div>");
                $("#"+idname).css({position:'absolute',top: ( offset['top'] + 28 ) + 'px', left: offset['left'] + 'px', height: imobj.height() + 'px'});

                // apply right edge
                var idname = "photo_right" + idnum;
                $("body").append( "<div id=\"" + idname + "\" class=\"photo_right\"></div>");
                $("#"+idname).css({position:'absolute',top: ( offset['top'] + 28 ) + 'px', left: ( offset['left'] + 28 + imobj.width() ) + 'px', height: imobj.height() + 'px'});

                // apply bottom edge
                var idname = "photo_bottom" + idnum;
                $("body").append( "<div id=\"" + idname + "\" class=\"photo_bottom\"></div>");
                $("#"+idname).css({position:'absolute',top: ( offset['top'] + 28 + imobj.height() ) + 'px', left: offset['left'], width: ( imobj.width() + 28 + 39 ) + 'px', height: '38px'});

                // apply bottom left corner
                var idname = "photo_bl" + idnum;
                $("body").append( "<div id=\"" + idname + "\" class=\"photo_bl\"></div>");
                $("#"+idname).css({position:'absolute',top: ( offset['top'] + 28 + imobj.height() ) + 'px', left: offset['left'], width: '28px', height: '38px'});

                // apply bottom left corner
                var idname = "photo_br" + idnum;
                $("body").append( "<div id=\"" + idname + "\" class=\"photo_br\"></div>");
                $("#"+idname).css({position:'absolute',top: ( offset['top'] + 28 + imobj.height() ) + 'px', left: ( offset['left'] + 28 + imobj.width() ), width: '39px', height: '38px'});

}

function launchSurvey(){
	$("object , embed").each( function(){ $(this).hide(); } );
	$("#bgfade").fadeIn();
	$("#blog-surveycontainer").fadeIn();
}
function hideSurvey(){
	$("#bgfade").fadeOut();
	$("#blog-surveycontainer").fadeOut();
	$("object , embed").each( function(){ $(this).show(); } );
}

$(document).ready( function(){

	/*
	 *  Give 'photoframe' images the rest of the frame
	 */
	$(".photoframe").each( function( i ){applyPhotoBorder( $(this) , i );} );
	/*
	 * on resize, redraw photo frames
	 */
	$(window).bind('resize', function() {
		$("div.photo_tr , div.photo_tl , div.photo_left , div.photo_bl , div.photo_bottom , div.photo_br , div.photo_right").remove();
		$(".photoframe").each( function( i ){applyPhotoBorder( $(this) , i );} );
	} );

	/*
	 * Bind survey launch to survey class links
	 */
	$("a.survey").click( function(){
		launchSurvey();	
	});
	if( window.location.href.toString().indexOf( "takesurvey" ) > -1 ){
		launchSurvey();
	}
	$("a#blog-survey-close").click( function(){
		hideSurvey();
	});

	// if no cookie, launch popup
/*
	if( $.cookie( 'surveypopup' ) != "opened" ){
		$.cookie( 'surveypopup' , 'opened' , { path: '/' } );
		launchSurvey();
	}
*/
} );
