var jsHTML = window.jsHTML || {};

jsHTML.shareMore = function(_this, _title, _url, _width) {
	var leftCalc = $(_this).offset().left - (_width / 2) + (($(_this).width() + parseInt($(_this).css("padding-left")) + parseInt($(_this).css("padding-right"))) / 2);
	var encodedUrl = encodeURIComponent(_url);
	var charSeparator = encodeURIComponent(_url.indexOf('?') == -1 ? '?' : '&');
	$("body").createAppend('div', {id:'shareMore', className: 'popupBox', style: 'left: ' + leftCalc + 'px; top: ' + ($(_this).offset().top + 15) + 'px; display: none;'}, [
		'div', {className:'title'}, [
			'h2', {}, 'Share this page',
			'div', {className: 'hr'}, ,
			'span', {}, 'Share TVNZ stories on some of the most-popular social networking and content sites on the internet.'
		],
		'a', {href: '#', className:'close'}, 'CLOSE',
		'div', {className:'content'}, [
			'a', {href: 'http://del.icio.us/post?url=' + encodedUrl + charSeparator + 'ref=delicious&title=' + _title, title: 'Bookmark on Delicious', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxDelicious.gif', alt:'Delicious'}],
			'a', {href: 'http://digg.com/submit?url=' + encodedUrl + charSeparator + 'ref=digg&title=' + _title, title: 'Share on Digg', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxDigg.gif', alt:'Digg'}],
			'a', {href: 'https://www.facebook.com/sharer.php?u=' + encodedUrl + charSeparator + 'ref=facebook&t=' + _title, title: 'Share on Facebook', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxFacebook.gif', alt:'Facebook'}],
			'a', {href: 'http://reddit.com/submit?url=' + encodedUrl + charSeparator + 'ref=reddit&title=' + _title, title: 'Share on Reddit', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxReddit.gif', alt:'Reddit'}],
			'a', {href: 'http://www.bebo.com/c/share?Url=' + encodedUrl + charSeparator + 'ref=bebo&Title=' + _title, title: 'Share on Bebo', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBebo2.gif', alt:'Bebo'}],
			'a', {href: 'http://www.newsvine.com/_wine/save?popoff=0&u=' + encodedUrl + charSeparator + 'ref=newsvine&h=' + _title, title: 'Share on Newsvine', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxNewsvine.gif', alt:'Newsvine'}],
			'a', {href: 'http://www.stumbleupon.com/submit?url=' + encodedUrl + charSeparator + 'ref=stumble&title=' + _title, title: 'Share on Stumbleupon', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxStumbleupon.gif', alt:'Stumbleupon'}],
			'a', {href: 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + encodedUrl + charSeparator + 'ref=myspace&t=' + _title, title: 'Share on MySpace', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxMyspace.gif', alt:'MySpace'}],
			'a', {href: 'http://www.mixx.com/submit?page_url=' + encodedUrl + charSeparator + 'ref=mixx&title=' + _title, title: 'Share on Mixx', target: '_blank'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxMixx.gif', alt:'Mixx'}],
			'a', {href: '#', title: 'Share on Twitter', target: '_blank', id: 'twitterBtn'}, [
				'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/share/shareBoxTwitter.gif', alt:'Twitter'}],
		],
		'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/makeHPArrow.gif', height:'9', width:'17', className:'arrow', alt:'Share this page'}
	]);
	$(document).ready(function(){
		$("#twitterBtn").click(function(event){
			www.tweet(productionUrl, urlEncodedArticleTitle);
			event.preventDefault();
		});
	});
}

jsHTML.shareVideo = function(_this, _title, _url, _width) {
	var leftCalc = $(_this).offset().left - (_width / 2) + (($(_this).width() + parseInt($(_this).css("padding-left")) + parseInt($(_this).css("padding-right"))) / 2);
	$("body").createAppend('div', {id:'shareMore', className: 'popupBox', style: 'left: ' + leftCalc + 'px; top: ' + ($(_this).offset().top + 15) + 'px; display: none;'}, [
		'div', {className:'title'}, [
			'span', {}, 'Share TVNZ pages on some of the most-popular social networking and content sites on the internet.',
			'a', {href: '#', className:'close'}, 'CLOSE'
		] ,
		'div', {className:'content'}, [
			'ul', {}, [
				'li', {className:'delicious'}, [
					'a', {href: 'http://del.icio.us/post?url=' + _url+'%3Fref=delicious' + '&title=' + _title, title: 'Bookmark on Delicious', target: '_blank'}, 'Delicious'],
				'li', {className:'digg'}, [
					'a', {href: 'http://digg.com/submit?url=' + _url + '%3Fref=digg&title=' + _title, title: 'Share on Digg', target: '_blank'}, 'Digg'],
				'li', {className:'facebook'}, [
					'a', {href: 'https://www.facebook.com/sharer.php?u=' + _url + '%3Fref=facebook&t=' + _title, title: 'Share on Facebook', target: '_blank'}, 'Facebook'],
				'li', {className:'reddit'}, [
					'a', {href: 'http://reddit.com/submit?url=' + _url + '%3Fref=reddit&title=' + _title, title: 'Share on Reddit', target: '_blank'}, 'Reddit'],
				'li', {className:'bebo'}, [
					'a', {href: 'http://www.bebo.com/c/share?Url=' + _url + '%3Fref=bebo&Title=' + _title, title: 'Share on Bebo', target: '_blank'}, 'Bebo'],
				'li', {className:'newsvine'}, [
					'a', {href: 'http://www.newsvine.com/_wine/save?popoff=0&u=' + _url + '%3Fref=newsvine&h=' + _title, title: 'Share on Newsvine', target: '_blank'}, 'Newsvine'],
				'li', {className:'stumbleupon'}, [
					'a', {href: 'http://www.stumbleupon.com/submit?url=' + _url + '%3Fref=stumble&title=' + _title, title: 'Share on Stumbleupon', target: '_blank'}, 'Stumbleupon'],
				'li', {className:'myspace'}, [
					'a', {href: 'http://www.myspace.com/Modules/PostTo/Pages/?u=' + _url + '%3Fref=myspace&t=' + _title, title: 'Share on MySpace', target: '_blank'}, 'MySpace'],
				'li', {className:'mixxed'}, [
					'a', {href: 'http://www.mixx.com/submit?page_url=' + _url + '%3Fref=mixx&title=' + _title, title: 'Share on Mixx', target: '_blank'}, 'Mixxed'],
				'li', {className:'twitter'}, [
					'a', {href: 'https://twitter.com/intent/tweet?text=' + _title + '&url=' + _url+'%3Fref=twitter', title: 'Twitter', target: '_blank'}, 'Twitter'],
			],
			'div', {className:'formRow', id: 'copyBox'}, [
				'label', {}, 'Or copy this link:',
				'input', {type: 'text', name: 'copylink', id: 'copyShareLink', value: _url}, '',
			],
			'div', {className:'formRow'}, [
				'a', {href: '#', className: 'copyLink'}, 'Click to copy link',
			], 
		],
		'div', {className:'corners'}, [], 
		'div', {className:'arrow'}, []
	]);
}


jsHTML.email = function(_this, _id, _title, _keyword, _url, _width) {
	var leftCalc = $(_this).filter(":first").offset().left - (_width / 2) + (($(_this).filter(":first").width() + parseInt($(_this).filter(":first").css("padding-left")) + parseInt($(_this).filter(":first").css("padding-right"))) / 2);
	var charSeparator = _url.href.indexOf('?') == -1 ? '?' : '&';
	$("body").createAppend('div', {id:'emailBox', className: 'popupBox', style: 'width: ' + _width + 'px; left: ' + leftCalc + 'px; top: ' + ($(_this).offset().top + 15) + 'px; display: none;'}, [
		'div', {className:'title'}, [
			'h2', {}, 'Email this page',
			'div', {className: 'hr'}, '',
			'span', {}, 'Enter your friend\'s name and email address first, then your own and hit submit.',
			'p', {}, 'The marked fields below are mandatory.'
		],
		'a', {href: '#', className:'close'}, 'CLOSE',
		'div', {className:'content'}, [
			'form', {id: 'emailForm', action: 'http://runes.tvnz.co.nz/tvnz_email_story_mail_latest.php', method: 'post'}, [
				'input', {type: 'hidden', value: _keyword, name: 'parentKeyword'}, '',
				'input', {type: 'hidden', value: _title, name: 'articleTitle'}, '',
				'input', {type: 'hidden', value: _id, name: 'articleId'}, '',
				'input', {type: 'hidden', value: _url + charSeparator + 'ref=emailfriend', name: 'articleUrl'}, '',
				'div', {className:'formRow'}, [
					'label', {}, '&nbsp;',
					'span', {}, 'Name:',
					'span', {}, 'Email:'
				],
				'div', {className:'formRow'}, [
					'label', {}, 'To:*',
					'input', {type: 'text', name: 'reciever', id: 'reciever'}, '',
					'input', {type: 'text', name: 'to', id: 'to'}, ''
				],
				'div', {className:'formRow'}, [
					'label', {}, 'From:*',
					'input', {type: 'text', name: 'sender', id: 'sender'}, '',
					'input', {type: 'text', name: 'from', id: 'from'}, ''
				],
				'div', {className:'formRow'}, [
					'a', {className: 'button', id: 'btnSubmit', href: '#'}, [
						'span', {}, 'Submit'
					]
				]
			]
		],
		'img', {src: 'http://images.tvnz.co.nz/tvnz_site_images/images/makeHPArrow.gif', height:'9', width:'17', className:'arrow', alt:'Email This Story'}
	]);
}

jsHTML.emailVideo = function(_this, _id, _title, _keyword, _url, _width) {
	var leftCalc = $(_this).offset().left - (_width / 2) + (($(_this).width() + parseInt($(_this).css("padding-left")) + parseInt($(_this).css("padding-right"))) / 2);
	$("body").createAppend('div', {id:'emailBox', className: 'popupBox', style: 'left: ' + leftCalc + 'px; top: ' + ($(_this).offset().top + 15) + 'px; display: none;'}, [
		'div', {className:'title'}, [
			'span', {}, 'Enter your friend\'s name and email address first, then your own and hit submit. All fields below are mandatory.',
			'a', {href: '#', className:'close'}, 'CLOSE'
		],
		'div', {className:'content'}, [
			'form', {id: 'emailForm', action: '', method: 'post'}, [ //http://runes.tvnz.co.nz/tvnz_email_story_mail_latest.php
				'input', {type: 'hidden', value: _keyword, name: 'parentKeyword'}, '',
				'input', {type: 'hidden', value: _title, name: 'articleTitle'}, '',
				'input', {type: 'hidden', value: _id, name: 'articleId'}, '',
				'input', {type: 'hidden', value: _url+'%3Fref=emailfriend', name: 'articleUrl'}, '',
				'div', {className:'formRow'}, [
					'label', {}, 'Your Name:',
					'input', {type: 'text', name: 'sender', id: 'sender'}, '',
				],
				'div', {className:'formRow'}, [
					'label', {}, 'Your Email Address:',
					'input', {type: 'text', name: 'from', id: 'from'}, '',
				],
				'div', {className:'formRow'}, [
					'label', {}, 'Friend\'s Email Address:',
					'input', {type: 'text', name: 'to', id: 'to'}, '',
				],
				'div', {className:'formRow smallText'}, 'Seperate multiple addresses with a comma',
				'div', {className:'formRow'}, [
					'a', {className: 'button', id: 'btnSubmit', href: '#'}, [
						'span', {}, 'Submit'
					],
				],
				'div', {className:'formRow', id: 'copyBox'}, [
					'label', {}, 'Or copy this link:',
					'input', {type: 'text', name: 'copylink', id: 'copyEmailLink', wrap: 'virtual', value: _url}, '',
				],
				'div', {className:'formRow'}, [
					'a', {href: '#', className: 'copyLink'}, 'Click to copy link',
				]
			]
		],
		'div', {className:'corners'}, [],
		'div', {className:'arrow'}, []
	]);
}
