// JavaScript Document

/*******************************************************************
 *
 *	dropshadow - generic dropshadow call made to assign a height based off of from value
 *
 *******************************************************************/

function MCOL_dropshadow_default(channame){
	var divh = document.getElementById('MCOL_middle').offsetHeight;
	if (divh > 0) { 
	document.getElementById('MCOL_dropshadow').style.display = 'block';
	document.getElementById('MCOL_dropshadow').style.height = divh+'px';
	document.getElementById('MCOL_top').style.backgroundImage = "url('/cm/cosmogirl/images/v01/FeatureContentWell/center_colors/backup/fcontentwell_top_"+channame+".png')"; // swap bkg with one with shad
	document.getElementById('MCOL_bottom').style.backgroundImage = "url('/cm/cosmogirl/images/v01/FeatureContentWell/center_colors/backup/fcontentwell_bot_"+channame+".png')";
	}
}

function dropshadow(to,from,offset){
	var divh = document.getElementById(from).offsetHeight;
	divh = divh-offset;
	if ((divh > 0) && (document.getElementById(to))) { 
	document.getElementById(to).style.display = 'block';
	document.getElementById(to).style.height = divh+'px';
	}
}

// this is the channel name the navbar defaults, if channel name is none, the navbar defaults to nothing
function initnav(channelname){
	dropshadow("MCOL_dropshadow","MCOL_middle",0);
	document.getElementById('MCOL_top').style.backgroundImage = "url('/cm/cosmogirl/images/v01/FeatureContentWell/center_colors/backup/fcontentwell_top_"+channelname+".png')"; // swap bkg with one with shad
	document.getElementById('MCOL_bottom').style.backgroundImage = "url('/cm/cosmogirl/images/v01/FeatureContentWell/center_colors/backup/fcontentwell_bot_"+channelname+".png')";
}
// this is a special init nav that is tailored for blogs, I'm lazy to come up with a universal solution, and this works for as is anyways, so why not?
function blog_initnav(channelname){
	dropshadow("MCOL_dropshadow","MCOL_middle",275);
	// the code below adds the drop shadow to the middle column. If the code does not execute, try and degrade gracefully so we don't see some nastiness on other browsers that don't support this functionality. However I don't see why not, but put it on anyway. Good luck
	document.getElementById('MCOL_bottom').style.backgroundImage = "url('/cm/cosmogirl/images/v01/FeatureContentWell/center_colors/backup/fcontentwell_bot_"+channelname+".png')";
	document.getElementById('CNTR_blogentry_top').style.backgroundImage = "url('/cm/cosmogirl/images/v01/BlogContent/wshad/bcontent_top_"+channelname+".png')";
	document.getElementById('MCOL_blog_side').style.backgroundImage = "url('/cm/cosmogirl/images/v01/BlogContent/wshad/bcontent_side_"+channelname+".png')";
	document.getElementById('CNTR_blog_3rdbox').style.backgroundImage = "url('/cm/cosmogirl/images/v01/BlogContent/wshad/bcontent_3_"+channelname+".png')";
}

// this is a special init nav that is tailored for open articles, and I'm still being lazy.. whatever.
function openarticle_initnav(channelname){
	dropshadow("MCOL_middle3col_SHAD","MCOL_middle3col",0);
	dropshadow("MCOL_dropshadow","MCOL_middle",17);
	document.getElementById('MCOL_bottom').style.backgroundImage = "url('/cm/cosmogirl/images/v01/FeatureContentWell/center_colors/backup/fcontentwell_bot_"+channelname+".png')";
}
function widearticle_initnav(channelname){
	dropshadow("MCOL_middle4col_shad","MCOL_middle4col",0);
	dropshadow("MCOL_dropshadow","MCOL_middle",15);
	document.getElementById('CNTR_blogentry_top').style.backgroundImage = "url('/cm/cosmogirl/images/v01/BlogContent/wshad/bcontent_top_"+channelname+".png')";
	document.getElementById('MCOL_bottom').style.backgroundImage = "url('/cm/cosmogirl/images/v01/FeatureContentWell/center_colors/backup/fcontentwell_bot_"+channelname+".png')";
}
function special_initnav(channelname){
	dropshadow("MCOL_dropshadow","MCOL_middle",0);
}
function games_initnav(channelname){
	dropshadow("MCOL_middle4col_shad","MCOL_middle4col",0);
	document.getElementById('CNTR_blogentry_top').style.backgroundImage = "url('/cm/cosmogirl/images/v01/BlogContent/wshad/bcontent_top_"+channelname+".png')";
}

/*******************************************************************
 *
 *	button swapper - a generic image swapper of images. All you need is the ID of the <img> tag and the src file addy
 *
 *******************************************************************/
function img_swap(img_ID,nameoffile){
	document.getElementById(img_ID).setAttribute('src','/'+nameoffile);
}


/*******************************************************************
 *
 *	navigator.js
 *
 *******************************************************************/
function navigator_ON(cat_ID){
	reset_tabs();
	document.getElementById('navigator_tab_'+cat_ID).style.backgroundImage = "url('cm/cosmogirl/images/v01/ArticleContentWell/navigator/n_"+cat_ID+"_ON.gif')";
	document.getElementById('navigator_tab_'+cat_ID).style.lineHeight = "17px";
}

function reset_tabs(){
	document.getElementById('navigator_tab_beauty').style.backgroundImage = "url('cm/cosmogirl/images/v01/ArticleContentWell/navigator/n_beauty_OFF.gif')";
	document.getElementById('navigator_tab_fashion').style.backgroundImage = "url('cm/cosmogirl/images/v01/ArticleContentWell/navigator/n_fashion_OFF.gif')";
	document.getElementById('navigator_tab_lifeadvice').style.backgroundImage = "url('cm/cosmogirl/images/v01/ArticleContentWell/navigator/n_lifeadvice_OFF.gif')";
	document.getElementById('navigator_tab_guys').style.backgroundImage = "url('cm/cosmogirl/images/v01/ArticleContentWell/navigator/n_guys_OFF.gif')";
	document.getElementById('navigator_tab_entertainment').style.backgroundImage = "url('cm/cosmogirl/images/v01/ArticleContentWell/navigator/n_entertainment_OFF.gif')";
	document.getElementById('navigator_tab_fungames').style.backgroundImage = "url('cm/cosmogirl/images/v01/ArticleContentWell/navigator/n_fungames_OFF.gif')";


	document.getElementById('navigator_tab_beauty').style.lineHeight = "34px";
	document.getElementById('navigator_tab_fashion').style.lineHeight = "34px";
	document.getElementById('navigator_tab_lifeadvice').style.lineHeight = "34px";
	document.getElementById('navigator_tab_guys').style.lineHeight = "34px";
	document.getElementById('navigator_tab_entertainment').style.lineHeight = "34px";
	document.getElementById('navigator_tab_fungames').style.lineHeight = "34px";
}


/*******************************************************************
 *
 *	RATE IT.js
 *	note: makes usage of jquery, so make sure jquery is supplied beforehand otherwise the ajax call will not work.
 *******************************************************************/

// this is defualt rated value, we'll have to work on how to give it a standard server value later
var ratedvalue = 0;

function rateit_over(x){
	x = parseInt( x );
	var parsed_x;
	var rateitstring;
	blankrates();
	for (i = 2; i <= x; i=i+2){
		parsed_x = parseInt(i/2);
		rateitstring = 'rateit_'+parsed_x;
		if (i <= ratedvalue) {
			document.getElementById(rateitstring).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/rateit_button_OVER_66.gif');
		} else {
			document.getElementById(rateitstring).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/rateit_button_OVER.gif');
		}
	}
}

function rateit_on(x){
	x = parseInt( x );
	var parsed_x;
	var rateitstring;
	blankrates();
	for (i = 2; i <= x; i=i+2){
		parsed_x = parseInt(i/2);
		rateitstring = 'rateit_'+parsed_x;
		document.getElementById(rateitstring).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/rateit_button_ON.gif');
	}
	ratedvalue = x;
}
function rateit_click(x,my_url){
	blankrates();
	var parsed_x;
	var rateitstring;
	for (i = 2; i <= x; i=i+2){
		parsed_x = parseInt(i/2);
		rateitstring = 'rateit_'+parsed_x;
		document.getElementById(rateitstring).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/rateit_button_ON.gif');
	}
	var dasurl = my_url+"/"+x;
	$.get(dasurl,function(data){process_rateit(data);});
}

function process_rateit(data){
	var rate_data = parseInt( data );
	rateit_on(rate_data);
}

function keepratedvalue(){
	rateit_on(ratedvalue)
}

function blankrates(){
	for (i = 1; i <= 5; i++){
		document.getElementById('rateit_'+i).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/rateit_button_OFF.gif');
	}
	
}

function viral_on(x){
	document.getElementById(x).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/viral_buttons/'+x+'_ON.gif');
	}
function viral_down(x){
	document.getElementById(x).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/viral_buttons/'+x+'_DOWN.gif');
	}
function viral_off(x){
	document.getElementById(x).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/viral_buttons/'+x+'_OFF.gif');
	}
function viral_up(x){
	document.getElementById(x).setAttribute('src','/cm/cosmogirl/images/v01/ArticleContentWell/viral_buttons/'+x+'_ON.gif');
}

/* comment Populating function */
function getCommentCount(id){$.get("/comments/getCount?article_id="+id,function(data){
	var number = parseInt(data);
	if (number < 1) return;
	if (number == 1){
		$(".comment_count_"+id).html("("+number+" comment)")
	} else {
		$(".comment_count_"+id).html("("+number+" comments)")
	};})}

/* REFRESH ADS */
function refreshAds() {
 ord=Math.random()*10000000000000000;
 if (document.getElementById('CONTAINER_BANNER_AD')) {document.getElementById('CONTAINER_BANNER_AD').innerHTML = document.getElementById('CONTAINER_BANNER_AD').innerHTML;}
 if (document.getElementById('CONTAINER_BOOMBOX_AD')) {document.getElementById('CONTAINER_BOOMBOX_AD').innerHTML = document.getElementById('CONTAINER_BOOMBOX_AD').innerHTML;}
 if (document.getElementById('CONTAINER_SKYSCRAPER_AD')) {document.getElementById('CONTAINER_SKYSCRAPER_AD').innerHTML = document.getElementById('CONTAINER_SKYSCRAPER_AD').innerHTML;}
 if (top.s) {s.eVar10="";s.eVar11="";s.eVar12="";s.eVar13="";s.eVar14="";s.eVar15="";s.eVar16="";s.eVar17="";s.eVar18="";s.referrer=(location.href);void(s.t());} 
}




/*TEMP CODE FOR COMMENT COUNT */
function jqgetComment(id, url){
	$.get("/comments/getCount?article_id="+id,function(data){
		if(data == 1){$(".comment_count_"+id).html(data + ' <a href=\"' + url + '\">comment</a>');}
		else {$(".comment_count_"+id).html(data + ' <a href=\"' + url + '\">comments</a>');}
	});
}