$(document).ready(function() {




  	$("#phonedrop").change(function() {							
	window.location = "/index_v2.php?phonelist=" + $("#phonedrop").val();
	}); 
	
  	$("#phonedrop_fb").change(function() {							
	window.location = "/index_v2.php?phonelist=" + $("#phonedrop_fb").val();
	}); 
	$("#laptoplist").change(function() {
	window.location = "/index_v2.php?phonelist=" + $("#laptoplist").val();
	}); 	



   //if submit button is clicked   
    $('#commentForm').submit(function () {   


 if (!$("#commentForm").valid()){ return false; }									 
        //Get the data from all the fields   
        var name = $('input[name=name]');   
        var email = $('input[name=email]');   
		var rating =$('#rating');
        var device = $('input[name=device]');   
		var comment = $('textarea[name=comment]');   
  
        //Simple validation to make sure user entered something   
        //If error found, add hightlight class to the text field   
		
/*        if (name.val()=='') {   
            name.addClass('hightlight');   
            return false;   
        } else name.removeClass('hightlight');   
           
        if (email.val()=='') {   
            email.addClass('hightlight');   
            return false;   
        } else email.removeClass('hightlight');   
           
        if (comment.val()=='') {   
            comment.addClass('hightlight');   
            return false;   
        } else comment.removeClass('hightlight');   
  */         
        //organize the data properly   
        var data = 'name=' + name.val() + '&email=' + email.val() + '&rating='  
        + rating.val() + '&device=' + device.val() + '&comment='  + encodeURIComponent(comment.val());   
           
        //show the loading sign   
        $('.loading').show();   
           
        //start the ajax   
        $.ajax({   
            //this is the php file that processes the data and send mail   
            url: "/usercomment.php",    
               
            //GET method is used   
            type: "GET",   
  
            //pass the data            
            data: data,        
               
            //Do not cache the page   
            cache: false,   
               
            //success   
            success: function (html) {                 
                //if process.php returned 1/true (send mail success)   
                if (html==1) {                     
                    //hide the form   
                    $('form.userform').fadeOut('slow');                    
                       
                    //show the success message   
                    $('.done').fadeIn('slow');   
			        $('.loading').hide();   
           
                       
                //if process.php returned 0/false (send mail failed)   
                } else alert('Sorry, unexpected error. Please try again later.');                  
            }          
		//	   } 
        });   
           
        //cancel the submit button default behaviours   
        return false;   
    });    



$("a.group").fancybox({
		'zoomSpeedIn':		300, 
		'zoomSpeedOut':	300, 
		'overlayShow':		false
	});

							   
							   


$('li.rating_list').hover(function() {
  $(this).addClass('rating-list-hover');
  $(this).find("h6").addClass('rating-box-hover');
}, function() {
  $(this).removeClass('rating-list-hover');
  $(this).find("h6").removeClass('rating-box-hover');
});



$('li.rating_list').click(function() {
	var l=$(this).attr("data");
	window.location.href = l;
});





$('tr.offersall').hover(function() {
	$(this).addClass('highlight');
	var mouseX = 0;var mouseY = 0;
	$().mousemove( function(e) {   mouseX = e.pageX;    mouseY = e.pageY;

$('div.offertooltip').css( { "left": (mouseX+20) + "px", "top":mouseY + "px" } );
							
	});
	var l=$(this).find("td").attr("data");
 $('div.offertooltip').html(l);
   $('div.offertooltip').addClass('show');
  
  
    //get the position of the placeholder element 
//	var pos = $("#placeholder").offset();
//	var width = $("#placeholder").width(); 
	//show the menu directly over the placeholder
//	$("#menu").css( { "left": (pos.left + width) + "px", "top":pos.top + "px" } );
//	$("#menu").show();
  
  
}, function() {
  $(this).removeClass('highlight');
  $('div.offertooltip').removeClass('show');

//  $(this).find("h6").removeClass('rating-box-hover');
});

$('tr.offersall').click(function() {
	var l=$(this).attr("data");
	window.location.href = l;
});


$('ul.nice-list li').hover(function() {
  $(this).addClass('listhighlight');
  //$(this).find("h6").addClass('rating-box-hover');
}, function() {
  $(this).removeClass('listhighlight');
  //$(this).find("h6").removeClass('rating-box-hover');
});





$("#faq").accordion();


$(".colourselector").click(function(){
	$(".colourselector").removeClass("colouron");
	$(this).addClass("colouron");
	$("#mainphone img").attr("src",$(this).attr("rel"));
	$(this).blur();
	return false;
	});


/* 
	//Default Action
	$(".tab_content").hide(); //Hide all content

	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
*/	
	//
	

//Default Action
$(".tab_content").hide(); //Hide all content
if(location.hash != "") {
var target = location.hash.split("#")[1]
$(location.hash).show(); //Show first tab content
// $("ul.tabs li:has(a[rel="+target+"])").addClass("active").show();;
$("ul.tabs li:has(a[href=#"+target+"])").addClass("active").show();;
} else {
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
}

//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any “active" class
$(this).addClass("active"); //Add “active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});

	
	
	
	
	//

	//Default Action
	$(".tab_content2").hide(); //Hide all content
	$("ul.tabs2 li:first").addClass("active").show(); //Activate first tab
	$(".tab_content2:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs2 li").click(function() {
		$("ul.tabs2 li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content2").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});


function updatecompare(type){

        var phoneid1, phoneid2, phoneid3, url;
        phoneid1 = $("#phonelist1").val();
        phoneid2 = $("#phonelist2").val(); 
        phoneid3 = $("#phonelist3").val(); 
		//nt= Date.getTime();
		var d = new Date();
		var t = d.getTime();
		url="/v2/compare_handsets.php?p1="+phoneid1+"&p2="+phoneid2+"&p3="+phoneid3+"&t="+t;
  //$("#objectID").load("test.php", { 'choices[]': ["Jon", "Susan"] } );
		if (type){
        phoneid1 = $("#laptoplist1").val();
        phoneid2 = $("#laptoplist2").val(); 
        phoneid3 = $("#laptoplist3").val(); 
		url="/v2/compare_laptops.php?p1="+phoneid1+"&p2="+phoneid2+"&p3="+phoneid3+"&t="+t;	
		}

//	alert('type='+url);
		$('#comparetable').hide();
/* 		  $('#loading').fadeIn(); */
		  $('#comparetable').fadeIn(); 

		$("#comparetable").load(url); 
}


//   	$("#phonelist1").bind('change'.(function() {
//$("#phonelist1").unbind('change').bind('change',function() { 
  	$("#phonelist1").change(function() {														 
	updatecompare(0);
   }); 
  	$("#phonelist2").change(function() {														 
	updatecompare(0);
   }); 
  	$("#phonelist3").change(function() {														 
	updatecompare(0);
   }); 

  	$("#laptoplist1").change(function() {														 
	updatecompare(1);
   }); 
  	$("#laptoplist2").change(function() {														 
	updatecompare(1);
   }); 
  	$("#laptoplist3").change(function() {														 
	updatecompare(1);
   }); 





    $("#generate").click(function()
	{ 
     $("#comparetable").load("/v2/compare_handsets.php"); 
   }); 

});