var a;
var b;
var c;
var d;
var e;
var l;
var reloadValue = window.location.hash.replace(/^#/, '');
	if(reloadValue != "" && reloadValue != null){
	window.location.replace(reloadValue);
}
function touchHandler(event)
{
    var touches = event.changedTouches,
        first = touches[0],
        type = "";
         switch(event.type)
    {
        case "touchstart": type = "mousedown"; break;
        case "touchmove":  type="mousemove"; break;        
        case "touchend":   type="mouseup"; break;
        default: return;
    }

             //initMouseEvent(type, canBubble, cancelable, view, clickCount, 
    //           screenX, screenY, clientX, clientY, ctrlKey, 
    //           altKey, shiftKey, metaKey, button, relatedTarget);
    
    var simulatedEvent = document.createEvent("MouseEvent");
    simulatedEvent.initMouseEvent(type, true, true, window, 1, 
                              first.screenX, first.screenY, 
                              first.clientX, first.clientY, false, 
                              false, false, false, 0/*left*/, null);

                                                                                 first.target.dispatchEvent(simulatedEvent);
}


function submitForm(){
	var name = document.getElementById('name').value;
	var email = document.getElementById('email').value;
	var message = document.getElementById('message').value;
	if(name == "Name"){
		alert("Please fill out your name");
		$("#submitSlider").slider({value:0});
		document.getElementById('name').focus();
		return;
	}
	if(email == "E-mail"){
		alert("Please fill out your email");
		$("#submitSlider").slider({value:0});
		document.getElementById('email').focus();
		return;
	}
	if(message == "Describe your problem" || message == "Please describe the project as much as possible" || message == "Message"){
		alert("Please write a message");
		$("#submitSlider").slider({value:0});
		document.getElementById('message').focus();
		return;
	}
	var subject = document.getElementById('subject').value;
	var data = "name="+name+"&email="+email+"&message="+message+"&subject="+subject;
	
	//Possible
	
	if(document.getElementById('website')){
		data += "&website="+document.getElementById('website').value;
	}
	if(document.getElementById('budget')){
		data += "&budget="+document.getElementById('budget').value;
	}
	if(document.getElementById('product')){
		data += "&product="+document.getElementById('product').value;
	}
	if(document.getElementById('oshardware')){
		data += "&hardware=" + document.getElementById('oshardware').value;
	}
	$('input').attr('disabled','disabled');
	$('textarea').attr('disabled','disabled');
	$.ajax({url:"sendmail.php",type:"POST",data:data,cache:false,success:function(html){
																		$('.envelop').animate({opacity:0},300,function(){
																		$('.envelop').css({"vertical-align":"middle"});
																		$('.envelop').html('<div class="messagePick">Your message was sent successfully. To send another message, pick a topic</div>');
																		$("#submitSlider").slider({disabled:true,value:0});
																		$('.mailBox').css({opacity:0});
																		$('.dragText').css({opacity:0});
																		$('#submitSlider').css({opacity:0});
																		$('#submitSlider a').css({"cursor":"default"});
																		$('.envelop').animate({opacity:1},300);
																		
																													   });
																		}});
	
}
function doSparkle(id){
	$("."+id).animate({opacity:0.8},1500,function(){
											   $("."+id).animate({opacity:0},2500);
										   });
}
function startSparkle(id,sender){
	clearInterval(sender);
	window.setInterval("doSparkle('"+id+"')", 4000);
}
function sparkles(){
	return;
	a = window.setInterval("startSparkle('sp1',a)",0);
	b = window.setInterval("startSparkle('sp2',b)",1000);
	c = window.setInterval("startSparkle('sp3',c)",2500);
	d = window.setInterval("startSparkle('sp4',d)",3400);
	e = window.setInterval("startSparkle('sp5',e)",6000);
}
function loadHash(){
	var hash = window.location.hash;
	hash = hash.replace(/^.*#/,"");
	if(hash){
		$(".container").hide('drop',function(){
													 $(".container").load(hash + " .content",function(){
																										   document.title = $("#title").html();
																										checkStuff();
																									     
																									  $('.container').show('drop');
																									  });
													 });
	}
	else{
		hash = window.location;
		$('#titleContainer').load(hash + ' #title',function(){
															document.title = $("#title").html();
															});
		$(".container").load(hash + " .content",function(){checkStuff();});
	}
}
function nothing(){
}
function pickTopic(id){
	$('.mailBox').css({opacity:1});
	$('.dragText').css({opacity:1});
	$('#submitSlider').css({opacity:1});
	$('#submitSlider').slider({disabled:false});
	$('#submitSlider a').css({"cursor":"default"});
	if(id == 'general'){
		$('.envelop').html('<input type="hidden" id="subject" value="General enquiry" /><input id="name" name="name" type="text" size="46" value="Name" style="color:#999999;margin-top:30px;" onfocus="if(this.value==\'Name\'){	this.value = \'\';this.setAttribute(\'style\',\'color: #000;margin-top:30px;\');}" onblur="if(this.value==\'\'){	this.value = \'Name\';this.setAttribute(\'style\',\'color: #999;margin-top:30px;\');}" /><input id="email" name="email" type="text" size="46" value="E-mail" style="color:#999999" onfocus="if(this.value==\'E-mail\'){this.value = \'\';this.setAttribute(\'style\',\'color: #000\');}" onblur="if(this.value==\'\'){this.value = \'E-mail\';    this.setAttribute(\'style\',\'color: #999\');}" /><textarea id="message" style="height:280px" name="message" onfocus="if(this.value==\'Message\'){this.value = \'\';    this.setAttribute(\'style\',\'color: #000;height:280px\');}" onblur="if(this.value==\'\'){	this.value = \'Message\';    this.setAttribute(\'style\',\'color: #999;height:280px\');}">Message</textarea>');
	}
	else if(id == 'press'){
		$('.envelop').html('<input type="hidden" id="subject" value="Press" /><input id="name" name="name" type="text" size="46" value="Name" style="color:#999999;margin-top:30px;" onfocus="if(this.value==\'Name\'){	this.value = \'\';this.setAttribute(\'style\',\'color: #000;margin-top:30px;\');}" onblur="if(this.value==\'\'){this.value = \'Name\';    this.setAttribute(\'style\',\'color: #999;margin-top:30px;\');}" /><input id=\"email\" name=\"email\" type=\"text\" size=\"46" value="E-mail" style="color:#999999" onfocus="if(this.value==\'E-mail\'){this.value = \'\';\   this.setAttribute(\'style\',\'color: #000\');}" onblur="if(this.value==\'\'){	this.value = \'E-mail\';    this.setAttribute(\'style\',\'color: #999\');}" /><input id="website" name="email" type="text" size="46" value="Website" style="color:#999999" onfocus="if(this.value==\'Website\'){this.value = \'\';    this.setAttribute(\'style\',\'color: #000\');}" onblur="if(this.value==\'\'){	this.value = \'Website\';    this.setAttribute(\'style\',\'color: #999\');}" /><textarea id="message" style="height:235px" name="message" onfocus="if(this.value==\'Message\'){this.value = \'\';    this.setAttribute(\'style\',\'color: #000;height:235px\');}" onblur="if(this.value==\'\'){	this.value = \'Message\';    this.setAttribute(\'style\',\'color: #999;height:235px\');}">Message</textarea>');
	}
	else if(id == 'support'){
		$('.envelop').html('<input name="subject" id="subject" type="hidden" value="Support" /><input id="name" name="name" type="text" size="46"value="Name" style="color:#999999;margin-top:30px;" onfocus="if(this.value==\'Name\'){	this.value = \'\';    this.setAttribute(\'style\',\'color: #000;margin-top:30px;\');}" onblur="if(this.value==\'\'){	this.value = \'Name\';    this.setAttribute(\'style\',\'color: #999;margin-top:30px;\');}" /><input id="email" name="email" type="text" size="46" value="E-mail" style="color:#999999" onfocus="if(this.value==\'E-mail\'){	this.value = \'\';    this.setAttribute(\'style\',\'color: #000\');}" onblur="if(this.value==\'\'){	this.value = \'E-mail\';    this.setAttribute(\'style\',\'color: #999\');}" /><input id="product" name="product" type="text" size="46" value="Product you need support for" style="color:#999999" onfocus="if(this.value==\'Product you need support for\'){	this.value = \'\';    this.setAttribute(\'style\',\'color: #000\');}" onblur="if(this.value==\'\'){this.value = \'Product you need support for\'; this.setAttribute(\'style\',\'color: #999\');}" /><input id="oshardware" name="oshardware" type="text" size="46" value="Details about your operating system/firmware and hardware" style="color:#999999;font-size:14px" onfocus="if(this.value==\'Details about your operating system/firmware and hardware\'){	this.value = \'\';    this.setAttribute(\'style\',\'color: #000\');}" onblur="if(this.value==\'\'){	this.value = \'Details about your operating system/firmware and hardware\';    this.setAttribute(\'style\',\'color: #999;font-size:14px\');}" /><textarea id="message" name="message" onfocus="if(this.value==\'Describe your problem\'){	this.value = \'\';    this.setAttribute(\'style\',\'color: #000\');}" onblur="if(this.value==\'\'){	this.value = \'Describe your problem\';    this.setAttribute(\'style\',\'color: #999;\');}">Describe your problem</textarea>');
	}
	else{
		$('.envelop').html("<input type=\"hidden\" id=\"subject\" value=\"Custom solution\" /><input id=\"name\" value='Name' name=\"name\" type=\"text\" size=\"46\ value=\"Name\" style=\"color:#999999;margin-top:30px;\" onfocus=\"if(this.value=='Name'){	this.value = \'\';    this.setAttribute('style','color: #000;margin-top:30px;');}\" onblur=\"if(this.value==''){	this.value = 'Name';    this.setAttribute('style','color: #999;margin-top:30px;');}\" /><input id=\"email\" name=\"email\" type=\"text\" size=\"46\" value=\"E-mail\" style=\"color:#999999\" onfocus=\"if(this.value=='E-mail'){this.value = '';    this.setAttribute('style','color: #000');}\" onblur=\"if(this.value==\'\'){	this.value = 'E-mail';    this.setAttribute('style','color: #999	');}\" /><input id=\"website\" name=\"email\" type=\"text\" size=\"46\" value=\"Website\" style=\"color:#999999\" onfocus=\"if(this.value=='Website'){	this.value = '';    this.setAttribute('style','color: #000');}\" onblur=\"if(this.value==\'\'){	this.value = 'Website';    this.setAttribute('style','color: #999	');}\" /><input id=\"budget\" name=\"budget\" type=\"text\" size=\"46\" value=\"Budget\" style=\"color:#999999\" onfocus=\"if(this.value=='Budget'){	this.value = \'\';    this.setAttribute('style','color: #000');}\" onblur=\"if(this.value==\'\'){	this.value = 'Budget';    this.setAttribute('style','color: #999	');}\" /><textarea id=\"message\" style=\"height:190px\" name=\"message\" onfocus=\"if(this.value=='Please describe the project as much as possible'){this.value = \'\';    this.setAttribute('style','color: #000;height:190px');}\" onblur=\"if(this.value==\'\'){	this.value = 'Please describe the project as much as possible';    this.setAttribute('style','color: #999;height:190px');}\">Please describe the project as much as possible</textarea>");
	}
}
function checkStuff(){
	$('.mailBox').css({opacity:0});
	$('.dragText').css({opacity:0});
	$('#postComment').removeAttr('slide').slider({animate:true, max:30, step:1,stop:function(ui){
																							 if(ui.value <= 27){
																								 return;
																							}
																							var name = $("#name").val();
																							var site = $("#website").val();
																							var email = $("#email").val();
																							var id = $("#id").val();
																							var msg = $('textarea').val();
																							if(name == "Name"){
																								alert('Please fill your name');
																								$('#postComment').slider({value:0});
																								return;
																							}
																							if(email == "Email"){
																								alert('Please fill your email');
																								$('#postComment').slider({value:0});
																								return;
																							}
																							if(msg == "Comment"){
																								alert('Please write a comment');
																								$('#postComment').slider({value:0});
																								return;
																							}
																							var data = "name="+name+"&site="+site+"&email="+email+"&id="+id+"&msg="+msg;
																							$.ajax({url:"comment.php",type:"POST",data:data,cache:false,success:function(html){
			
																		$('#commentToPost').animate({opacity:0},300,function(){
																		$('#commentToPost').css({"padding-top":"200px"});
																		$('#commentToPost').css({"height":"200px"});
																		$('#commentToPost').css({"text-align":"center"});
																		$('#commentToPost').html('Your comment was posted successfully. It will appear after someone approve it');
																		$('#commentToPost').animate({opacity:1},300);
																		
																													   });
																		}});
																							 }});
	$('#postComment a').css('background','url(images/face.png)');
	$('#postComment a').css('height','62px');
	$('#postComment a').css('width','60px');
	$('#submitSlider').removeAttr('slide').slider({animate:true,max:30,step:1,disabled:true,stop:function(event,ui){
																		if(ui.value < 29){
																			return;
																		}
																		else{
																			submitForm();
																		}
																		
																		}});
	$('#submitSlider').css({opacity:0});
																		$('#submitSlider a').css({"cursor":"default"});
																		
	$('.insideLink').click(function(){
									var hash = this.href;
									hash = hash.replace(/^.*#/,"");
									$.history.load(hash);
									return false;
									});
	if(document.getElementById('submitSlider')){
		document.getElementById('submitSlider').setAttribute('ontouchstart','event.preventDefault();');
	}
}
$(document).ready(function(){
								document.addEventListener("touchstart", touchHandler, true);
    document.addEventListener("touchmove", touchHandler, true);
    document.addEventListener("touchend", touchHandler, true);
    document.addEventListener("touchcancel", touchHandler, true); 
						   checkStuff();
						   $(window).hashchange(function(){loadHash();});
							$.history.init(nothing);
						   sparkles();
						  	});
function showiOS(){
		$("#Mac").animate({opacity:0},400);
		$("#Cases").animate({opacity:0},400);
		$("#Free").animate({opacity:0},400,function(){
													$("#Mac").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Cases").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Free").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#iOS").css({width:"auto",height:"auto",'z-index':30,"margin-left":"93px"});
													$("#iOS").animate({opacity:1},400);
													});
}
function showMac(){
		$("#iOS").animate({opacity:0},400);
		$("#Cases").animate({opacity:0},400);
		$("#Free").animate({opacity:0},400,function(){
													$("#iOS").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Cases").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Free").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Mac").css({height:"auto",width:"auto",'z-index':30,"margin-left":"93px"});
													$("#Mac").animate({opacity:1},400);
													});
}
function showCases(){
		$("#iOS").animate({opacity:0},400);
		$("#Mac").animate({opacity:0},400);
		$("#Free").animate({opacity:0},400,function(){
													$("#iOS").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Mac").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Free").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Cases").css({height:"auto",width:"auto",'z-index':30,"margin-left":"93px"});
													$("#Cases").animate({opacity:1},400);
													});
}
function showFree(){
		$("#iOS").animate({opacity:0},400);
		$("#Cases").animate({opacity:0},400);
		$("#Mac").animate({opacity:0},400,function(){
													$("#iOS").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Cases").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Mac").css({height:'0px',width:'0px','z-index':20,"margin-left":"0px"});
													$("#Free").css({height:"auto",width:"auto",'z-index':30,"margin-left":"93px"});
													$("#Free").animate({opacity:1},400);
		
		});
}
