var relmediaptr = 1;
var owndomain = true;
var relmedialim = 5;
var relmediaulim;
var wopener = window.opener;
var selectedCollectibles = {};

$(window).load(function(){
	
	$('#label-button').mouseover(function() {
		$('#label-info').removeClass().addClass('label_show_on');
	});
	$('#label-button').mouseout(function() {
		$('#label-info').removeClass().addClass('label_show_off');
	});

	$('#recommend-button-show').click(function() {
		$('#recommend').removeClass().addClass('recommend_show_on');
		$(this).blur();
	});
	$('#recommend-button-close').click(function() {
		$('#recommend').removeClass().addClass('recommend_show_off');
	});

	$('#big').mouseover(function() {
		$('#prev').removeClass().addClass('on');
		$('#next').removeClass().addClass('on');
	});
	$('#big').mouseout(function() {
		$('#prev').removeClass().addClass('off');
		$('#next').removeClass().addClass('off');
	});

	var xx = function(item) {
	    $('#offer').load(jumptohome + '/mediaoffer_ajax?tag=' + item.getAttribute("id") + ';excl=' + thismediaid);
	};

	$('#info-data a.clickabletag').click(function() {
	    this.blur();
	    xx(this);
	    return false;
	});
	
	try {
		var a = wopener.document.location.hostname;
	} catch (ex) {
		owndomain = false;
	} finally {
		if (!wopener && !owndomain && referer == '') {
			var winid = window.open(document.location, 'MediaTar', 'toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no,status=no,width=790, height=590');
			if (winid) {
				document.location.href = jumptohome;
			}
		}
	}
});

function showDencItem(num) {
	document.getElementById('info-text').style.display='none';
	document.getElementById('info-data').style.display='none';
	var shorts = document.getElementById('short').getElementsByTagName('div');
	for (var a = 0; a < shorts.length; a++) {
		var myNode = shorts[a];
		if (myNode.parentNode.getAttribute('id') == 'short') {
			shorts[a].style.display = 'none';
		}
	}
	document.getElementById('short-' + num).style.display='block';
	document.getElementById('short').style.display='block';
}

function hideDencItem(num) {
	document.getElementById('info-text').style.display='block';
	document.getElementById('info-data').style.display='block';
	document.getElementById('short').style.display='none';
}

function toBookmark() {
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.Addfavorite(document.location.href, document.title + ' / HáziPatika.com');
	} else if (navigator.appName == "Netscape") {
		window.sidebar.addPanel(document.title + ' / HáziPatika.com', document.location.href, '');
	} else {
	alert('Böngészőhiba');
	}
}

function scrollRelMedia(dir) {
	
	relmediacnt = document.getElementById('items').getElementsByTagName('a').length;

	if (dir == 'up') {
		if (relmediaptr > 1) {
			relmediaptr --;
		}
	} else {
		if (relmediaptr < relmediacnt - relmedialim){
			if (relmediaptr < relmediacnt) {
				relmediaptr ++;
			}
		}
	}

	relmediaulim = (relmediaptr + relmedialim) > relmediacnt ? relmediacnt : relmediaptr + relmedialim;
	if (document.getElementById('relmedia_' + (relmediaptr - 1))) {
		document.getElementById('relmedia_' + (relmediaptr - 1)).style.display = 'none';
		document.getElementById('relmediasep_' + (relmediaptr - 1)).style.display = 'none';
	}
	if (document.getElementById('relmedia_' + (relmediaptr))) {
		document.getElementById('relmedia_' + (relmediaptr)).style.display = 'block';
		document.getElementById('relmediasep_' + (relmediaptr)).style.display = 'block';
	}
	if (document.getElementById('relmedia_' + (relmediaulim + 1))) {
		document.getElementById('relmedia_' + (relmediaulim + 1)).style.display = 'none';
		document.getElementById('relmediasep_' + (relmediaulim + 1)).style.display = 'none';
	}
	if (document.getElementById('relmedia_' + (relmediaulim))) {
		document.getElementById('relmedia_' + (relmediaulim)).style.display = 'block';
		if (document.getElementById('relmediasep_' + (relmediaulim - 1))) {
			document.getElementById('relmediasep_' + (relmediaulim - 1)).style.display = 'block'; //na ennél gusztustalanabbul nem tudom... :-(
		}
		document.getElementById('relmediasep_' + (relmediaulim)).style.display = 'none';
	}
}
function parentOpenUrl(url, wname) {
	if (wopener) {
		wopener.open(url, wname);return false;
	} else {
		window.open(url, wname);return false;
	}
}

function sendUrl() {
	$("#recommend-innerp").load(jumptohome + '/sendurl_ajax', {to: document.getElementById('to').value, toname: document.getElementById('toname').value, fromname: document.getElementById('fromname').value, from: document.getElementById('from').value, mediaid: thismediaid, mediatitle: thismediatitle});
}

function closeSendUrl() {
	$('#recommend').removeClass().addClass('recommend_show_off');
}

function goHome() {
	if (wopener && owndomain) {
		wopener.location.href = jumptohome;
		window.close();
	} else {
		document.location.href = jumptohome;
	}
}

function changeToMedia(id) {
	imgpos = id;
	//document.getElementById('mediatitle').innerHTML = imgobjects[id]['title'];
	//document.getElementById('mediasubtitle').innerHTML = imgobjects[id]['subtitle'];
	document.getElementById('mediadescription').innerHTML = imgobjects[id]['description'];
	document.getElementById('big').style.backgroundImage = 'url(' + MEDIAURL + '/mediatar' + thismediapath + '/' + imgobjects[id]['id'] + '/' + imgobjects[id]['filename'] + ')';
}

function turn(dir) {
	if (dir == 'up') {
		if (imgpos < imgnum) {
			changeToMedia(++imgpos);
		} else {
			imgpos = 1;
			changeToMedia(1);
		}
	} else {
		if (imgpos > 1) {
			changeToMedia(--imgpos);
		} else {
			imgpos = imgnum;
			changeToMedia(imgnum);
		}
	}
}




