$(window).load(function () {
    prepareLinks();
})

function prepareLinks(){
	$('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;
    });
    socialmedia();
}

function popup(x,y,w,h,fn){
	NewWindow = window.open(fn,'descr','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=0,scrollbars=1,resizable=1,copyhistory=no,width='+w+',height='+h+', top='+y+',left='+x)
}

function SignInPopup(){
	NewWindow = window.open('/mypinkuk/login.aspx','descr','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=0,scrollbars=1,resizable=1,copyhistory=no,width=400,height=300, top=100,left=100');
}

function OpenNewWindow(fn){
	NewWindow = window.open(fn)
}

function swapImage(imgID) {
    var img;
    if (document.getElementById(imgID))
        img = imgID;
    else
        img = imgID + 'a';
    document.getElementById(img).setAttribute('src', '/img/' + imgID + 'on.gif');
}

function ImgRestore(imgID){
    var img;
    if (document.getElementById(imgID))
        img = imgID;
    else
        img = imgID + 'a';
    document.getElementById(img).setAttribute('src', '/img/' + imgID + 'off.gif');
}

function menu(whichMenu,whatState){
	menuOut();
	if (whatState == 'visible')
		showDiv(whichMenu);
	else
		hideDiv(whichMenu);
}

function menuOut(){
	hideDiv('listings')
	hideDiv('community')
	hideDiv('classifieds')
	hideDiv('events')
}


function targetBlank(url){
	blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
}

function disablethis(fID){
	fID.disabled = true;
}

function signInForm_click(page,qs,us,pw){
	if (qs !='')
		var url = '/login.aspx?source='+page+'&qs='+qs.replace('&','~~~~~')+'&us='+us+'&pw='+pw;
	else
		var url = '/login.aspx?source='+page+'&us='+us+'&pw='+pw;
	window.location = url;
}

function hideDiv(divid){
	document.getElementById(divid).style.display = 'none';
}

function showDiv(divid) {
	document.getElementById(divid).style.display = 'block';
}

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 */
        if (u.indexOf('#') > -1) {
            u = u.substring(1,u.indexOf('#'))
        }
        var iconDirectory = '/img/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 class="none"><a class="external" 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 id="share_this" class="gen_box">' + socialHtm + '</div>');
    }
    drawSocialLinks($('#sp_socialMedia'));
};
