/* (c) Copyright 2007-2008 favicon.cc */
var USE_ANIMATION=1;var CURSOR_PATH="/images/cursors";var MAX_FRAMES=100;var ICON_COLUMNS=16;var ICON_ROWS=16;var DEFAULT_DELAY_SECS=1;var DELAY_LIST=[5,10,20,30,40,50,60,70,80,90,100,150,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000];var favicon_matrix;var mover_started;var start_mover_row;var start_mover_column;var last_mover_row;var last_mover_column;var moved_image_changed;var current_frame;var animation_matrix;var delays;var iterations;var frame_count;var animated_frame;function initialize_ordinary_page(){}function initialize_create_page(){initialize_color_picker();initialize_mover();current_frame=1;initialize_animation();if(USE_ANIMATION){frame_duration_changed();if(frame_count>1){use_animation()}}Event.observe("big_icon","mousedown",mouse_down_on_icon)}function initialize_mover(){mover_started=0;start_mover_row=0;start_mover_column=0;last_mover_row=0;last_mover_column=0;moved_image_changed=1;favicon_matrix=[];for(var A=1;A<=ICON_ROWS;A++){favicon_matrix[A]=[]}}function initialize_animation(){animation_matrix=[];delays=[];if($("frame_count")){frame_count=$("frame_count").value;for(var D=1;D<=frame_count;D++){animation_matrix[D]=[];for(var C=1;C<=ICON_ROWS;C++){animation_matrix[D][C]=[];if($(get_pixel_field_name(C,D))){var B=$(get_pixel_field_name(C,D)).value;for(var A=1;A<=ICON_COLUMNS;A++){if(B.match(/^trans/)){B=B.replace(/^trans/,"");animation_matrix[D][C][A]="trans"}else{if(B.match(/^[\dA-F]{6}/i)){animation_matrix[D][C][A]=B.match(/^[\dA-F]{6}/i);B=B.replace(/^[\dA-F]{6}/i,"")}else{alert("parsing error: "+B)}}}}else{for(var A=1;A<=ICON_COLUMNS;A++){animation_matrix[D][C][A]="trans"}}}if($("delays-f"+D)){delays[D]=get_closest($("delays-f"+D).value)}else{delays[D]=100*DEFAULT_DELAY_SECS}}}else{initialize_frame(1)}if(USE_ANIMATION){display_animation_controls();initialize_small_animation()}}function initialize_frame(C){animation_matrix[C]=[];for(var B=1;B<=ICON_ROWS;B++){animation_matrix[C][B]=[];for(var A=1;A<=ICON_COLUMNS;A++){animation_matrix[C][B][A]="trans"}}delays[C]=100;frame_count=C}function mouse_down_on_icon(A){if(!Event.isLeftClick(A)){return }Event.observe("big_icon","mousemove",mouse_move_on_icon);Event.observe("page_body","mousemove",mouse_move_on_body);Event.observe("big_icon","mouseup",mouse_up_on_icon);Event.stop(A);change_color(A)}function mouse_up_on_icon(A){mover_started=0;Event.stopObserving("big_icon","mousemove",mouse_move_on_icon);Event.stopObserving("page_body","mousemove",mouse_move_on_body);Event.stop(A)}function mouse_move_on_icon(A){change_color(A);Event.stop(A)}function mouse_move_on_body(A){mover_started=0;Event.stopObserving("big_icon","mousemove",mouse_move_on_icon);Event.stopObserving("page_body","mousemove",mouse_move_on_body);Event.stop(A)}function change_color(B){var D=new Position.cumulativeOffset($("big_icon"));var C=parseInt((Event.pointerY(B)-D[1])/20,10)+1;var A=parseInt((Event.pointerX(B)-D[0])/22,10)+1;if((C<1)||(A<1)||(C>ICON_ROWS)||(A>ICON_COLUMNS)){return }if($("pipette").checked){process_pipette_clicked_on_table(C,A)}else{if($("transparency").checked){process_erasor_clicked_on_table(C,A)}else{if($("mover").checked){process_mover_clicked_on_table(C,A)}else{process_pen_clicked_on_table(C,A)}}}}function process_mover_clicked_on_table(E,B){if(!mover_started){mover_started=1;if(moved_image_changed){start_mover_row=E;start_mover_column=B;for(var D=1;D<=ICON_ROWS;D++){for(var A=1;A<=ICON_COLUMNS;A++){favicon_matrix[D][A]=animation_matrix[current_frame][D][A]}}moved_image_changed=0}else{start_mover_row=start_mover_row-last_mover_row+E;start_mover_column=start_mover_column-last_mover_column+B}}else{if((last_mover_row!=E)||(last_mover_column!=B)){for(var D=1;D<=ICON_ROWS;D++){for(var A=1;A<=ICON_COLUMNS;A++){var C=D+start_mover_row-E;var F=A+start_mover_column-B;if((C>0)&&(C<=ICON_ROWS)&&(F>0)&&(F<=ICON_COLUMNS)){colorize_field(D,A,favicon_matrix[C][F])}else{colorize_field(D,A,"trans")}}}}}last_mover_row=E;last_mover_column=B}function process_pen_clicked_on_table(B,A){moved_image_changed=1;colorize_field(B,A,$("color_hex_string").innerHTML)}function process_erasor_clicked_on_table(B,A){moved_image_changed=1;colorize_field(B,A,"trans")}function colorize_field(C,B,A){colorize_field_in_icons(C,B,A);animation_matrix[current_frame][C][B]=A}function colorize_field_in_icons(C,B,A){if(A=="trans"){$("big-r"+C+"c"+B).style.backgroundImage='url("images/cell_background.png")';if((frame_count==1)||(!$("animate_preview").checked)){$("small-r"+C+"c"+B).style.backgroundColor="#FFFFFF"}}else{$("big-r"+C+"c"+B).style.backgroundColor="#"+A;$("big-r"+C+"c"+B).style.backgroundImage="";if((frame_count==1)||(!$("animate_preview").checked)){$("small-r"+C+"c"+B).style.backgroundColor="#"+A}}}function process_pipette_clicked_on_table(C,B){moved_image_changed=1;if($("big-r"+C+"c"+B).style.backgroundImage){$("pipette").checked=0;$("transparency").checked=1}else{$("pipette").checked=0;$("transparency").checked=0;var A=animation_matrix[current_frame][C][B];$("color_hex_string").innerHTML=A;$S("current_color_box").background="#"+A;$S("big_current_color_box").background="#"+A;set_hex_color(A)}update_after_checkbox_change()}function get_pixel_field_name(B,A){return("points-r"+B+"f"+A)}function get_x_coordinate(B){var A=0;if(B.pageX){A=B.pageX}else{if(B.clientX){A=B.clientX+document.body.scrollLeft+document.documentElement.scrollLeft}}return(A)}function get_y_coordinate(A){var B=0;if(A.pageY){B=A.pageY}else{if(A.clientY){B=A.clientY+document.body.scrollTop+document.documentElement.scrollTop}}return(B)}function update_current_color_box(){if($("transparency").checked){$("pipette").checked="";$("mover").checked=""}update_after_checkbox_change()}function transparent_tool_clicked(){if($("transparency").checked){$("transparency").checked=""}else{$("transparency").checked=1}update_current_color_box()}function pipette_checked(){if($("pipette").checked){$("transparency").checked="";$("mover").checked=""}update_after_checkbox_change()}function pipette_tool_clicked(){if($("pipette").checked){$("pipette").checked=""}else{$("pipette").checked=1}pipette_checked()}function mover_tool_clicked(){if($("mover").checked){$("mover").checked=""}else{$("mover").checked=1}mover_checked()}function mover_checked(){if($("mover").checked){$("pipette").checked="";$("transparency").checked=""}update_after_checkbox_change()}function pen_selected(){$("pipette").checked="";$("mover").checked="";$("transparency").checked="";update_after_checkbox_change()}function update_after_checkbox_change(){if($("pipette").checked){$("big_icon").style.cursor='url("'+CURSOR_PATH+'/pipette.cur"), pointer;'}else{if($("mover").checked){$("big_icon").style.cursor='url("'+CURSOR_PATH+'/mover.cur"), pointer;'}else{if($("transparency").checked){$("big_icon").style.cursor='url("'+CURSOR_PATH+'/eraser.cur"), pointer;'}else{$("big_icon").style.cursor='url("'+CURSOR_PATH+'/pen.cur"), pointer;'}}}if($("transparency").checked){$("big_current_color_box").style.backgroundImage='url("images/cell_background.png")'}else{$("big_current_color_box").style.backgroundImage=""}}function next_frame(){if(current_frame<MAX_FRAMES){current_frame++}if(current_frame>frame_count){current_frame=1}write_hidden_fields_to_tables()}function previous_frame(){current_frame--;if(current_frame<1){if($("iterations").value!=1){current_frame=frame_count}else{current_frame=1}}write_hidden_fields_to_tables()}function write_hidden_fields_to_tables(){$("frame_no").innerHTML=current_frame;$("frame_count_display").innerHTML=frame_count;display_animation_controls();for(var C=1;C<=ICON_ROWS;C++){for(var B=1;B<=ICON_COLUMNS;B++){var A=animation_matrix[current_frame][C][B];colorize_field_in_icons(C,B,A)}}}function write_hidden_fields(){$("hidden_fields").innerHTML="";append_hidden_field("hidden_fields","frame_count",frame_count);if(USE_ANIMATION){append_hidden_field("hidden_fields","iter_count",$("iterations").value)}else{append_hidden_field("hidden_fields","iter_count",1)}for(var D=1;D<=frame_count;D++){for(var C=1;C<=ICON_ROWS;C++){var B="";for(var A=1;A<=ICON_COLUMNS;A++){B+=animation_matrix[D][C][A]}append_hidden_field("hidden_fields",get_pixel_field_name(C,D),B)}append_hidden_field("hidden_fields","delays-f"+D,delays[D])}}function append_hidden_field(A,B,C){var D=document.createElement("input");D.setAttribute("type","hidden");D.setAttribute("name",B);D.setAttribute("value",C);$(A).appendChild(D)}function download_icon(){write_hidden_fields();$("download_icon").submit()}function download_cursor(){$("action_flag").value="download_cursor";write_hidden_fields();$("download_icon").submit()}function publish_icon(){$("action_flag").value="publish_request";write_hidden_fields();$("download_icon").submit()}function frame_duration_changed(){delays[current_frame]=$("frame_duration").value;return(true)}function display_animation_controls(){if(frame_count>current_frame){$("animation_next_text").innerHTML="Next";$("animation_next_arrow").style.display="inline";$("loop_next").style.display="none"}else{if(frame_count==current_frame){if(($("iterations").value!=1)&&(frame_count!=1)){$("animation_next_text").innerHTML="First";$("animation_next_arrow").style.display="inline";$("loop_next").style.display="inline"}else{$("animation_next_arrow").style.display="none"}}}if(current_frame>1){$("animation_previous_text").innerHTML="Previous";$("animation_previous_arrow").style.display="inline";$("loop_previous").style.display="none"}else{if(($("iterations").value==1)||(frame_count==1)){$("animation_previous_arrow").style.display="none"}else{$("animation_previous_text").innerHTML="Last";$("animation_previous_arrow").style.display="inline";$("loop_previous").style.display="inline"}}$("frame_duration").value=delays[current_frame];$("frame_count_display").innerHTML=frame_count;$("frame_no").innerHTML=current_frame}function use_animation(){$("animation_frame").style.display="block";$("animation_link").style.display="none";display_animation_controls();return }function copy_previous_frame(){if(current_frame>1){for(var B=1;B<=ICON_ROWS;B++){for(var A=1;A<=ICON_COLUMNS;A++){colorize_field(B,A,animation_matrix[current_frame-1][B][A])}}}}function clear_frame(){for(var B=1;B<=ICON_ROWS;B++){for(var A=1;A<=ICON_COLUMNS;A++){colorize_field(B,A,"trans")}}}function append_new_frame(){frame_count++;initialize_frame(frame_count);delays[frame_count]=delays[current_frame];current_frame=frame_count;clear_frame(current_frame);display_animation_controls()}function get_closest(A){var B=DELAY_LIST[0];for(var C=0;C<DELAY_LIST.length;C++){if(A>=DELAY_LIST[C]){B=DELAY_LIST[C]}else{if(A<DELAY_LIST[C]){break}}}return(B)}function update_small_animation(){if($("animate_preview").checked){if(animated_frame>frame_count){animated_frame=1}for(var C=1;C<=ICON_ROWS;C++){for(var B=1;B<=ICON_COLUMNS;B++){var A=animation_matrix[animated_frame][C][B];if(A=="trans"){$("small-r"+C+"c"+B).style.backgroundColor="#FFFFFF"}else{$("small-r"+C+"c"+B).style.backgroundColor="#"+A}}}animated_frame++;window.setTimeout(update_small_animation,delays[animated_frame-1]*10)}}function initialize_small_animation(){animated_frame=1;update_small_animation()}function animate_preview_checked(){if($("animate_preview").checked){animated_frame=1;update_small_animation()}else{write_hidden_fields_to_tables()}};