/*
This is some...png fix I need
I cannot tell you what it does
Because this is obviously done by someone else named Angus
*/

// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support
// (c) 2008-2009 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

var IEPNGFix = window.IEPNGFix || {};

IEPNGFix.tileBG = function(elm, pngSrc, ready) {
	// Params: A reference to a DOM element, the PNG src file pathname, and a
	// hidden "ready-to-run" passed when called back after image preloading.

	var data = this.data[elm.uniqueID],
		elmW = Math.max(elm.clientWidth, elm.scrollWidth),
		elmH = Math.max(elm.clientHeight, elm.scrollHeight),
		bgX = elm.currentStyle.backgroundPositionX,
		bgY = elm.currentStyle.backgroundPositionY,
		bgR = elm.currentStyle.backgroundRepeat;

	// Cache of DIVs created per element, and image preloader/data.
	if (!data.tiles) {
		data.tiles = {
			elm: elm,
			src: '',
			cache: [],
			img: new Image(),
			old: {}
		};
	}
	var tiles = data.tiles,
		pngW = tiles.img.width,
		pngH = tiles.img.height;

	if (pngSrc) {
		if (!ready && pngSrc != tiles.src) {
			// New image? Preload it with a callback to detect dimensions.
			tiles.img.onload = function() {
				this.onload = null;
				IEPNGFix.tileBG(elm, pngSrc, 1);
			};
			return tiles.img.src = pngSrc;
		}
	} else {
		// No image?
		if (tiles.src) ready = 1;
		pngW = pngH = 0;
	}
	tiles.src = pngSrc;

	if (!ready && elmW == tiles.old.w && elmH == tiles.old.h &&
		bgX == tiles.old.x && bgY == tiles.old.y && bgR == tiles.old.r) {
		return;
	}

	// Convert English and percentage positions to pixels.
	var pos = {
			top: '0%',
			left: '0%',
			center: '50%',
			bottom: '100%',
			right: '100%'
		},
		x,
		y,
		pc;
	x = pos[bgX] || bgX;
	y = pos[bgY] || bgY;
	if (pc = x.match(/(\d+)%/)) {
		x = Math.round((elmW - pngW) * (parseInt(pc[1]) / 100));
	}
	if (pc = y.match(/(\d+)%/)) {
		y = Math.round((elmH - pngH) * (parseInt(pc[1]) / 100));
	}
	x = parseInt(x);
	y = parseInt(y);

	// Handle backgroundRepeat.
	var repeatX = { 'repeat': 1, 'repeat-x': 1 }[bgR],
		repeatY = { 'repeat': 1, 'repeat-y': 1 }[bgR];
	if (repeatX) {
		x %= pngW;
		if (x > 0) x -= pngW;
	}
	if (repeatY) {
		y %= pngH;
		if (y > 0) y -= pngH;
	}

	// Go!
	this.hook.enabled = 0;
	if (!({ relative: 1, absolute: 1 }[elm.currentStyle.position])) {
		elm.style.position = 'relative';
	}
	var count = 0,
		xPos,
		maxX = repeatX ? elmW : x + 0.1,
		yPos,
		maxY = repeatY ? elmH : y + 0.1,
		d,
		s,
		isNew;
	if (pngW && pngH) {
		for (xPos = x; xPos < maxX; xPos += pngW) {
			for (yPos = y; yPos < maxY; yPos += pngH) {
				isNew = 0;
				if (!tiles.cache[count]) {
					tiles.cache[count] = document.createElement('div');
					isNew = 1;
				}
				var clipR = Math.max(0, xPos + pngW > elmW ? elmW - xPos : pngW),
					clipB = Math.max(0, yPos + pngH > elmH ? elmH - yPos : pngH);
				d = tiles.cache[count];
				s = d.style;
				s.behavior = 'none';
				s.left = (xPos - parseInt(elm.currentStyle.paddingLeft)) + 'px';
				s.top = yPos + 'px';
				s.width = clipR + 'px';
				s.height = clipB + 'px';
				s.clip = 'rect(' +
					(yPos < 0 ? 0 - yPos : 0) + 'px,' +
					clipR + 'px,' +
					clipB + 'px,' +
					(xPos < 0 ? 0 - xPos : 0) + 'px)';
				s.display = 'block';
				if (isNew) {
					s.position = 'absolute';
					s.zIndex = -999;
					if (elm.firstChild) {
						elm.insertBefore(d, elm.firstChild);
					} else {
						elm.appendChild(d);
					}
				}
				this.fix(d, pngSrc, 0);
				count++;
			}
		}
	}
	while (count < tiles.cache.length) {
		this.fix(tiles.cache[count], '', 0);
		tiles.cache[count++].style.display = 'none';
	}

	this.hook.enabled = 1;

	// Cache so updates are infrequent.
	tiles.old = {
		w: elmW,
		h: elmH,
		x: bgX,
		y: bgY,
		r: bgR
	};
};


IEPNGFix.update = function() {
	// Update all PNG backgrounds.
	for (var i in IEPNGFix.data) {
		var t = IEPNGFix.data[i].tiles;
		if (t && t.elm && t.src) {
			IEPNGFix.tileBG(t.elm, t.src);
		}
	}
};
IEPNGFix.update.timer = 0;

if (window.attachEvent && !window.opera) {
	window.attachEvent('onresize', function() {
		clearTimeout(IEPNGFix.update.timer);
		IEPNGFix.update.timer = setTimeout(IEPNGFix.update, 100);
	});
}

/*
This is the end of png fix
Please find Angus
*/

/* ----------------------------------------------------- */

/*
This is some random functions
It's your life/death choice in editing the below
*/

$(function(){
	
	
	if($(window).height()==$(document).height()-10||$(window).height()<$(document).height()-10){
		$("#not_index #footer").css('width','100%');
		$("#not_index #footer").css('position','absolute');
		$("#not_index #footer").css('top',$(document).height());
		$(window).resize(function() {
		  $("#not_index #footer").css('top','');
		  $("#not_index #footer").css('bottom','0px');
		  if($(window).height()<$(document).height()){
			  $("#not_index #footer").css('bottom','');
			  $("#not_index #footer").css('top',$(document).height());
		  }else{
			  $("#not_index #footer").css('top','');
			  $("#not_index #footer").css('bottom','0px');
		  }
		});
	}
	
	
	$('#full_container #container #nav ul li ul').hover(
		function(){$(this).siblings('a').addClass('over');},
		function(){$(this).siblings('a').removeClass('over');}
	);
	
	$('#nav ul ul').hide();
	
	$('#full_container #container #nav ul li').hover(
		function(){$(this).children('ul').show();},
		function(){$(this).children('ul').hide();}
	);
	
	function bannerRotate(){
		for(var i=2;i<5;i++){
			$('#banner #no'+i).hide();
		}
		
		var j=2;
	
		var bannerImg=window.setInterval(function() {
			
			if(j>4){
				$('#banner #no1').fadeIn('slow');
				$('#banner #no4').fadeOut('slow');
				j=1;
			}else{
				$('#banner #no'+j).fadeIn('slow');
				$('#banner #no'+(j-1)).fadeOut('slow');
				j++;
			};
			
		},8000);
	}
	
	bannerRotate();
	
	$('#scrollup').mouseover(
	function() {
		$(this).siblings('#img_container').children('ul').animate({top: 0}, {duration: 1000, easing: 'swing'});
	}).mouseout(function() {
		$(this).siblings('#img_container').children('ul').stop();
	});
	
	$('#scrolldown').mouseover(
	function() {
		$(this).siblings('#img_container').children('ul').animate({top: "-"+($(this).siblings('#img_container').children('ul').height()-356)}, {duration: 1000, easing: 'swing'});
	}).mouseout(function() {
		$(this).siblings('#img_container').children('ul').stop();
	});
	
	$('#gallery img').hide();
	$('#gallery div.big_img_container:first-child img').fadeIn(1500);
	$('#gallery div:nth-child(2) img').fadeIn(1500);
	$('#single_img li:first-child').children('.selected_png').addClass('over')
	
	var curr_img = "";
	$('#single_img li').mouseover(function(){
		var single_src_arr = $(this).children('.small_img_container').children('img.thumbnail').attr('src').split('/');
		$('#single_img li .selected_png').removeClass('over');
		$(this).children('.selected_png').addClass('over')
		var big_img = single_src_arr[single_src_arr.length-1].split('tn')[1];
		$('#gallery img').each(function(index) {
			if($(this).attr('id')=='img'+big_img.split('.')[0]){
				$(this).fadeIn(1000);
			}else{
				$(this).fadeOut(1500).stop(true,true);
			}
		});
	});
	
	$('#submit').click(function(e){
		e.preventDefault();
		$error = false;
		if($('#fullname').val()==""){
			alert('Full Name is a mandatory field');
			$error = true;
			return false;
		}
		if(!fnCheckString($('#fullname').val())){
			alert('Please check if Full Name field is valid');
			$error = true;
			return false;
		}
		
		if($('#company').val()==""){
			alert('Company is a mandatory field');
			$error = true;
			return false;
		}
		if(!fnCheckString($('#company').val())){
			alert('Please check if Company field is valid');
			$error = true;
			return false;
		}
		
		if($('#email').val()==""){
			alert('Email is a mandatory field');
			$error = true;
			return false;
		}
		if(!CheckEmail($('#email').val())){
			alert('Please check if Email field is valid');
			$error = true;
			return false;
		}
		
		if($('#contact').length==""){
			alert('Contact is a mandatory field');
			$error = true;
			return false;
		}

		if(isNaN($('#contact').val())||$('#contact').val().length<8){
			alert('Please check if Contact field is valid');
			$error = true;
			return false;
		}
		
		if($('#subject').val()==""){
			alert('Subject is a mandatory field');
			$error = true;
			return false;
		}
		if(!fnCheckString($('#subject').val())){
			alert('Please check if Subject field is valid');
			$error = true;
			return false;
		}
		
		if($('#message').val()==""){
			alert('Message is a mandatory field');
			$error = true;
			return false;
		}
		
		if($('#recaptcha_response_field').val()==""){
			alert('Please fill in the Checksum');
			$error = true;
			return false;
		}

		if($error){
			return false;
		}
		$('#contact_form').submit();
	});
	
	function fnCheckString(str){
		var re=/^[- a-z.']+$/i;
		return re.test(str);
	}
	
	function CheckEmail(s_email){
		// developed by willmaster.com
		var i = s_email.indexOf(' ',0);
		while(i > -1){
			s_email = s_email.substring(0,i) +
				s_email.substring((i + 1),s_email.length);
			i = s_email.indexOf(' ',0);
		}
		if((s_email.length < 6) ||
		   (s_email.indexOf('@',0) < 1) ||
		   (s_email.lastIndexOf('@') != s_email.indexOf('@',0)) ||
		   (s_email.lastIndexOf('@') > (s_email.length - 5)) ||
		   (s_email.lastIndexOf('.') > (s_email.length - 3)) ||
		   (s_email.lastIndexOf('.') < (s_email.length - 4)) ||
		   (s_email.indexOf('..',0) > -1) ||
		   (s_email.indexOf('@.',0) > -1) ||
		   (s_email.indexOf('.@',0) > -1) ||
		   (s_email.indexOf(',',0) > -1))
		{
			return false;
		}
		return true;
	}

	
	$('#project_new').submit(function(e){
		$('.error').remove();
		$error = false;
		if($('#project_new #title').val()==""){
			$('#project_new #title').parent('td').append("<div class=\"error\">The <strong><em>Title</em></strong> field is required.</div>");
			$error = true;
		}
		if($('#thumbnail_upload').val()==""){
			$('#thumbnail_upload').parent('td').append("<div class=\"error\">The <strong><em>Thumbnail Upload</em></strong> field is required.</div>");
			$error = true;
		}
		if($('#image_upload_1').val()==""&&$('#image_upload_2').val()==""&&$('#image_upload_3').val()==""&&$('#image_upload_4').val()==""&&$('#image_upload_5').val()==""){
			$('#image_upload_1').parent('td').append("<div class=\"error\">At least <strong>one</strong> image is needed.</div>");
			$error = true;
		}

		if($error){
			e.preventDefault();
		}
	});
	
	$('#project_edit').submit(function(e){
		$('.error').remove();
		$error = false;
		if($('#project_new #title').val()==""){
			$('#project_new #title').parent('td').append("<div class=\"error\">The <strong><em>Title</em></strong> field is required.</div>");
			$error = true;
		}
		
		old_img_arr = $(this).children('#old_images').val().split('||');
		
		$('.remove_img:checked').each(function(index) {
			var removeItem = $(this).val();
			old_img_arr = jQuery.grep(old_img_arr, function(value) {
					return value != removeItem;
			});
		});
		if(old_img_arr.length==1&&$('#image_upload_1').val()==""&&$('#image_upload_2').val()==""&&$('#image_upload_3').val()==""&&$('#image_upload_4').val()==""&&$('#image_upload_5').val()==""){
			$('#image_upload_1').parent('td').append("<div class=\"error\">At least <strong>one</strong> image is needed.</div>");
			$error = true;
		}
		if($error){
			e.preventDefault();
		}
	});
	
});
/*
This is the end of random functions
Go away, that's all it's in here
*/
