(function($) { 

function isSecure() {
    return window.location.protocol == 'https:';
}

function getHIFUrl(){
    var url="";
    if(isSecure){
        url = "https://";
    }
    else{
        url = "http://";
    }
    return url + "www.healthinsurancefinders.com";
}

function ShowPreview(e, currentListing) {
	    var divwidth = $('#floatDiv').width() + 15; // distance from mouse to right floating div
	    var divheight = $('#floatDiv').height() + 5; // distance from mouse to bottom floating div

	    var folderpath = $("#thumbsdefaultpath").val();
	    var filename = $(currentListing).find('input[name*=previewimage]').attr('value').split('/').pop();
	    var hifUrl= getHIFUrl();

	    var fullpath = "";
	    if (typeof (eval("folderpath")) != 'undefined')	    
	        fullpath = folderpath + filename;
	    else
	        fullpath = $(currentListing).find('input[name*=previewimage]').attr('value');

	    // get client window size
	    var relativeX = e.clientX + divwidth;
	    var relativeY = e.clientY + divheight;
	    var windowX = $(window).width();
	    var windowY = $(window).height();

	    if (relativeX > windowX) {
	        var relativeX = e.pageX - divwidth;
	        $("#floatDiv").find('img[name*=floatarrow]').attr({ src: hifUrl + '/images/arrow-right.gif' });
	        $(".arroblack").css("float", "right").css("width", "14px");
	    } else {
	        var relativeX = e.pageX + 15;
	        $("#floatDiv").find('img[name*=floatarrow]').attr({ src: hifUrl + '/images/arrow-left.gif' });
	        $(".arroblack").css("float", "left").css("width", "6px");
	    }
	    if (relativeY > windowY) {
	        var relativeY = e.pageY - divheight;
	        $(".arroblack").css("padding-top", "140px");
	    } else {
	        var relativeY = e.pageY;
	        $(".arroblack").css("padding-top", "15px");
	    }

	    $("#floatDiv").find('img[name*=thumbpreview]').attr({ src: fullpath });
	    $("#floatDiv").css({ "left": relativeX + "px", "top": relativeY + "px" });
	    $("#floatDiv").show();
	}

$('.lilisting .left a').live('mousemove', function(e) {
	    p = getParent(this, 'lilisting');
		ShowPreview(e, p);
	});
$('.lilistingAlt .left a').live('mousemove', function(e) {
	    p = getParent(this, 'lilistingAlt');
		ShowPreview(e, p);
	});

$(document).ready(function() {
    ListingPreviewType = $('#bwapsPreviewType').attr('value');
    if (ListingPreviewType == "hover") {
        $('.bwapslistingContainer').live('mousemove', function(e) {
            ShowPreview(e, this);
        });

        $('.bwapslistingContainer').live('mouseout', function() {
         $("#floatDiv").hide();
         }
        );
    }
});

$('.lilisting .left a').live('mouseout',
 function() {
     $("#floatDiv").hide();
 }
);

$('.lilistingAlt .left a').live('mouseout',
	function() {
	    $("#floatDiv").hide();
	}
);

function ActionReadMore(parentContainerId) {
    $('#' + parentContainerId + '> a').hide();
    $('#' + parentContainerId + '> span').show();
}

function getParent(element, elementToFind) {
	var elementName = $(element).attr('class');
	while (elementName != elementToFind) {
		element = $(element).parent();
		elementName = $(element).attr('class');
	}
	return element;
}

})(jQuery)
