$(document).ready(function() {
	$("a[rel='colorbox']").colorbox(); 
	$("a[rel='colorbox_video']").colorbox({iframe:true, innerWidth:450, innerHeight:320});
	itemHighlight();

	$('#content a[class=tooltips]').each(function(){
		$(this).attr("href", "javascript:void(0)");
		$(this).qtip(
		{
			content: {
				text: '<img class="throbber" src="image/throbber.gif" alt="Loading..." />',
				url: 'index.php?route=information/tooltip&title=' + $(this).text(),
				title: {
					text: 'Tooltip - ' + $(this).text(),
					button: 'Close'
				}
			},
			position: {
				corner: {
					target: 'bottomRight',
					tooltip: 'topLeft'
				},
				adjust: {
					screen: true 
				}
			},
			show: { 
				when: 'mouseover', 
				//when: 'click', 
				solo: true 
			},
			hide: 'unfocus',
			style: {
				tip: true, 
				border: {
					width: 0,
					radius: 4
				},
				name: 'light', 
				width: 300 
			}
		})
	});

	$('#newsletter a').click(function () {
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/newsletter/submit',
			dataType: 'html',
			data: $('#newsletter_form :input'),
			success: function (html) {
				if (html == "success"){
					window.location.replace("information_success");
				} 
				else {
					$('#newsletter .error').html(html);
				}
			},	
			complete: function () {
			}			
		});			
	});		
});

$('#search input').keydown(function(e) {
	if (e.keyCode == 13) {
		moduleSearch();
	}
});

function moduleSearch() {
	url = 'video_search';
	
	var filter_keyword = $('#filter_keyword').attr('value')
	
	if (filter_keyword) {
		url += '&keyword=' + encodeURIComponent(filter_keyword);
	}
	
	var filter_category_id = $('#filter_category_id').attr('value');
	
	if (filter_category_id>0) {
		url += '&category_id=' + filter_category_id;
	}
	
	location = url;
}

$('#search_doc input').keydown(function(e) {
	if (e.keyCode == 13) {
		docSearch();
	}
});

function docSearch() {
	url = 'index.php?route=information/search';
	
	var filter_keyword = $('#filter_doc_keyword').attr('value')
	
	if (filter_keyword) {
		url += '&keyword=' + encodeURIComponent(filter_keyword);
	}
	
	location = url;
}

$('.switcher').bind('click', function() {
	$(this).find('.option').slideToggle('fast');
});
$('.switcher').bind('mouseleave', function() {
	$(this).find('.option').slideUp('fast');
}); 

function bookmark(url, title) {
	if (window.sidebar) { // firefox
    window.sidebar.addPanel(title, url, "");
	} else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all) {// ie
   		window.external.AddFavorite(url, title);
	}
}

function user_login () {
	$.ajax({
		type: 'post',
		url: 'index.php?route=account/login/login',
		dataType: 'html',
		data: $('#login_form :input'),
		success: function (html) {
			if (html == "success"){
				window.location.reload();
			} 
			else {
				$('#login_error').html(html);
			}
		},	
		complete: function () {
		}			
	});			
}

function itemHighlight() {
	$("a[rel='colorbox_video']").each(function(index){
		$(this).mouseover(function() { highLightThis($(this)) });
		$(this).mouseout(function() { setDefault() });
	});
}

function highLightThis(obj) {
	$("a[rel='colorbox_video']").each(function(index){
		$(this).css( { 
			"opacity"	: "0.5"
		} );
	});
	obj.css( { 
		"opacity"	: "1"
	} );
}

function setDefault(){
	$("a[rel='colorbox_video']").each(function(index){
		$(this).css( { 
			"opacity"	: "1"
		} );
	});
}
