1jQuery.fn.iphoneSwitch = function(start_state, switched_on_callback, switched_off_callback, options) {
2	var state = start_state == '1' ? start_state : '0';
3
4	// define default settings
5	var settings = {
6		mouse_over: 'pointer',
7		mouse_out:  'default',
8		switch_container_path: '/switcherplugin/iphone_switch_container_on.png',
9		switch_path: '/switcherplugin/iphone_switch.png',
10		switch_height: 32,
11		switch_width: 74
12	};
13
14	if(options) {
15		jQuery.extend(settings, options);
16	}
17
18	// create the switch
19	return this.each(function() {
20
21		var container;
22		var image;
23
24		// make the container
25		container = '<div class="iphone_switch_container" style="height:'+settings.switch_height+'px; width:'+settings.switch_width+'px; position: relative; overflow: hidden">';
26
27		// make the switch image based on starting state
28		image = '<img id="iphone_switch" class="iphone_switch" src="'+settings.switch_container_path+'" style="border-radius:7px;height:'+settings.switch_height+'px; width:'+settings.switch_width+'px; background-image:url('+settings.switch_path+'); background-repeat:no-repeat; background-position:'+(state == '1' ? 0 : -37)+'px" /></div>';
29
30		// insert into placeholder
31		jQuery(this).html(container + image);
32
33		jQuery(this).mouseover(function(){
34			jQuery(this).css("cursor", settings.mouse_over);
35		});
36
37		jQuery(this).mouseout(function(){
38			jQuery(this).css("background", settings.mouse_out);
39		});
40
41		// click handling
42		jQuery(this).unbind("click"); // initial click event
43		jQuery(this).click(function() {
44			if((this.id == "radio_clouddisk_enable" || this.id == "radio_web_restrict_enable" || this.id == "apps_analysis_enable" || this.id == "radio_wps_enable" || this.id == "nm_radio_dualwan_enable" || this.id == "simdetect_switch" || this.id == "dns_switch") && typeof(curState))
45				state = curState;
46			else if(this.id.length > 18 && this.id.substr(0, 18) == "wtfast_rule_enable"){
47				var index = (this.id).substr(18);
48				var index_int = parseInt(index);
49				state = rule_enable_array[index_int];
50			}
51
52                        if((this.id == "wandhcp_switch") && typeof(curWandhcpState))
53                                state = curWandhcpState;
54
55			if(state == '1') {
56				jQuery(this).find('.iphone_switch').animate({backgroundPosition: -37}, "slow", function() {
57					jQuery(this).attr('src', settings.switch_container_path);
58					if(typeof(index))
59						switched_off_callback(index);
60					else
61					switched_off_callback();
62				});
63				state = '0';
64			}
65			else {
66				jQuery(this).find('.iphone_switch').animate({backgroundPosition: 0}, "slow", function() {
67					jQuery(this).find('.iphone_switch').attr('src', settings.switch_container_path);
68					if(typeof(index))
69						switched_on_callback(index);
70					else
71					switched_on_callback();
72				});
73				state = '1';
74			}
75		});
76
77	});
78
79};
80