$(function (){
    $('.linkedpanel').each(function (){

        var self = $(this);
        var link = self.find("a");
        var url = link.attr("href");
        link.attr("href", "javascript:void(0);");
        self.mouseenter(function (){
            self.toggleClass("hover", true).css("cursor", "pointer");
        }).mouseleave(function (){
            self.toggleClass("hover", false).css("cursor", "default");
        }).click(function (){
            location.href = base_href+url;
            
        });
    });
});
$(function (){
	$('#referal').change(function (){
		toggle(this);
	}).each(function (){
		toggle(this);
	});
	
	$('#qualification_expertise').change(function (){
		toggle_expertise(this);
	})
	
});
function toggle (x){
	if ($(x).val() == "Other"){
		$('#findout_other').show();
	}else {
		$('#findout_other').hide();
	}
}

function toggle_expertise (x){
	if ($(x).val() == "other"){
		$('#expertise_other').show();
	}else {
		$('#expertise_other').hide();
	}
}
$(document).ready(function() {
	$("a.videopreview").click(function (){
	   var link = $(this);
        $("#overlay").overlay({ 
		    expose: { 	 
		        color: '#000', 
		        loadSpeed: 200, 
		        opacity: 0.5 
		    },
		    closeOnClick: true, 
            onBeforeLoad: function() {
                var flashvars = { 'src':link.attr("rel"),'name':link.attr("title") };
				var params = {'allowScriptAccess':'always', 'allowFullScreen':'true'};
				swfobject.embedSWF("./flash/vidplayer.swf", "swfwrap", "699", "502", "9.0.115", null, flashvars, params, false);
            },
            api: true  
        }).load();
    }); 


	$("#email-signup-form").submit(function(e){
	
		var api = $("#prompt").overlay({
			// custom top position 
		    top: 272, 
		    expose: { 	 
		        // you might also consider a "transparent" color for the mask 
		        color: '#000', 
		        // load mask a little faster 
		        loadSpeed: 200, 
		        // highly transparent 
		        opacity: 0.5 
		    },  
		    onBeforeLoad: function() { 
		    	  var wrap = $("#contentWrap"); 
		    	  var postdata= $("#email-signup-form").serialize();
		    	  wrap.load(base_href + 'subscribe/?' + postdata );
	        },
		    // disable this for modal dialog-type of overlays 
		    closeOnClick: true, 
		    // we want to use the programming API 
		    api: true 
		// load it immediately after the construction 
		});

		api.load();

		return false;
	});
	
	$("#termsandconditions").click(function(e){
	
		var api = $("#termsandconditions_prompt").overlay({
			// custom top position 
		    top: 0, 
		    expose: { 	 
		        // you might also consider a "transparent" color for the mask 
		        color: '#000', 
		        // load mask a little faster 
		        loadSpeed: 200, 
		        // highly transparent 
		        opacity: 0.5 
		    },  
		    onBeforeLoad: function() { 
		    	 	// grab wrapper element inside content
					var wrap = this.getOverlay().find(".contentWrap");
					// load the page specified in the trigger
					wrap.load($('#termsandconditions').attr("href")+'AJAX');

	        },
		    // disable this for modal dialog-type of overlays 
		    closeOnClick: true, 
		    // we want to use the programming API 
		    api: true 
		// load it immediately after the construction 
		});
		
		api.load();
		
		return false;
	});
	
	
	$("#deliverydetails").click(function(e){
	
		var api = $("#deliverydetails_prompt").overlay({
			// custom top position 
		    top: 20, 
		    expose: { 	 
		        // you might also consider a "transparent" color for the mask 
		        color: '#000', 
		        // load mask a little faster 
		        loadSpeed: 200, 
		        // highly transparent 
		        opacity: 0.5 
		    },  
		    onBeforeLoad: function() { 
		    	 	// grab wrapper element inside content
					var wrap = this.getOverlay().find(".contentWrap");
					// load the page specified in the trigger
					wrap.load($('#deliverydetails').attr("href")+'AJAX');

	        },
		    // disable this for modal dialog-type of overlays 
		    closeOnClick: true, 
		    // we want to use the programming API 
		    api: true 
		// load it immediately after the construction 
		});
		
		api.load();
		
		return false;
	});


	$("#cv2_info").click(function(){

		var api = $("#cv2_prompt").overlay({
			// custom top position 
			width:900,
		    top: 0, 
		    expose: { 	 
		        // you might also consider a "transparent" color for the mask 
		        color: '#000', 
		        // load mask a little faster 
		        loadSpeed: 200, 
		        // highly transparent 
		        opacity: 0.5 
		    },  
		    // disable this for modal dialog-type of overlays 
		    closeOnClick: true, 
		    // we want to use the programming API 
		    api: true 
		// load it immediately after the construction 
		});

		api.load();

		return false;
	});

	$("#issue_info").click(function(){

		var api = $("#issue_prompt").overlay({
			// custom top position 
			width:900,
		    top: 0, 
		    expose: { 	 
		        // you might also consider a "transparent" color for the mask 
		        color: '#000', 
		        // load mask a little faster 
		        loadSpeed: 200, 
		        // highly transparent 
		        opacity: 0.5 
		    },  
		    // disable this for modal dialog-type of overlays 
		    closeOnClick: true, 
		    // we want to use the programming API 
		    api: true 
		// load it immediately after the construction 
		});

		api.load();

		return false;
	});
	
	$("#why_register").click(function(){

		var api = $("#why_register_prompt").overlay({
			// custom top position 
			width:900,
		    top: 0, 
		    expose: { 	 
		        // you might also consider a "transparent" color for the mask 
		        color: '#000', 
		        // load mask a little faster 
		        loadSpeed: 200, 
		        // highly transparent 
		        opacity: 0.5 
		    },  
		    // disable this for modal dialog-type of overlays 
		    closeOnClick: true, 
		    // we want to use the programming API 
		    api: true 
		// load it immediately after the construction 
		});

		api.load();

		return false;
	});
	
	$('#close').click(function(e){
		 $("#prompt").overlay().close(); 
	});

	$('#close_popup').click(function(e){
		 $("#cv2_prompt").overlay().close(); 
		 $("#deliverydetails_prompt").overlay().close();
	});
	
	$('#close_issue_popup').click(function(e){
		 $("#issue_prompt").overlay().close(); 
	});
	
	$('#close_popup_tc').click(function(e){
		 $("#termsandconditions_prompt").overlay().close(); 
	});

});

function doSignup() {
	var subscribe = true;
	if ($("#unsubscribe") == true) {
		subscribe = false;
	}

	var data = $("#email-popup-form").serialize()
	$.post(base_href + "subscribe/", {
		'data' : data,
		'subscribe' : subscribe,
		'ajax' : true
	}, function(transport) {
		var result = transport;
		if (result.msg != "OK") {
			var html = "";
			var errors = result.error;
			$.each(errors, function() {
				html += "<li>" + this + "</li>"
			});

			$("#errors").html("<ul>" + html + "</ul>");
			$("#errors").show();

		} else {

			$("#content_area").hide();
			$("#content_msg").html("<p>" + result.content + "</p>");
			$("#content_msg").show();
		}
	}, "json");
}

