﻿(function($){ $.fn.extend({ _height: $.fn.height, _width: $.fn.width, height: function(val) { if ( this[0] == window ) return self.innerHeight || $.boxModel && document.documentElement.clientHeight || document.body.clientHeight; if ( this[0] == document ) return Math.max( document.body.scrollHeight, document.body.offsetHeight ); return this._height(val); }, width: function(val) { if ( this[0] == window ) return self.innerWidth || $.boxModel && document.documentElement.clientWidth || document.body.clientWidth; if ( this[0] == document ) return Math.max( document.body.scrollWidth, document.body.offsetWidth ); return this._width(val); }, innerHeight: function() { return this[0] == window || this[0] == document ? this.height() : this.is(':visible') ? this[0].offsetHeight - num(this, 'borderTopWidth') - num(this, 'borderBottomWidth') : this.height() + num(this, 'paddingTop') + num(this, 'paddingBottom'); }, innerWidth: function() { return this[0] == window || this[0] == document ? this.width() : this.is(':visible') ? this[0].offsetWidth - num(this, 'borderLeftWidth') - num(this, 'borderRightWidth') : this.width() + num(this, 'paddingLeft') + num(this, 'paddingRight'); }, outerHeight: function() { return this[0] == window || this[0] == document ? this.height() : this.is(':visible') ? this[0].offsetHeight : this.height() + num(this,'borderTopWidth') + num(this, 'borderBottomWidth') + num(this, 'paddingTop') + num(this, 'paddingBottom'); }, outerWidth: function() { return this[0] == window || this[0] == document ? this.width() : this.is(':visible') ? this[0].offsetWidth : this.width() + num(this, 'borderLeftWidth') + num(this, 'borderRightWidth') + num(this, 'paddingLeft') + num(this, 'paddingRight'); }, scrollLeft: function(val) { if ( val != undefined ) return this.each(function() { if (this == window || this == document) window.scrollTo( val, $(window).scrollTop() ); else this.scrollLeft = val; }); if ( this[0] == window || this[0] == document ) return self.pageXOffset || $.boxModel && document.documentElement.scrollLeft || document.body.scrollLeft; return this[0].scrollLeft; }, scrollTop: function(val) { if ( val != undefined ) return this.each(function() { if (this == window || this == document) window.scrollTo( $(window).scrollLeft(), val ); else this.scrollTop = val; }); if ( this[0] == window || this[0] == document ) return self.pageYOffset || $.boxModel && document.documentElement.scrollTop || document.body.scrollTop; return this[0].scrollTop; }, offset: function(options, returnObject) { var x = 0, y = 0, sl = 0, st = 0, elem = this[0], parent = this[0], op, parPos, elemPos = $.css(elem, 'position'), mo = $.browser.mozilla, ie = $.browser.msie, sf = $.browser.safari, oa = $.browser.opera, absparent = false, relparent = false, options = $.extend({ margin: true, border: true, padding: false, scroll: true, lite: false }, options || {}); if (options.lite) return this.offsetLite(options, returnObject); if (elem.tagName.toLowerCase() == 'body') { x = elem.offsetLeft; y = elem.offsetTop; if (mo) { x += num(elem, 'marginLeft') + (num(elem, 'borderLeftWidth')*2); y += num(elem, 'marginTop') + (num(elem, 'borderTopWidth') *2); } else if (oa) { x += num(elem, 'marginLeft'); y += num(elem, 'marginTop'); } else if (ie && jQuery.boxModel) { x += num(elem, 'borderLeftWidth'); y += num(elem, 'borderTopWidth'); } } else { do { parPos = $.css(parent, 'position'); x += parent.offsetLeft; y += parent.offsetTop; if (mo || ie) { x += num(parent, 'borderLeftWidth'); y += num(parent, 'borderTopWidth'); if (mo && parPos == 'absolute') absparent = true; if (ie && parPos == 'relative') relparent = true; } op = parent.offsetParent; do { if (options.scroll) { sl += parent.scrollLeft; st += parent.scrollTop; } if (mo && parent != elem && $.css(parent, 'overflow') != 'visible') { x += num(parent, 'borderLeftWidth'); y += num(parent, 'borderTopWidth'); } parent = parent.parentNode; } while (parent != op); parent = op; if (parent.tagName.toLowerCase() == 'body' || parent.tagName.toLowerCase() == 'html') { if ((sf || (ie && $.boxModel)) && elemPos != 'absolute' && elemPos != 'fixed') { x += num(parent, 'marginLeft'); y += num(parent, 'marginTop'); } if ( (mo && !absparent && elemPos != 'fixed') || (ie && elemPos == 'static' && !relparent) ) { x += num(parent, 'borderLeftWidth'); y += num(parent, 'borderTopWidth'); } break; } } while (parent); } var returnValue = handleOffsetReturn(elem, options, x, y, sl, st); if (returnObject) { $.extend(returnObject, returnValue); return this; } else { return returnValue; } }, offsetLite: function(options, returnObject) { var x = 0, y = 0, sl = 0, st = 0, parent = this[0], op, options = $.extend({ margin: true, border: true, padding: false, scroll: true }, options || {}); do { x += parent.offsetLeft; y += parent.offsetTop; op = parent.offsetParent; if (options.scroll) { do { sl += parent.scrollLeft; st += parent.scrollTop; parent = parent.parentNode; } while(parent != op); } parent = op; } while (parent && parent.tagName.toLowerCase() != 'body' && parent.tagName.toLowerCase() != 'html'); var returnValue = handleOffsetReturn(this[0], options, x, y, sl, st); if (returnObject) { $.extend(returnObject, returnValue); return this; } else { return returnValue; } } }); var num = function(el, prop) { return parseInt($.css(el.jquery?el[0]:el,prop))||0; }; var handleOffsetReturn = function(elem, options, x, y, sl, st) { if ( !options.margin ) { x -= num(elem, 'marginLeft'); y -= num(elem, 'marginTop'); } if ( options.border && ($.browser.safari || $.browser.opera) ) { x += num(elem, 'borderLeftWidth'); y += num(elem, 'borderTopWidth'); } else if ( !options.border && !($.browser.safari || $.browser.opera) ) { x -= num(elem, 'borderLeftWidth'); y -= num(elem, 'borderTopWidth'); } if ( options.padding ) { x += num(elem, 'paddingLeft'); y += num(elem, 'paddingTop'); } if ( options.scroll ) { sl -= elem.scrollLeft; st -= elem.scrollTop; } return options.scroll ? { top: y - st, left: x - sl, scrollTop: st, scrollLeft: sl } : { top: y, left: x }; }; })(jQuery);

$(document).ready(init);

function init() {

$(document.body).addClass("jsOn");
if (getId() == 'mp1') {
	fixIndexBoxHeights();
}

if ($('#footer')[0]) {
	$('#footer').find('a[@href]').each( function() { 
	var id = document.body.getAttribute('id');
	var t = $(this);
	if (t.parent().is('.'+id)) { 
			t.removeAttr('href'); 
		}
	})
}
if (getId() == 'mp3' || getId() == 'mp4') {
	var hash = unescape(location.search.substring(1, location.search.length));
	if (hash.length > 0) {
		showPart(hash,null);
	} else { 
		showPart('q1',null);
	}
	$('#subMenu a').click(function(e) {
		if ($(this).parent().is('.current')) { 
			return false;
		};
		a = this.getAttribute('href',2);  a = a.split('#')[1];
		showPart(a,1);
		cancelClick(e);
	});
}
if (!navigator.appVersion.match(/MSIE [0-6]\./)) {
}
	
if (getId() == 'contact') {
// $('#am_contactFormContainer').empty().append(contactFormContents());
prepareContactForm();
}

$('#menuMainUpper').find('li:not(.mp61)').each( function() {
       applyPngSpan(document.body.getAttribute('id'),this);
})

fixFooter();

};

function getId() {
return document.body.getAttribute('id');
};

function applyPngSpan(id,a) {
	var t = $(a); 
	t.hover(function() {
		t.toggleClass('applyPng');
	},function() {
		t.toggleClass('applyPng'); 
	})
};

function showPart(a,b) {
// 	scroll(0,0);
if ($('#contentMain div.section:visible')[0]) {
	var sel = $('#contentMain div.section:visible').attr('id');
	$('#contentMain div.section:visible').hide();
	$('#subMenu li.'+sel).removeClass('current');
}
	$('#'+a).show();
	$('#subMenu li.'+a).addClass('current');
	if (b==1) {
		$("#footer").removeClass("stickToBot");
		fixFooter();
	}
};
function fixIndexBoxHeights() { 
var lh = $("#indContentLeft").height();
var mh = $("#indContentMiddle").height(); 
var rh = $("#indContentRight").height();
var add_lh = $("#indContentLeft .indContentText").height();
var add_mh = $("#indContentMiddle .indContentText").height();
var add_rh = $("#indContentRight .heightFix").height();

var h=0; var ind=0;
var temp=new Array(lh,mh,rh);
for(var i=0;i<temp.length;i++){
	if(temp[i]>h){
	h=temp[i]; ind = i;
	}
}

switch (ind) {
case 0 : 
	var dif1 = lh-mh; $("#indContentMiddle .indContentText").css("height",add_mh+dif1); 
	var dif2 = lh-rh; $("#indContentRight .heightFix").css("height",add_rh+dif2); 
	break;
case 1 :
	var dif1 = mh-lh; $("#indContentLeft .indContentText").css("height",add_lh+dif1); 
	var dif2 = mh-rh; $("#indContentRight .heightFix").css("height",add_rh+dif2); 
	break;
case 2 :
	var dif1 = rh-lh; $("#indContentLeft .indContentText").css("height",add_lh+dif1); 
	var dif2 = rh-mh; $("#indContentMiddle .indContentText").css("height",add_mh+dif2); 
	break;
}

};

function fixFooter() { 
var fMT = 30; // constant, defined in .css == #footer {margin-top: 30px } */
var fOuth = $("#footer").outerHeight();
var offset = $("#footer").offset({ scroll: false }, offset); 

var h = $(window).height()-(offset.top+fOuth);

if (h>0) { 
$("#footer").addClass('stickToBot');
}

};

function cancelClick(e){
		if (window.event){
			window.event.cancelBubble = true;
			window.event.returnValue = false;
		}
		if (e && e.stopPropagation && e.preventDefault){
			e.stopPropagation();
			e.preventDefault();
		}
};
function prepareContactForm() {
	if (jQuery.browser.msie) {
		$('#amcf_submitBtn').hover(function() { 
		$(this).toggleClass("over"); },function() {
		$(this).toggleClass("over"); });
		$('#am_contactform input').focus(function() {$(this).addClass('ieFocus')});
		$('#am_contactform input').blur(function() {$(this).removeClass('ieFocus')});
		$('#am_contactform textarea').focus(function() {$(this).addClass('ieFocus')});
		$('#am_contactform textarea').blur(function() {$(this).removeClass('ieFocus')})
	};
	if($.browser.safari) {
		$("#am_contactform input").addClass('safari');
		$("#am_contactform textarea").addClass('safari');
	}
		$("#am_contactform input").focus( function() { 
			if($(this).next().is(':visible')) { $(this).next().hide('slow')}
		});
		var options = { beforeSubmit: validate, success: showResponse };
		$('#am_contactform').ajaxForm(options);
};

//start of contact form module
function validate(formData, jqForm, options) { 
	var form = jqForm[0];
	var pass = true;
	if (!form.amcf_name.value) { $("#amcf_nameErr").show(); pass = false;}
	if (emailCheck(form.amcf_email.value)) { $("#amcf_emailErr").show(); pass = false; }
	if (!pass) return false;
};

function showResponse()  {
	$('#am_contactform').unbind('submit'); $('#amcf_submitBtn').unbind('click');
	$('#am_contactform').hide('slow',function() {
	$('#am_contactFormContainer').append('<div id="amcf_thankYou" style="display:none"><p>Thank You for contacting us!</p></div>')
	$('#amcf_thankYou').fadeIn('slow')});
};

function emailCheck(value) {
	return !value.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i);
};


