/*-----------------------------------------------------------------
Functions to do on body load
-----------------------------------------------------------------*/
function DMscripts() {
	if (document.body.clientWidth < 1024) {
		window.resizeTo(1024,screen.availHeight);
	}
	if (document.body.clientHeight < screen.availHeight ) {
		window.resizeTo(document.body.clientWidth,screen.availHeight);
	}
	externalLinks();
	safariSearch();
}

/*-----------------------------------------------------------------
Open External Links in a new window
-----------------------------------------------------------------*/
function externalLinks() {
	if (!document.getElementsByTagName) return;

	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
			if (anchor.getAttribute("rel") == "me" || anchor.getAttribute("rel") == "external" || anchor.getAttribute("rel") == "nofollow" || anchor.getAttribute("rel") == "external nofollow" || anchor.getAttribute("rel") == "nofollow external") {
				if (anchor.getAttribute("href")) anchor.target = "_blank";
			}
	}	
} 

/*-----------------------------------------------------------------
Create a Safari Like Search Input
-----------------------------------------------------------------*/
function safariSearch() {
	// configuration
		var searchID		 = 's';
		var autoSave		 = 'dmblog';	// name of autosave, use null for none
		var searchText  = '';
	// end configuration
	var search = document.getElementById(searchID);
	// check for safari
	if ( !window.opera && navigator.vendor && navigator.vendor.indexOf("Apple") != -1 ) {
		// using safari so change search input into safari
			search.setAttribute('type', 'search');
			search.setAttribute('placeholder', searchText);
			search.style.height = "24px";
			search.style.width = "135px";
			search.style.margin = "11px 0";
		// autosave?
		if(autoSave) {
			search.setAttribute('autosave', autoSave + '-autosave');
			search.setAttribute('results', '10');
		}
	}
}

/*-----------------------------------------------------------------
Open Subscribe options using Lightview
-----------------------------------------------------------------*/
function dmsubscribe(){
	Lightview.show({
		href: 'http://DMblog.com/wp-content/plugins/dm-blog-custom/dm-subscribe.php',
		rel: 'ajax',
		options: {topclose: true,menubar: false,width: 500,height: 275,
			ajax:{method: 'post',parameters:{x: 'x'}}
		}
	});
}

/*-----------------------------------------------------------------
Open Images using Lightview
-----------------------------------------------------------------*/
function showimage(imgsrc,imgextension,imgtitle){
	Lightview.show({
		href: 'http://DMblog.com/wp-content/uploads/'+imgsrc+'.'+imgextension,
		/*rel: 'image',*/
		title: imgtitle
	});
}

/*-----------------------------------------------------------------
Open Videos using Lightview
-----------------------------------------------------------------*/
function showvideo(vidsrc,vidtitle){
	Lightview.show({
		href: 'http://DMblog.com/wp-content/uploads/'+vidsrc + '.mov',
		rel: 'quicktime',
		title: vidtitle
	});
}

/*-----------------------------------------------------------------
Open YouTube Videos using Lightview
-----------------------------------------------------------------*/
function showyoutube(vidid,vidtitle){
	Lightview.show({
		href: 'http://www.youtube.com/v/'+vidid+'&hl=en&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6&autoplay=1&showsearch=0&ap=%2526fmt%3D18',
		rel: 'flash',
		title: vidtitle
	});
}

/*-----------------------------------------------------------------
Open YouTube Videos in HD using Lightview
-----------------------------------------------------------------*/
function showyoutubeHD(vidid,vidtitle){
	Lightview.show({
		href: 'http://www.youtube.com/v/'+vidid+'&hl=en&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6&autoplay=1&showsearch=0&ap=%2526fmt%3D18&hd=1',
		rel: 'flash',
		title: vidtitle,
		options: {width: 640,height: 385}
	});
}

/*-----------------------------------------------------------------
Open Audio using Lightview
-----------------------------------------------------------------*/
function playaudio(audsrc,audtitle){
	Lightview.show({
		href: 'http://DMblog.com/wp-content/uploads/'+audsrc + '.mp3',
		rel: 'quicktime',
		title: audtitle,
		options: {width: 480,height: 16,controls: true}
	});
}