var theTip = new Object();

theTip.tip1 = "<div class=\"tip-content\"><h3>Remember me on this PC</h3><p>s1jobs now allows you to stay permanently \'signed in\' to your account, saving the need to <nobr>re-enter</nobr> your password every time you visit.</p><p><strong>You should not use this feature if you're on a public or shared computer</strong>, since this would give other users access to your account.</p></div>";

theTip.tip2 = "<div class=\"tip-content\"><p>The Herald &amp; Times Group is Scotland's leading multimedia publisher.  Its titles include The Herald, Sunday Herald and Evening Times, plus the s1 family of websites.</p></div>";

theTip.tip3 ="<div class=\"tip-content\"><h3>Making your CV anonymous</h3><p><strong>Remember to remove details from your CV which would reveal your identity</strong>.</p><p>We recommend that you remove your name, contact details (including email address) and the name of your most recent employer.</p><p><strong>Note:</strong> If you don't want to change your CV then you should use Option 2: Career Profile</p></div>"

theTip.tip4 ="<div class=\"tip-content\"><p>Our text messaging services include job alerts by SMS. Don't worry, entering your mobile number here will not automatically subscribe you for any mobile services.</p></div>"

theTip.tip5 ="<div class=\"tip-content\"><p>Candidate Database is our database of over 130,000 Scottish job seekers.  This is separate to a job posting account.  If you would like access, simply contact our sales team.</p></div>"

theTip.tip6 ="<div class=\"tip-content\"><p>You followed up this job on an external site.</p></div>"

theTip.tip7 ="<div class=\"tip-content\"><p>Get an email 2 or 3 days before a job closes to remind you to apply on time.</p></div>"

theTip.tip8 ="<div class=\"tip-content\"><p>A single job credit, which allows you to post one vacancy for 2 weeks, costs just &pound;299 +VAT.</p><p>It costs &pound;270 +VAT per listing if you buy more than one vacancy.</p><p>You don't need to use all the job credits now – you have up to a year to use them.</p></div>" 
 

$(window).load(function() {

    $('<div id="dyn-tip"><div class="close-tip"><a href="#" id="close-tip">x</a></div> <div class="tip-content"></div><div style="line-height:0;"><img width="18" height="9" class="pointer" alt="" src="/ui/images/general/adv-tip-arrow.png"/></div></div>').insertAfter('#wrapper');

    function findPos(obj) {
        var curLeft = curTop = 0;
        
        var objHeight = $('#dyn-tip').height();
        var objWidth = $('#dyn-tip').width();        
        
        //alert('height=' + objHeight + ' width=' + objWidth);
        
        if (obj.offsetParent) {
        
            do {
                curLeft += obj.offsetLeft;
                curTop += obj.offsetTop;
            } while (obj = obj.offsetParent);
            
            curLeft = curLeft - (objWidth/2);
            curTop = curTop - (objHeight);
            
			if (curLeft < 10) {
				curLeft = 10
			}
			if (curTop < 10) {
				curTop = 10
			}

			return [curLeft,curTop];
        }
    }
    
    var $tip = $('#dyn-tip');
    
    $('.help').click(function(e) {
    
        e.preventDefault();
		
		var tipID;
		var tipURLArray;
		
		if($tip.css('display') != 'none')
        {
            $tip.hide();
        }
        else
        {
			
            if ($(this).attr('rel')){
				tipID = $(this).attr('rel');		
			} else {
				tipURLArray = $(this).attr('href').split('/');
				tipID = tipURLArray[tipURLArray.length-1];
			}

			$('.tip-content').replaceWith(theTip[tipID]);

			clickPos = findPos(this);
            $tip.css({left:clickPos[0],top:clickPos[1]}).show();        
        }
        return false;
    });

    $('#close-tip').click(function(){
        $('#dyn-tip').hide();
        return false;
    });
});
