// JavaScript Document
pageType = 'normal';

function init() {
	if($('authimage')!=null) getAuthImage();
	
	if ($chk($("links"))) {
		$("links").getChildren().each(function(el){
			if(el.nodeName == 'LI') {
				el.addEvent('mouseenter',function (e) {
					this.addClass('over');
				});
				el.addEvent('mouseleave',function (e) {
					this.removeClass('over');
				});
			}
			
		});
	}
	
	if($chk($('basket'))) {
		var url = domain + "ajaxbasket.php";
		$('basket').set('load', {method: 'get',evalScripts: false }).load(url);
	}
	if($chk($("overlay"))) {
		if(navigator.userAgent.toLowerCase().indexOf('msie 7')) {
			$("overlay").setStyle('left','50%');
			$("overlay").setStyle('margin-left','-150px');
		}
		window.addEvent('scroll',function (e) {
			pos = Math.max(document.body.scrollTop,document.documentElement.scrollTop) - 160;
			if(pos < 0) pos = 0;
			$('overlay').tween('top',pos + 'px');
		});
	}
	if($chk($('product_form'))) {
		$('product_form').addEvent('submit', function(e){
			new Event(e).stop();
			this.set('send',{
				onComplete: function(responseHTML) {
					$('basket').set('html', responseHTML);
					$('overlay').setStyle('visibility','visible');
				},
				evalScripts: true
			}).send();
		});
	}
	if(check('before')) {
		var cbanner = function() {
			showHide('before');
		}
		periodical = cbanner.periodical(5000, this);
	}
	var IE6 = (navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) && (navigator.userAgent.toLowerCase().indexOf('msie 7') == -1);  
	if(IE6) {
		alert('ie6');
	}
}

function getAuthImage() {
	var reference = Math.floor(Math.random() * 9999999);
	$('authimage').innerHTML = "<label>Copy text (<a href=\"javascript:getAuthImage()\">refresh</a>)</label><img src='http://cms.afxdesign.com/getAuthImage.php?reference= " + reference + "' /><input type='hidden' name='imagereference' value='" + reference + "' /><input type='text' name='imagetext' style='width: 60px; height: 20px;' />";
}

/* DomReady Event fires when all Elements are ready, but not images. */
window.addEvent('domready', function() {
	init();	
});

function show(el) {
	$(el).fade('in');
}

function hide(el) {
	$(el).fade('out');
}

function showHide(el) {
	if($(el).getStyle('visibility') == 'visible') {
		$(el).fade('out');
		$(el).innerHTML = "";
	}
	else $(el).fade('in');
}

function showConcern(tid,cid,csubject) {
	$$('.concern').setStyle('display','none');
	var url = domain + "ajaxtreatment.php?aid=" + tid + "&cid=" + cid + "&csubject=" + csubject;
	$('concern-' + tid).set('load', {method: 'get',evalScripts: false }).load(url);
	$('concern-' + tid).setStyle('display','block');
}

function check(Id)
{
  var o = document.getElementById(Id);
  if (o) return true;
  return false;
}

function showVideo(id) {
	var url = domain + "ajaxvideo.php?fid=" + id;
	$('overlay').set('load', {method: 'get',evalScripts: true,
		onComplete: function() {
			$('overlay').setStyle('width','520px');
			$('overlay').setStyle('z-index','1000');
			$("overlay").setStyle('margin-left','-260px');
			showHide('overlay');
		}
	 }).load(url);
	
}

