$(window).load(function () {
	prepareLinks();
	highlightNav();

});

function prepareLinks()
{

	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++)
	{
		if (links[i].getAttribute("className"))
		{
			if (links[i].getAttribute("classname") == "external") 
			{
				if (links[i].getAttribute('title') == '' || links[i].getAttribute('title') == null)
					links[i].setAttribute("title","(opens in a new window)");
			}
			else if (links[i].getAttribute('classname').substring(0,6) == 'popup_')
				links[i].setAttribute('title','this is a popup');
		}
		else if (links[i].getAttribute("class"))
		{
			if (links[i].getAttribute("class") == "external")
			{
				if (links[i].getAttribute('title') == '' || links[i].getAttribute('title') == null)
					links[i].setAttribute("title","(opens in a new window)");
			}
			else if (links[i].getAttribute('class').substring(0,6) == 'popup_')
				links[i].setAttribute('title','this is a popup');
		}
	}
	
	$('a.external').click(function()
	{
	     window.open(this.href);
    	 return false;
    });

	$("a[class^='popup_']").click(function(event)
	{
    	var prop = event.target.className;
        var w = prop.split('_')[1];
        var h = prop.split('_')[2];
        window.open(this.href,'','menubar=0,location=0,scrollbars=1,toolbar=0,status=0,directories=0,titlebar=0,width='+w+',height='+h);
        return false;
    });
}


function highlightNav(){
	var path = location.pathname;//filename
    //deals with acnhorrs
	if (location.search){
		path += location.search;//take path and location
	}

	$(".dohighlightnav a[href='" + [ path ] + "']").parents("li").each(function() {
        $(this).addClass("onpage");
    });
}

 $(document).ready(function(){
//adding social media thanks to http://www.hardcode.nl/archives_139/article_420-social-media-icon-script

drawSocialLinks = function(oContainers){
    	var l,i,socialList = [], socialHtm='';
    	var t = $('h1').eq(0).text();   /*  adjust this to select the title of your article */
    	var u = document.location.href;  /*  this selects the link to your article */
    	//var u = "WERWERWR";  /*  this selects the link to your article */
		var iconDirectory = '/img/icons/socialmedia/'; /* this is the director containing your icons */

		var socialMedia = [
			{linkText: 'Del-icio-us', icon:'delicious.png',href:'http://del.icio.us/post?url='+u+'&title='+t},
			{linkText: 'Stumbleupon', icon:'stumbleupon.png',href:'http://www.stumbleupon.com/submit?url='+u},
			{linkText: 'Facebook', icon:'facebook.png',href:'http://www.facebook.com/share.php?u='+u},
			{linkText: 'Twitter', icon:'twitter.png',href:'http://twitter.com/home?status='+u},
			{linkText: 'Google', icon:'google.png',href:'http://www.google.com/bookmarks/mark?op=edit&bkmk='+u},
			{linkText: 'LinkedIn', icon:'linkedin.png',href:'http://www.linkedin.com/shareArticle?mini=true&url='+u+'&title='+t}
		];

		l = socialMedia.length;
		for (i=0; i<l;i++){
		//	socialList.push('<li><a href="'+socialMedia[i].href+'" title="'+socialMedia[i].linkText+'"><img src ="'+this.webRoot+iconDirectory+socialMedia[i].icon+'" alt="'+socialMedia[i].linkText+'" /></a></li>');
			socialList.push('<li><a href="'+socialMedia[i].href+'" title="'+socialMedia[i].linkText+'"><img src ="'+iconDirectory+socialMedia[i].icon+'" alt="'+socialMedia[i].linkText+'" width="26px" /></a></li>');
		}
		socialHtm = '<ul>'+socialList.join("\n")+'</ul>';
		oContainers.append('<div class="share_this general_box"><h2>Share This Page:</h2>'+socialHtm+'<p title="These sites allow you to tag, share and store links across the internet." class="tool_tip_trigger_click">What is this?</p></div>');
    }
drawSocialLinks($('body.show_share #main_content'));


$('.tool_tip_trigger_hover[title]').qtip({
   show: 'mouseover',
   hide: 'mouseout',
     position: {
        corner: {
           target: 'topLeft',
           tooltip: 'bottomLeft'
        }
     },
     style: {
        name: 'dark', // Inherit from preset style
        //width: 340,
        //padding: 5,
        tip: 'bottomLeft',
        border: {
           width: 1,
           radius: 5
        }
     }
})

$('.tool_tip_trigger_click[title]').qtip({
    content: {
        title: {
          text: '&nbsp;',
          button: '<span onclick=\"return false\">Close this box</span>'
        }
      },
     style: {
        name: 'dark', // Inherit from preset style
        width: 340,
        padding: 5,
        tip: 'bottomLeft',
        border: {
           width: 1,
           radius: 5
        }
     },
     position: {
        corner: {
           target: 'topLeft',
           tooltip: 'bottomLeft'
        }
     },
     show: {
            when: { event: 'click' },
            solo: true
           },
     hide: { when: { event: 'unfocus' } }
})




/*DVD TAKEN OFF $('.tool_tip_trigger_dvd_info').qtip({

      content: {
        //url: '/RunYourOwnPub/DVDInformationPack.aspx',
        title: {
          text: 'DVD Information Pack: ',
          button: '<span onclick=\"return false\">Close this box</span>'
        }
      },
      api: {
      onRender: function() {
         this.elements.content.load('/RunYourOwnPub/DVDInformationPack.aspx #for_contact_form');
      }
    },
     style: {
        name: 'dark', // Inherit from preset style
        width: 420,
        padding: 5,
        tip: 'topRight',
        border: {
           width: 1,
           radius: 5
        }
     },
     position: {
        corner: {
           target: 'topRight',
           tooltip: 'topRight'
        },
        adjust: {  x: 0,
                   y: 12
           }

     },
     prerender: true,
        show: {
            when: { event: 'click' },
            solo: true
        },
     hide: { when: { event: 'unfocus' } }

})*/


 });