/*get the instance of the last "/" in the url - this gives us portability*/
var docUrl = document.URL.substring(0,(document.URL.lastIndexOf('/')));

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function checkVersion() {
    var ret = 1;
    var ver = getInternetExplorerVersion();
    if (ver > -1) {
        if (ver >= 8.0)
            ret = 2;
        else
            ret = 1;
    } else {
    ret = 2;
	}
	return ret;
}


$(document).ready(function() {
var docUrl = "http://"+document.domain;

//do the background element


//do the header - we'll extract the charcode from the title, recreate it from similarly-named png icons and hide the text version. Makes it easier to edit.
$('h3.title').hide();

var str = $('h3.title').html();
var strArr = new Array(); 
for (i=0;i<str.length;i++) {
strArr.push(str.charCodeAt(i)); }
//add the container element to the header
var brows = checkVersion()

if (brows > 1) {

$('.menuspacer').prepend('<div id="titleholder"></div>');
//iterate the array, create the string and stick the text in the correct box

for (k in strArr) {
var img = strArr[k]+".png";
var path = docUrl+"/wp-content/themes/GargoylePie/img/skia/"+img;
$('#titleholder').append('<img src="'+path+'" alt="'+String.fromCharCode(strArr[k])+'" />');
}

}

$('a.footerlink, span.copy').each(function() {
var ftr = $(this).html();
var ftrArr = new Array();
for (i=0;i<ftr.length;i++) {
ftrArr.push(ftr.charCodeAt(i));
}

$(this).html('');


for (c in ftrArr) {
var img = ftrArr[c]+".png";
var path = docUrl+"/wp-content/themes/GargoylePie/img/skia/"+img;
$(this).append('<img src="'+path+'" alt="'+String.fromCharCode(ftrArr[c])+'" />');
}

});

if ($('.menuspacerfooter').length > 0) {
$('#titleholder').css('width','358px');
} else {
$('#titleholder').css('width','896px');
}
if ($('#contentbox_searchbox').length > 0) {
$('#titleholder').css('width','974px');
}

if ($('#img_footer').length > 0) {//we need to change the style slightly for this one
var mpos = $('#img_footer').position();
//remove the footerdiv border and replace it with a horizontal div to recreate the line effect.
$('#footerdiv > p').css('border-top','0px');
}

if($('#ur_bottom_content').length > 0) {
//set the middle paragraph widths
$('.ur_short_desc, .ur_long_desc').css('width',$('.ur_display_area').width() - ($('#ur_rh_bar').width()+50)+ 'px'); 


//do the heights and lines
var lpos = $('.ur_contact_content').position();
var rpos = $('#ur_location_desc').position();
var dwidth = rpos.left - (lpos.left+4);
var lheight = lpos.top - rpos.top;
$('#ur_location_desc').css('height',lheight-5+'px');
$('#maincontent').append('<div class=\"horizlineGreen\"></div>');
$('.horizlineGreen').css('height','1px').css('width',dwidth+'px').css('background-color','#016701').css('position','absolute').css('left',lpos.left+5+'px').css('top',lpos.top+'px');
}

//Move the large image 9000 pixels to the right until it's loaded inand the attributes can be accessed.

$('.popupImg img').css('visibility', 'hidden');


}); //end ready


$(window).load(function() {

// The function for the small bottom-right-hand image that launch a popup bubble with the big image in it when moused over. 

$('.popupImg img').css('visibility', 'visible');

var enlargeImage = $('.popupImg img');

enlargeImage.removeAttr("width");
enlargeImage.removeAttr("height");

var origWidth = enlargeImage.width();
var origHeight = enlargeImage.height();

enlargeImage.width(140);
enlargeImage.height(80);

var newWidth = (origWidth+'px');
var newHeight = (origHeight+'px');
var newMarTop = (((origHeight-30)*-1)+'px');
var newMarLeft = (((origWidth+30)*-1)+'px');

// Function to create the animation on the larger image

$('#img_footer').hover(function(){

 
	       //stops the event from happening in case of an abrupt mouseOut
            enlargeImage.stop();
			

            //custom animation effect to change the width and height of the img
            enlargeImage.animate({

				width: newWidth,
                height: newHeight,
				marginTop: newMarTop,  
				marginLeft: newMarLeft
				
                //space the animation out over 1 sec (deals in milliseconds)
            },400); 
	
			
			
  },
  //this is just like a mouseOut effect to take the img back to the original size
  function(){

			
             //stops the event from happening in case of an abrupt mouseOut
             enlargeImage.stop();
			 enlargeImage.removeShadow();
                //this animation shrinks the image back to original size
               enlargeImage .animate({
			   
                    width: '140px',
                    height: '80px',
					marginTop: '0px', 
					marginLeft: '0px'

                },200);
				
				
				//$('.popupImg').hide();

  });

});


