var HOST = (window.location.hostname == 'localhost') ? 'http://localhost/infogue' : 'http://www.infogue.com';
var Data = GetData();

function GetData() {
	var Data = new Object();
	Data.HOST = (window.location.hostname == 'localhost') ? 'http://localhost/infogue' : '';
	return Data;
}

function DropDownInitialize() {
	cssdropdown.startchrome("chromemenu");
	$('#chromemenu .list').hover(
		function() {
			$(this).css('background', 'url(' + HOST + '/Image/Website/hover.gif) no-repeat top left');
			$(this).children('a').css('background', 'url(' + HOST + '/Image/Website/hover.gif) no-repeat bottom right');
		}, function() {
			$(this).css('background', '');
			$(this).children('a').css('background', '');
		}
	);
	$('.Head .media .none').hover(
		function() {
			$(this).css('background', 'url(' + HOST + '/Image/Website/unselected.gif) no-repeat top left');
		}, function() {
			$(this).css('background', '');
		}
	);
}

function InitializeListTopArticle(PassMedia, PassCategory, PassTopic) {
	var Media = PassMedia;
	var Category = PassCategory;
	var Topic = PassTopic;
	
	$('#TopAll').click(function() { Media = 'semua'; RefreshListTopArticle(); });
	$('#TopNews').click(function() { Media = 'berita'; RefreshListTopArticle(); });
	$('#TopPhoto').click(function() { Media = 'foto'; RefreshListTopArticle(); });
	$('#TopVideo').click(function() { Media = 'video'; RefreshListTopArticle(); });
	
	function RefreshListTopArticle() {
		$.post(Data.HOST + '/php/AjaxRequest.php', { Method:'Request', Media:Media, Category:Category, Topic:Topic }, function(data) {
			$('#list_top_article').html(data);
		});
	}
}

function InitializeSearch() {
	var SearchDefaultText = 'search infoGue ...';
	$('#SearchValue').blur(function() { $('#SearchValue').val($('#SearchValue').val() == '' ? SearchDefaultText : $('#SearchValue').val()); } );
	$('#SearchValue').focus(function() { $('#SearchValue').val($('#SearchValue').val() == SearchDefaultText ? '' : $('#SearchValue').val()); } );
}
function InitializeIndexVote() {
	$('.cnt_art_pad .image-vot').click(function() {
		var Container = $(this);
		var ArticleID = Container.parents('.left').children('.bg').children('.ListArticleID').text();
		$.post(HOST + '/php/AjaxRequest.php', { Method:'Vote', ArticleID:ArticleID }, function(Result) {
			eval('var Data = ' + Result);
			if (Data.Result) {
				Container.parents('.left').children('.bg').children('.ArticleVote').text(Data.ArticleVote);
			} else {
				window.location = HOST + '/login';
			}
		});
	});
	
	$('.cnt_art_pad .image-vot-dislike').click(function() {
		var Container = $(this);
		var ArticleID = Container.parents('.left').children('.bg').children('.ListArticleID').text();
		$.post(HOST + '/php/AjaxRequest.php', { Method:'UnVote', ArticleID:ArticleID }, function(Result) {
			eval('var Data = ' + Result);
			if (Data.Result) {
				Container.parents('.left').children('.bg').children('.ArticleVote').text(Data.ArticleVote);
			} else {
				window.location = HOST + '/login';
			}
		});
	});
}

function InitCarouselVideo() {
	jQuery("#VideoCarousel").jcarousel({
		scroll: 4,
		initCallback: mycarousel_Video,
		
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
}
function mycarousel_Video(carousel) {
	jQuery('#Video-Next').bind('click', function() { carousel.next(); return false; });
	jQuery('#Video-Prev').bind('click', function() { carousel.prev(); return false; });
}

function InitCarouselFoto() {
	jQuery("#FotoCarousel").jcarousel({
		scroll: 5,
		initCallback: mycarousel_Foto,
		
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
}
function mycarousel_Foto(carousel) {
	jQuery('#Foto-Next').bind('click', function() { carousel.next(); return false; });
	jQuery('#Foto-Prev').bind('click', function() { carousel.prev(); return false; });
}

function InitCarouselIVideo() {
	jQuery("#IVideoCarousel").jcarousel({
		scroll: 4,
		initCallback: mycarousel_IVideo,
		
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
}
function mycarousel_IVideo(carousel) {
	jQuery('#IVideo-Next').bind('click', function() { carousel.next(); return false; });
	jQuery('#IVideo-Prev').bind('click', function() { carousel.prev(); return false; });
};

function Conversation() {
	$(document).ready(function() {
		$('#ConversationSubmit').click(function() {
			var UserID = $('#UserID').val();
			var ConversationTitle = $('#ConversationTitle').val();
			$.post(HOST + '/php/PublicUserAjaxRequest.php', { Method:'Conversation', UserID:UserID, ConversationTitle:ConversationTitle }, function(data) {
				$('#ContentConversation').html(data + $('#ContentConversation').html());
				$('#ConversationTitle').val('');
				InizializeConversationComment();
			});
		});
		InizializeConversationComment();
	});
}
function InizializeConversationComment() {
	$('.ConversationComment').click(function() {
		var ConversationID = $(this).parent('div').children('span').html();
		var ConversationDetailTitle = $(this).parent('div').children('input[type="text"]').val();
		$.post(HOST + '/php/PublicUserAjaxRequest.php', { Method:'ConversationDetail', ConversationID:ConversationID, ConversationDetailTitle:ConversationDetailTitle }, function(data) {
			$('#ConversationDetail_' + ConversationID).html(data);
			$(this).parent('div').children('input[type="text"]').val('');
			InizializeConversationComment();
		});
	});
}

function ArticleDetailIndex() {
	$(document).ready(function () {
		$('#VoteDetailIncrease .Vote').click(function() {
			$.post(HOST + '/php/AjaxRequest.php', { Method:'VoteDetailIncrease', ArticleID:$('#ArticleID').val(), CategoryID:$('#CategoryID').val() }, function(Result) {
				$('#VoteDetailIncrease').html(Result);
			});
		});
		
		InitializeSearch();
	});
}

function PopupVideo() {
	$('.PlayVideo').click(function() {
		var ArticleID = $('#ArticleID').val();
		var FrameLink = HOST + '/php/popup_play_video.php?id=' + ArticleID;
		$('#VideoFrame').attr('src', FrameLink);
		ModalReveal('VideoModal');
	});
}

function ModalReveal(divID) {
	window.onscroll = function () { document.getElementById(divID).style.top = document.body.scrollTop; };
	document.getElementById(divID).style.display = "block";
	document.getElementById(divID).style.top = document.body.scrollTop;
	document.body.style.overflow = 'hidden';
}

function ModalHide(divID) {
	document.getElementById(divID).style.display = "none";
	document.body.style.overflow = '';
}

function SearchPage() {
	$(document).ready(function() {
		var SearchMode = $('#SearchMode').val();
		if (SearchMode == 'tag') {
			
		} else {
			$('.page a').attr('href', '#');
			$('.page a').click(function() {
				$('#PageActive').val($(this).children('span').text());
				document.SearchArticle.submit();
			});
			
			$('#SearchMedia a').click(function() {
				$('#PageActive').val(1);
				$('#MediaActive').val($(this).children('span').text());
				document.SearchArticle.submit();
			} );
		}
	});
}

var HeadLineCounter = 0;
var HeadlineTime = 5000;
var HeadLineChange = true;
function InitHeadLine() {
	$('.title_right a').click(function() {
		var HeadlineNo = $(this).text();
		$('#HeadLine_1').hide();
		$('#HeadLine_2').hide();
		$('#HeadLine_3').hide();
		$('#HeadLine_' + HeadlineNo).show();
		HeadLineChange = false;
	});
	
	HeadLineRoll();
}
function HeadLineRoll() {
	if (!HeadLineChange) {
		return;
	}
	
	HeadLineCounter = (HeadLineCounter == 3) ? 1 : HeadLineCounter + 1;
	$('#HeadLine_1').hide();
	$('#HeadLine_2').hide();
	$('#HeadLine_3').hide();
	$('#HeadLine_' + HeadLineCounter).show();
	setTimeout("HeadLineRoll()", HeadlineTime);
}

function InitVoteDetail() {
	$('#VoteDetailIncrease .image-vot').click(function() {
		var ArticleID = $('#ArticleID').val();
		var CategoryName = $('#CategoryName').val();
		var LinkRequest = (HOST == 'http://localhost/infogue') ? HOST + '/php/AjaxRequest.php' : '/php/AjaxRequest.php';
		
		$.post(LinkRequest, { Method: 'Vote', ArticleID: ArticleID }, function(Result) {
			eval('var Data = ' + Result);
			if (Data.Result) {
				$('#VoteDetailIncrease .image-vote a').html(Data.ArticleVote + '<br/><span class="image-vote-pick">Vote</span>');
			} else {
				window.location = HOST + '/login';
			}
		});
	});
	
	$('#VoteDetailIncrease .image-vot-dislike').click(function() {
		var ArticleID = $('#ArticleID').val();
		var CategoryName = $('#CategoryName').val();
		var LinkRequest = (HOST == 'http://localhost/infogue') ? HOST + '/php/AjaxRequest.php' : '/php/AjaxRequest.php';
		
		$.post(LinkRequest, { Method: 'UnVote', ArticleID: ArticleID }, function(Result) {
			eval('var Data = ' + Result);
			if (Data.Result) {
				$('#VoteDetailIncrease .image-vote a').html(Data.ArticleVote + '<br/><span class="image-vote-pick">Vote</span>');
			} else {
				window.location = HOST + '/login';
			}
		});
	});
}
