 $(document).ready(function(){
	var wl = window.location+'';
	if (wl.toLowerCase().indexOf('/backendpopall/') == -1)
		mainMenuNav();
	prepareLinks();
    qtip();
    basketchange();
});


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;
    });
}

//adding social media thanks to http://www.hardcode.nl/archives_139/article_420-social-media-icon-script
function socialmedia(){
    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: 'LinkedIn', icon:'linkedin.png',href:'http://www.linkedin.com/shareArticle?mini=true&url='+u+'&title='+t},
                {linkText: 'Digg', icon:'digg.png',href:'http://digg.com/submit?phase=2&url='+u+'&title='+t},
    			{linkText: 'Stumbleupon', icon:'stumbleupon.png',href:'http://www.stumbleupon.com/submit?url='+u},
    			{linkText: 'Google', icon:'google.png',href:'http://www.google.com/bookmarks/mark?op=edit&bkmk='+u},
    			{linkText: 'Twitter', icon:'twitter.png',href:'http://twitter.com/home?status='+u},
    			{linkText: 'Facebook', icon:'facebook.png',href:'http://www.facebook.com/share.php?u='+u}
    		];

    		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.prepend('<div id="share_this" class="social"><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($('#footer_content'));
};

function qtip(){

$('.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' } }

})
};



/*using JS for menu so that we can control over and out delays. 
IF people go over the menu too quickly it won't show by adding a sfHover class we know which <li> to use. This uses the hoverIntent pluginb*/
/*THISISONEVERYPAGE*/
function mainMenuNav()
{
	var config = 
	{
  	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
	interval: 90, // number = milliseconds for onMouseOver polling interval

	over: function() {
     		$(this).addClass('sfHover');
		},
	timeout: 305, // number = milliseconds delay before onMouseOut
	out: function() {
     		$(this).removeClass('sfHover');}
	}
	$('#mainnav li, #topnav li')
		.hoverIntent(config);
}


function basketchange(){

	$('.changed').fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();


}
