<?php load_theme_textdomain( 'sofa_shoppr' ); ?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar Index',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar Single',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar Category',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar Page',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar Search',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar Checkout',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Sidebar Contact',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Home Page',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
?>
<?php

class SofaShoppr {

	function addOptions () {

		if( isset($_POST[ 'sshoppr_reset' ] ) ) { SofaShoppr::initOptions( true ); }

		if( isset($_POST[ 'sshoppr_save' ] ) ) {

			$aOptions = SofaShoppr::initOptions( false );
			// general
			$aOptions[ 'enable_paypal' ] = $_POST[ 'enable_paypal' ];
			$aOptions[ 'enable_authorize' ] = $_POST[ 'enable_authorize' ];
			$aOptions[ 'enable_checkout' ] = $_POST[ 'enable_checkout' ];
			$aOptions[ 'enable_email' ] = $_POST[ 'enable_email' ];
			
			$aOptions[ 'paypal_mode' ] = $_POST[ 'paypal_mode' ];
			$aOptions[ 'authorize_mode' ] = $_POST[ 'authorize_mode' ];
			$aOptions[ 'checkout_mode' ] = $_POST[ 'checkout_mode' ];
			
			$aOptions[ 'ppal' ] = $_POST[ 'ppal' ];
			$aOptions[ 'authorize_user' ] = $_POST[ 'authorize_user' ];
			$aOptions[ 'authorize_secret_key' ] = $_POST[ 'authorize_secret_key' ];
			$aOptions[ 'checkout_vendor' ] = $_POST[ 'checkout_vendor' ];
			$aOptions[ 'checkout_secret' ] = $_POST[ 'checkout_secret' ];
			
			$aOptions[ 'entrycurrency' ] = $_POST[ 'entrycurrency' ];
			$aOptions[ 'taxpercentage' ] = floatval( stripslashes( strip_tags( $_POST[ 'taxpercentage' ] ) ) );
			// checkout page
			$aOptions[ 'chckoutpage' ] = $_POST[ 'chckoutpage' ];
			// orders page
			$aOptions[ 'orderspage' ] = $_POST[ 'orderspage' ];
			// slidespage page
			$aOptions[ 'slidespage' ] = $_POST[ 'slidespage' ];
			// intro page
			$aOptions[ 'useintropage' ] = $_POST[ 'useintropage' ];
			$aOptions[ 'intropage' ] = $_POST[ 'intropage' ];
			// slider
			$aOptions[ 'useslider' ] = $_POST[ 'useslider' ];
			$aOptions[ 'slider_type' ] = $_POST[ 'slider_type' ];
			// awkward
			$aOptions[ 'sstiming' ] = intval( $_POST[ 'sstiming' ] );
			$aOptions[ 'ssmode' ] = $_POST[ 'ssmode' ];
			// piecemaker
			$aOptions[ 'segments' ] = intval( $_POST[ 'segments' ] );
			$aOptions[ 'tween_time' ] = $_POST[ 'tween_time' ];
			$aOptions[ 'tween_delay' ] = $_POST[ 'tween_delay' ];
			$aOptions[ 'tween_type' ] = $_POST[ 'tween_type' ];
			$aOptions[ 'z_distance' ] = $_POST[ 'z_distance' ];
			$aOptions[ 'expand' ] = intval( $_POST[ 'expand' ] );
			$aOptions[ 'inner_color' ] = $_POST[ 'inner_color' ];
			$aOptions[ 'text_background' ] = $_POST[ 'text_background' ];
			$aOptions[ 'text_distance' ] = intval( $_POST[ 'text_distance' ] );
			$aOptions[ 'shadow_darkness' ] = intval( $_POST[ 'shadow_darkness' ] );
			$aOptions[ 'autoplay' ] = intval( $_POST[ 'autoplay' ] );
			// home page layout
			$aOptions[ 'layout_build' ] = $_POST[ 'layout_build' ];
			// category and search page layout
			$aOptions[ 'layout_build_category' ] = $_POST[ 'layout_build_category' ];
			// stock inventory
			$aOptions[ 'use_stock_inventory' ] = $_POST[ 'use_stock_inventory' ];
			$aOptions[ 'stock_notify_on_low' ] = $_POST[ 'stock_notify_on_low' ];
			// globally disable comments
			$aOptions[ 'gdc' ] = $_POST[ 'gdc' ];
			// breadcrumbs
			$aOptions[ 'usebread' ] = $_POST[ 'usebread' ];
			// copyright text
			$aOptions[ 'copytext' ] = $_POST[ 'copytext' ];
			
			
			update_option( 'sshoppr_theme', $aOptions );

		}
		
		add_theme_page("Sofa Shoppr Options", "SofaShoppr Options", 'edit_themes', basename(__FILE__), array('SofaShoppr', 'displayOptions'));
	}
	
	function initOptions( $bReset ) {
		$aOptions = get_option('sshoppr_theme' );
		if( !is_array( $aOptions) || $bReset ) {
			// general
			$aOptions[ 'enable_paypal' ] = 'yes';
			$aOptions[ 'enable_authorize' ] = 'yes';
			$aOptions[ 'enable_checkout' ] = 'yes';
			$aOptions[ 'enable_email' ] = 'yes';
			
			$aOptions[ 'paypal_mode' ] = 'sandbox';
			$aOptions[ 'authorize_mode' ] = 'sandbox';
			$aOptions[ 'checkout_mode' ] = 'sandbox';
			
			$aOptions[ 'ppal' ] = 'yourpaypaladdress@yourdomain.ext';
			$aOptions[ 'authorize_user' ] = 'myAuthorizeUser';
			$aOptions[ 'authorize_secret_key' ] = 'myAuthorizeSecretKey';
			$aOptions[ 'checkout_vendor' ] = '2CO vendor ID';
			$aOptions[ 'checkout_secret' ] = 'Secret Word';
			
			$aOptions[ 'entrycurrency' ] = 'USD';
			$aOptions[ 'taxpercentage' ] = '0';
			// checkout page
			$aOptions[ 'chckoutpage' ] = '0';
			// orders page
			$aOptions[ 'orderspage' ] = '0';
			// slidespage page
			$aOptions[ 'slidespage' ] = '0';
			// intro page
			$aOptions[ 'useintropage' ] = 'yes';
			$aOptions[ 'intropage' ] = '0';
			// slider
			$aOptions[ 'useslider' ] = 'yes';
			$aOptions[ 'slider_type' ] = 'flash';
			// awkward
			$aOptions[ 'sstiming' ] = '5';
			$aOptions[ 'ssmode' ] = 'manual';
			// piecemaker
			$aOptions[ 'segments' ] = 9;
			$aOptions[ 'tween_time' ] = 3;
			$aOptions[ 'tween_delay' ] = 0.1;
			$aOptions[ 'tween_type' ] = 'linear';
			$aOptions[ 'z_distance' ] = 25;
			$aOptions[ 'expand' ] = 9;
			$aOptions[ 'inner_color' ] = '0x000000';
			$aOptions[ 'text_background' ] = '0x666666';
			$aOptions[ 'text_distance' ] = 25;
			$aOptions[ 'shadow_darkness' ] = 25;
			$aOptions[ 'autoplay' ] = 2;
			// home page layout
			$aOptions[ 'layout_build' ] = 'gridandsidebar';
			// category and search page layout
			$aOptions[ 'layout_build_category' ] = 'gridandsidebar';
			// stock inventory
			$aOptions[ 'use_stock_inventory' ] = 'no';
			$aOptions[ 'stock_notify_on_low' ] = 'no';
			// globally disable comments
			$aOptions[ 'gdc' ] = 'yes';
			// breadcrumbs
			$aOptions[ 'usebread' ] = 'yes';
			// copyright text
			$aOptions[ 'copytext' ] = '&copy; Company Name 2010. All rights reseved.';
		}
		return $aOptions;
	}

	function displayOptions () {
		$aOptions = SofaShoppr::initOptions( false );
?>

<script type="text/javascript" src="<?php echo( bloginfo( 'template_directory' ) . '/script/prototype.js' ); ?>"></script>
<script src="<?php echo( bloginfo( 'template_directory' ) . '/script/prototype-effects.js' ); ?>" type="text/javascript"></script>

<script type="text/javascript">  
function ajaxUpd( id, url ) {  
	new Ajax.Updater( id, url, { asynchronous: true } );  
	document.getElementById( "installer" ).style.display = "none";
	document.getElementById( "responder" ).style.border = "none";
} 
function hideButt() {
	document.getElementById( "updateme" ).style.color = "green";
	document.getElementById( "responder" ).style.border = "none";
	document.getElementById( "updateme" ).innerHTML = "Required dataBase table has been properly installed!";
	document.getElementById( "installer" ).style.display = "none";
}
</script>

<style type="text/css"> 
.mymenu {
	margin-top: 50px;
	overflow: hidden;
	float: left;
	display: inline;
}
.mymenu p { font-family: Tahoma, Geneva, sans-serif; border-bottom: 1px dotted #CCC; font-weight: normal; padding: 10px; background-color: #F1F1F1; width: 200px; margin: 0; }
.mymenu p a { text-decoration: none; }
.mytable {
	width: 600px;
	padding: 0;
	margin: 50px 0 20px 0;
	font: 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
	border: 1px dotted #CCC;
	float: left;
	display: inline;
}
tbody { width: 600px; background-color: #FFF; overflow: hidden; }
td {
	border-bottom: 1px dotted #CCC;
	background-color: #fff;
	padding: 10px;
	color: #4f6b72;
	width: 578px;
}
td.right {
	text-align: right;
	border: none;
}
input, textarea, select.mlist {
	border: 1px solid #CFCFCF;
}
#wpcontent select.mlist {
	height: 200px;
	width: 200px;
	overflow: scroll;
}
#wpcontent .row {
	background-color: #F1F1F1; overflow: hidden; height: 30px; width: 700px; padding: 5px 10px 10px 10px; margin-bottom: 10px;
}
#wpcontent .cbholder {
	width: 300px; float: left; display: inline; padding: 11px 0 0 0;
}
#wpcontent .snholder {
	width: 300px; float: left; display: inline; padding: 5px 0;
}
#wpcontent .clear { height: 10px; width: 600px; clear: both; }
textarea {
	width: 99%;
}
p {
	font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
	color: #666666;
}
span.exp {
	font-weight: normal;
	font-style: italic;
}
.centered { 
	font-size: 11px; 
	font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
	color: #666666;
	vertical-align: top; 
}
</style>
<script src="<?php echo( bloginfo( 'template_directory' ) . '/script/jcookie.js' ); ?>" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
jQuery( document ).ready( function() {
	jQuery( '[id^=toggle-item]' ).hide();
	var curr_cookie = jQuery.cookie( "openpresspanel" );
	if( curr_cookie != null ) jQuery( curr_cookie ).show();
	else jQuery( '[id^=toggle-item-toggler1]' ).show();
	jQuery( '[class^=toggler]' ).click( function() {
		jQuery( '[id^=toggle-item-toggler]' ).hide();
		var $this = jQuery( this );
		var x = $this.attr( "className" );
		var who = "#toggle-item-" + x;
		jQuery( who ).fadeIn( 200 );
		jQuery.cookie( "openpresspanel", who );
		return false;
	} );
} );
</script>
<div class="wrap">
	<h2>Sofa Shoppr Theme Options</h2>
    <form action="#" method="post" enctype="multipart/form-data" name="massive_form" id="massive_form">
    
    <div class="mymenu">
    	<p><a href="#" class="toggler1">&raquo; Install Required dataBase Tables</a></p>
    	<p><a href="#" class="toggler2">&raquo; Payment Gateways Settings</a></p>
        <p><a href="#" class="toggler3">&raquo; Payment Settings</a></p>
        <p><a href="#" class="toggler4">&raquo; !Required Custom Templates!</a></p>
        <p><a href="#" class="toggler5">&raquo; Home Page Images Slider</a></p>
        <p><a href="#" class="toggler6">&raquo; Template Pages Content Layout</a></p>
        <p><a href="#" class="toggler7">&raquo; Stock Inventory</a></p>
        <p><a href="#" class="toggler8">&raquo; Other Options/Settings</a></p>
    </div>
    
    <table class="mytable" id="toggle-item-toggler1">
      <tr>
        <td>
            <h2>Install Required dataBase Tables</h2>
            <p>Additional database table needs to be installed for this theme! Click "Install Additional Table" button and let the system do the hard job for you. This additional table will enable Admin to have a clean overview of all purchases/transaction details.</p>
        </td>
      </tr>
      <tr>
        <td id="responder">
            <div id="updateme">Awaiting response...</div>
        </td>
      </tr>
      <tr id="installer" name="installer">
        <td class="right">
        <?php
		global $wpdb;
		$purchase_history_table_name = $wpdb->prefix . 'purchases_history';
		
		if( $wpdb->get_var( "show tables like '$purchase_history_table_name'" ) != $purchase_history_table_name ) {
		?>
        <input type="button" value="Install Additional Table" style="background-color: red; color: #FFF;" onClick="ajaxUpd( 'updateme', '<?php echo( get_bloginfo( 'template_directory' ) . '/sql_create.php' ); ?>' )">
        <?php
		} else echo '<script type="text/javascript">hideButt();</script>';
		?>
        </td>
      </tr>
    </table>
                
    <table class="mytable" id="toggle-item-toggler2">
      <tr>
        <td>
            <h2>Payment Gateways Settings</h2>
            <p>Test your webshop before you decide to make it "alive"! Switch between test ('sandbox', still requires valid testing accounts) and real mode.</p>
            <p style="color: red;">You will have to open account (register) for each of available Payment gateways!</p>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>Enable users to pay by PayPal?</strong></p>
        <p>If YES, PayPal button will appear at Checkout page.</p>
        <p>Enable PayPal Payment Gateway? [ <span class="exp">select yes or no</span> ]</p>
            <select id="enable_paypal" name="enable_paypal" size="1">
                <?php
                if( $aOptions[ 'enable_paypal' ] == 'yes' ) {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                } else if( $aOptions[ 'enable_paypal' ] == 'no' ) {
                ?>
                <option value="yes"> - YES - </option>
                <option value="no" selected="selected"> - NO - </option>
                <?php
                } else {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                }
                ?>
            </select>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>PayPal Mode</strong></p>
        <p>Please note that Sandbox mode still requires PayPal account. You can get one <a href="https://developer.paypal.com/" target="_blank">HERE</a>. Otherwise everything will run for real!</p>
        <p>Select PayPal Mode [ <span class="exp">Sandbox or PayPal</span> ]</p>
            <select id="paypal_mode" name="paypal_mode" size="1">
                <?php
                if( $aOptions[ 'paypal_mode' ] == 'sandbox' ) {
                ?>
                <option value="sandbox" selected="selected"> - Sandbox - </option>
                <option value="paypal"> - PayPal - </option>
                <?php
                } else if( $aOptions[ 'paypal_mode' ] == 'paypal' ) {
                ?>
                <option value="sandbox"> - Sandbox - </option>
                <option value="paypal" selected="selected"> - PayPal - </option>
                <?php
                } else {
                ?>
                <option value="sandbox" selected="selected"> - Sandbox - </option>
                <option value="paypal"> - PayPal - </option>
                <?php
                }
                ?>
            </select>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>PayPal account e-mail address</strong></p>
        <p>It doesn't make the difference whether you run this theme in Sandbox or PayPal mode, both require valid e-mail address!</p>
        <p>PayPal e-mail address [ <span class="exp">Must be valid Sandbox or Business PayPal account!</span> ]</p>
        <input name="ppal" id="ppal" value="<?php echo $aOptions[ 'ppal' ]; ?>" size="50" ></input>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>Enable users to pay by Authorize.net?</strong></p>
        <p>If YES, Authorize.net button will appear at Checkout page.</p>
        <p>Enable Authorize.net payment gateway? [ <span class="exp">select yes or no</span> ]</p>
            <select id="enable_authorize" name="enable_authorize" size="1">
                <?php
                if( $aOptions[ 'enable_authorize' ] == 'yes' ) {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                } else if( $aOptions[ 'enable_authorize' ] == 'no' ) {
                ?>
                <option value="yes"> - YES - </option>
                <option value="no" selected="selected"> - NO - </option>
                <?php
                } else {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                }
                ?>
            </select>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>Authorize.net Mode</strong></p>
        <p>Please note that Sandbox mode still requires Authorize.net test account. You can get one <a href="https://developer.authorize.net/testaccount/" target="_blank">HERE</a>. Otherwise everything will run for real!</p>
        <p>Select Authorize.net mode [ <span class="exp">Sandbox or Authorize.net</span> ]</p>
            <select id="authorize_mode" name="authorize_mode" size="1">
                <?php
                if( $aOptions[ 'authorize_mode' ] == 'sandbox' ) {
                ?>
                <option value="sandbox" selected="selected"> - Sandbox - </option>
                <option value="authorize"> - Authorize.net - </option>
                <?php
                } else if( $aOptions[ 'authorize_mode' ] == 'authorize' ) {
                ?>
                <option value="sandbox"> - Sandbox - </option>
                <option value="authorize" selected="selected"> - Authorize.net - </option>
                <?php
                } else {
                ?>
                <option value="sandbox" selected="selected"> - Sandbox - </option>
                <option value="authorize"> - Authorize.net - </option>
                <?php
                }
                ?>
            </select>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>Authorize.net account settings</strong></p>
        <p>Both are provided upon approved account in disregard of account type!</p>
        <p>Authorize.net User ID [ <span class="exp">Must be valid!</span> ]</p>
        <input name="authorize_user" id="authorize_user" value="<?php echo $aOptions[ 'authorize_user' ]; ?>" size="50" ></input>
        </td>
      </tr>
      <tr>
        <td>
        <p>Authorize.net Secret Key [ <span class="exp">Must be valid!</span> ]</p>
        <input name="authorize_secret_key" id="authorize_secret_key" value="<?php echo $aOptions[ 'authorize_secret_key' ]; ?>" size="50" ></input>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>Enable users to pay by 2CheckOut?</strong></p>
        <p>If YES, 2CheckOut button will appear at Checkout page.</p>
        <p>Enable 2CheckOut payment gateway? [ <span class="exp">select yes or no</span> ]</p>
            <select id="enable_checkout" name="enable_checkout" size="1">
                <?php
                if( $aOptions[ 'enable_checkout' ] == 'yes' ) {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                } else if( $aOptions[ 'enable_checkout' ] == 'no' ) {
                ?>
                <option value="yes"> - YES - </option>
                <option value="no" selected="selected"> - NO - </option>
                <?php
                } else {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                }
                ?>
            </select>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>2CheckOut Mode</strong></p>
        <p>Note that Sandbox mode still requires 2CheckOut Vendor account. You can get one <a href="https://www.2checkout.com/2co/signup" target="_blank">HERE</a>. There's a certain procedure that needs to be followed in order to open a test account. Please read below how to obtain approved test account (mail sent from 2CO support staff)!</p>
        <p style="font-style: italic;">
Please note, we do offer free developer accounts for software developers. To open a free account you would need to select Mailed Check as the payment method for the $49.00 application fee. You will still need to fill out the Application form, however you would only need to complete the Billing Information and Primary Contact information sections with valid information. For the balance of the information you may fill the fields with "n/a". After you have opened your account please respond to <del>this email</del> with your new account number so that we may mark the account as a developer only account.
        </p>
        <p>2CheckOut mode [ <span class="exp">Sandbox or 2Checout</span> ]</p>
            <select id="checkout_mode" name="checkout_mode" size="1">
                <?php
                if( $aOptions[ 'checkout_mode' ] == 'sandbox' ) {
                ?>
                <option value="sandbox" selected="selected"> - Sandbox - </option>
                <option value="checkout"> - 2Checkout - </option>
                <?php
                } else if( $aOptions[ 'checkout_mode' ] == 'checkout' ) {
                ?>
                <option value="sandbox"> - Sandbox - </option>
                <option value="checkout" selected="selected"> - 2Checkout - </option>
                <?php
                } else {
                ?>
                <option value="sandbox" selected="selected"> - Sandbox - </option>
                <option value="checkout"> - 2Checkout - </option>
                <?php
                }
                ?>
            </select>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>2CheckOut account settings</strong></p>
        <p>"2CheckOut Vendor ID" is provided upon account approval while "2CheckOut Secret Word" can be set within account settings!</p>
        <p>2CheckOut Vendor ID [ <span class="exp">Must have valid Sandbox (test) / 2CO account!</span> ]</p>
        <input name="checkout_vendor" id="checkout_vendor" value="<?php echo $aOptions[ 'checkout_vendor' ]; ?>" size="50" ></input>
        </td>
      </tr>
      <tr>
        <td>
        <p>2CheckOut Secret Word [ <span class="exp">string</span> ]</p>
        <input name="checkout_secret" id="checkout_secret" value="<?php echo $aOptions[ 'checkout_secret' ]; ?>" size="50" ></input>
        </td>
      </tr>
      <tr>
        <td>
        <p><strong>Enable users to place order by e-mail?</strong></p>
        <p>If YES, E-mail Order button will appear at Checkout page.</p>
        <p>On a side note, be aware of the fact that Stock Inventory will not be changed after placing an e-mail order due to the fact the payment hasn't been actually made.</p>
        <p>Enable e-mail orders? [ <span class="exp">select yes or no</span> ]</p>
            <select id="enable_email" name="enable_email" size="1">
                <?php
                if( $aOptions[ 'enable_email' ] == 'yes' ) {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                } else if( $aOptions[ 'enable_email' ] == 'no' ) {
                ?>
                <option value="yes"> - YES - </option>
                <option value="no" selected="selected"> - NO - </option>
                <?php
                } else {
                ?>
                <option value="yes" selected="selected"> - YES - </option>
                <option value="no"> - NO - </option>
                <?php
                }
                ?>
            </select>
        </td>
      </tr>
      <tr>
        <td class="right"><input type="submit" name="sshoppr_save" value="Save Options" /></td>
      </tr>
    </table>
    
<table class="mytable" id="toggle-item-toggler3">
  <tr>
    <td>
        <h2>Payment Settings</h2>
        <p>Currecy, Tax and Shipping price</p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Default currency used by your webshop</strong></p>
    <p>All the payments will be made in currency of your choice and as such will appear on reports.</p>
    <p>Which Currency? [ <span class="exp">Select</span> ]</p>
				<select name="entrycurrency" id="entrycurrency">
                	<option value="EUR" <?php if ( $aOptions[ 'entrycurrency' ] == "EUR" ) { echo 'selected="selected"'; } ?>>Euro</option>
                    <option value="AUD" <?php if ( $aOptions[ 'entrycurrency' ] == "AUD" ) { echo 'selected="selected"'; } ?>>Australian Dolars</option>
					<option value="USD" <?php if ( $aOptions[ 'entrycurrency' ] == "USD" ) { echo 'selected="selected"'; } ?>>U.S. Dolars</option>
					<option value="CAD" <?php if ( $aOptions[ 'entrycurrency' ] == "CAD" ) { echo 'selected="selected"'; } ?>>Canadian Dolars</option>
					<option value="GBP" <?php if ( $aOptions[ 'entrycurrency' ] == "GBP" ) { echo 'selected="selected"'; } ?>>British Pounds</option>
				</select>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Tax value, percentge</strong></p>
    <p>This value shall be applied on the price Total. If the Tax is already calculated in each product price, set this value to 0 (zero) because no need to declare it twice. No need to add '%' at the end!</p>
    <p>Tax? [ <span class="exp">Number (percentage), integer or floating point (must use dot if floating!!!)</span> ]</p>
	<input name="taxpercentage" id="taxpercentage" value="<?php echo $aOptions[ 'taxpercentage' ]; ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sshoppr_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable" id="toggle-item-toggler4">
  <tr>
    <td>
        <h2>!Required Custom Templates!</h2>
        <p>There are 2 Custom Templates that must be present in Pages section (Admin panel, select Pages &gt; Pages). Be sure you created these two according to theme manuals!</p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Checkout page (Custom Template)</strong></p>
    <p>In case you didn't create it so far, from Admin menu select Pages > Add New, write some content if required, then select 'Checkout Point Page' from Template drop-down, Attributes panel.</p>
    <p>Select your Checkout Page to make it active [ <span class="exp">select</span> ]</p>
    <?php
	$already_selected = $aOptions[ 'chckoutpage' ];
	
	$args = array(
    	'child_of' => 0,
    	'sort_order' => 'ASC',
    	'sort_column' => 'menu_order',
    	'hierarchical' => 0,
    	'exclude' => '',
    	'include' => '',
    	'meta_key' => '',
    	'meta_value' => '',
    	'authors' => '',
    	'parent' => 0,
    	'exclude_tree' => '',
    	'number' => '',
    	'offset' => 0 );
	
	$pages = get_pages( $args ); 
	echo '<select id="chckoutpage" name="chckoutpage" size="1">';
	foreach( $pages as $p ) {
		if( (int)$already_selected == (int)$p->ID ) $add_str = ' selected="selected" ';
		else $add_str = ' ';
		$option = '<option' . $add_str . 'value="' . $p->ID . '"> - ';
		$option .= $p->post_title;
		$option .= ' - </option>';
		echo $option;
	}
	echo '</select>';
	?>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Orders page (Custom Template)</strong></p>
    <p>In case you didn't create it so far, from Admin menu select Pages > Add New, write some content if required, then select 'Orders Handling' from Template drop-down, Attributes panel. This page will enable site Admin an overview of existing or new orders, the ability to tag each order with 'Shipped', 'Returned' or 'Pendig', contact buyers, etc.</p>
    <p>Orders Handling Page [ <span class="exp">select</span> ]</p>
    <?php
	$already_selected = $aOptions[ 'orderspage' ];
	
	$args = array(
    	'child_of' => 0,
    	'sort_order' => 'ASC',
    	'sort_column' => 'menu_order',
    	'hierarchical' => 0,
    	'exclude' => '',
    	'include' => '',
    	'meta_key' => '',
    	'meta_value' => '',
    	'authors' => '',
    	'parent' => 0,
    	'exclude_tree' => '',
    	'number' => '',
    	'offset' => 0 );
	
	$pages = get_pages( $args ); 
	echo '<select id="orderspage" name="orderspage" size="1">';
	foreach( $pages as $p ) {
		if( (int)$already_selected == (int)$p->ID ) $add_str = ' selected="selected" ';
		else $add_str = ' ';
		$option = '<option' . $add_str . 'value="' . $p->ID . '"> - ';
		$option .= $p->post_title;
		$option .= ' - </option>';
		echo $option;
	}
	echo '</select>';
	?>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sshoppr_save" value="Save Options" /></td>
  </tr>
</table>
    
<table class="mytable" id="toggle-item-toggler5">
  <tr>
    <td>
        <h2>Home Page Images Slider - Flash or jQuery</h2>
        <p>
        It will be visible at Home Page, header section. However, you will have to create an Image Repository page first! This special page will hold/keep all of your image slides. If already not, from Admin menu select Pages > Add New and publish it. Feel free to upload image slides afterward - according to theme manuals recommendation. No need to add this page to main or footer menu (Appearance > Menus) because Images Repository page should be hidden from site visitors. Once created, just select from drop-down list.
        </p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Enable Images Slider on Home Page or not?</strong></p>
    <p>Images Slider is actually optional, you can disable it if you like.</p>
    <p>Use Images Slider? [ select <span class="exp">yes or no</span> ]</p>
        <select id="useslider" name="useslider" size="1">
        	<?php
			if( $aOptions[ 'useslider' ] == 'yes' ) {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
            <?php
			} else if( $aOptions[ 'useslider' ] == 'no' ) {
			?>
        	<option value="yes"> - YES - </option>
            <option value="no" selected="selected"> - NO - </option>
            <?php
			} else {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Select and make active Images Repository Page</strong></p>
    <p>Be sure you created this page according to theme manuals!</p>
    <p>Images Repository Page [ <span class="exp">select</span> ]</p>
    <?php
	$already_selected = $aOptions[ 'slidespage' ];
	
	$args = array(
    	'child_of' => 0,
    	'sort_order' => 'ASC',
    	'sort_column' => 'menu_order',
    	'hierarchical' => 0,
    	'exclude' => '',
    	'include' => '',
    	'meta_key' => '',
    	'meta_value' => '',
    	'authors' => '',
    	'parent' => 0,
    	'exclude_tree' => '',
    	'number' => '',
    	'offset' => 0 );
	
	$pages = get_pages( $args ); 
	echo '<select id="slidespage" name="slidespage" size="1">';
	foreach( $pages as $p ) {
		if( (int)$already_selected == (int)$p->ID ) $add_str = ' selected="selected" ';
		else $add_str = ' ';
		$option = '<option' . $add_str . 'value="' . $p->ID . '"> - ';
		$option .= $p->post_title;
		$option .= ' - </option>';
		echo $option;
	}
	echo '</select>';
	?>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Slider type to use; Piecemaker (Flash) or Awkward (jQuery)</strong></p>
    <p>Select preferred type first, then change selected slider options.</p>
    <p>Use Piecemaker or use Awkward [ select <span class="exp">type</span> ]</p>
        <select id="slider_type" name="slider_type" size="1">
        	<?php
			if( $aOptions[ 'slider_type' ] == 'flash' ) {
			?>
        	<option value="flash" selected="selected"> - Piecemaker (Flash) - </option>
            <option value="jq"> - Awkward (jQuery) - </option>
            <?php
			} else if( $aOptions[ 'slider_type' ] == 'jq' ) {
			?>
        	<option value="flash"> - Piecemaker (Flash) - </option>
            <option value="jq" selected="selected"> - Awkward (jQuery) - </option>
            <?php
			} else {
			?>
        	<option value="flash" selected="selected"> - Piecemaker (Flash) - </option>
            <option value="jq"> - Awkward (jQuery) - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <h3>&raquo; Awkward jQuery slider settings</h3>
    <p>You can find more info on this great jQuery slider <a href="http://www.awkwardgroup.com/sandbox/awkward-showcase-a-jquery-plugin/" target="_blank">HERE!</a></p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Images Slider mode</strong></p>
    <p>Slider images can be auto-rotated or require user interaction.</p>
    <p>Slider mode [ select <span class="exp">auto or manual</span> ]</p>
        <select id="ssmode" name="ssmode" size="1">
            <?php
            if( $aOptions[ 'ssmode' ] == 'auto' ) {
            ?>
            <option value="auto" selected="selected"> - AUTO-ROTATE - </option>
            <option value="manual"> - MANUAL - </option>
            <?php
            } else if( $aOptions[ 'ssmode' ] == 'manual' ) {
            ?>
            <option value="auto"> - AUTO-ROTATE - </option>
            <option value="manual" selected="selected"> - MANUAL - </option>
            <?php
            } else {
            ?>
            <option value="auto" selected="selected"> - AUTO-ROTATE - </option>
            <option value="manual"> - MANUAL - </option>
            <?php
            }
            ?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Slider Timing</strong></p>
    <p>If your choice above was AUTO-ROTATE, you can set the timing here. Enter the number of seconds to pause before next slide.</p>
    <p>Seconds to pause [ <span class="exp">number, integer (for example: 5)</span> ]</p>
    <input name="sstiming" id="sstiming" value="<?php echo $aOptions[ 'sstiming' ]; ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <h3>&raquo; Piecemaker Flash slider settings</h3>
    <p>You can find more info on this great Flash made image slider <a href="http://www.modularweb.net/piecemaker/" target="_blank">HERE!</a></p>
    <p>All of original Piecemaker options are available below and no need to configure it manually via XML file.</p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Segments</strong>, number of segments in which the image will be sliced [ <span class="exp">number, integer</span> ]</p>
    <input name="segments" id="segments" value="<?php echo stripslashes( $aOptions[ 'segments' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Tween Time</strong>, number of seconds for each element to be turned [ <span class="exp">number, integer</span> ]</p>
    <input name="tween_time" id="tween_time" value="<?php echo stripslashes( $aOptions[ 'tween_time' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Tween Delay</strong>, number of seconds from one element starting to turn to the next element starting [ <span class="exp">number, float</span> ]</p>
    <input name="tween_delay" id="tween_delay" value="<?php echo stripslashes( $aOptions[ 'tween_delay' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Tween Type</strong>, type of animation transition [ <span class="exp">select</span> ]</p>
    <?php
	$tween_types = array( 'linear','easeInSine','easeOutSine', 'easeInOutSine', 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', 'easeOutInCubic', 'easeInQuint', 'easeOutQuint', 'easeInOutQuint', 'easeOutInQuint', 'easeInCirc', 'easeOutCirc', 'easeInOutCirc', 'easeOutInCirc', 'easeInBack', 'easeOutBack', 'easeInOutBack', 'easeOutInBack', 'easeInQuad', 'easeOutQuad', 'easeInOutQuad', 'easeOutInQuad', 'easeInQuart', 'easeOutQuart', 'easeInOutQuart', 'easeOutInQuart', 'easeInExpo', 'easeOutExpo', 'easeInOutExpo', 'easeOutInExpo', 'easeInElastic', 'easeOutElastic', 'easeInOutElastic', 'easeOutInElastic', 'easeInBounce', 'easeOutBounce', 'easeInOutBounce', 'easeOutInBounce' );
	
	$count_tweens = 0;
	$tweens_length = count( $tween_types );
	$saved_tween_type = $aOptions[ 'tween_type' ];
	echo '<select id="tween_type" name="tween_type" size="1">';
	while( $count_tweens < $tweens_length ) {
		if( $saved_tween_type == $tween_types[ $count_tweens ] ) $add_str_tween = ' selected="selected" ';
		else $add_str_tween = ' ';
		$option = '<option' . $add_str_tween . 'value="' . $tween_types[ $count_tweens ] . '"> - ';
		$option .= $tween_types[ $count_tweens ];
		$option .= ' - </option>';
		echo $option;
		$count_tweens ++;
	}
	echo '</select>';
	?>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Z-distance</strong>, to which extend are the cubes moved on z axis when being tweened. Negative values bring the cube closer to the camera, positive values take it further away. A good range is roughly between -200 and 700 [ <span class="exp">number, integer: positive or negative</span> ]</p>
    <input name="z_distance" id="z_distance" value="<?php echo stripslashes( $aOptions[ 'z_distance' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Expand</strong>, to which etxend are the cubes moved away from each other when tweening [ <span class="exp">number, integer</span> ]</p>
    <input name="expand" id="expand" value="<?php echo stripslashes( $aOptions[ 'expand' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Inner Color</strong>, color of the sides of the elements in hex values [ <span class="exp">color, hex value (for example 0x000000)</span> ]</p>
    <input name="inner_color" id="inner_color" value="<?php echo stripslashes( $aOptions[ 'inner_color' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Text Background Color</strong>, color of the description text background in hex values [ <span class="exp">color, hex value (for example 0xCC0000)</span> ]</p>
    <input name="text_background" id="text_background" value="<?php echo stripslashes( $aOptions[ 'text_background' ] ); ?>" size="50" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Text Distance</strong>, distance of the info text to the borders of its background [ <span class="exp">number, integer</span> ]</p>
    <input name="text_distance" id="text_distance" value="<?php echo stripslashes( $aOptions[ 'text_distance' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Shadow Darkness</strong>, to which extend are the sides shadowed, when the elements are tweening and the sided move towards the background. 100 is black, 0 is no darkening [ <span class="exp">number, integer</span> ]</p>
    <input name="shadow_darkness" id="shadow_darkness" value="<?php echo stripslashes( $aOptions[ 'shadow_darkness' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Auto Play</strong>, Number of seconds to the next image when autoplay is on. Set 0, if you don't want autoplay [ <span class="exp">number, integer</span> ]</p>
    <input name="autoplay" id="autoplay" value="<?php echo stripslashes( $aOptions[ 'autoplay' ] ); ?>" size="5" ></input>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sshoppr_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable" id="toggle-item-toggler6">
  <tr>
    <td>
        <h2>Templates Content Layout</h2>
        <p>You can have products listed in your webshop in several different layout presets...</p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Select Home Page Layout</strong></p>
    <p>Home page layout can cosist of Widgets only (auto-arranged in grid-like form), full page width grid of posts, or 2/3 grid plus sidebar. First two options do not allow you to use sidebar. On a side note, the last two options will allow you use Widgets in conjunction with the rest of the content. If you do so, Widgets will always be listed on top of everything else.</p>
    <p>Select Layout type [ <span class="exp">options</span> ]</p>
        <select id="layout_build" name="layout_build" size="1">
        	<?php
			if( $aOptions[ 'layout_build' ] == 'widgets' ) {
			?>
        	<option value="widgets" selected="selected"> - WIDGETS - </option>
            <option value="grid"> - FULL WIDTH GRID, NO SIDEBAR - </option>
            <option value="gridandsidebar"> - 2/3 GRID AND SIDEBAR - </option>
            <?php
			} else if( $aOptions[ 'layout_build' ] == 'grid' ) {
			?>
        	<option value="widgets"> - WIDGETS - </option>
            <option value="grid" selected="selected"> - FULL WIDTH GRID, NO SIDEBAR - </option>
            <option value="gridandsidebar"> - 2/3 GRID AND SIDEBAR - </option>
            <?php
			} else if( $aOptions[ 'layout_build' ] == 'gridandsidebar' ) {
			?>
        	<option value="widgets"> - WIDGETS - </option>
            <option value="grid"> - FULL WIDTH GRID, NO SIDEBAR - </option>
            <option value="gridandsidebar" selected="selected"> - 2/3 GRID AND SIDEBAR - </option>
			<?php
			} else {
			?>
        	<option value="widgets"> - WIDGETS - </option>
            <option value="grid"> - FULL WIDTH GRID, NO SIDEBAR - </option>
            <option value="gridandsidebar" selected="selected"> - 2/3 GRID AND SIDEBAR - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Inner pages Layout</strong></p>
    <p>Category, Search and Tag page layout can be a full page width grid of posts or 2/3 grid plus sidebar. First option do not allow you to display sidebar(s). None of these three templates can display Widgets in main content area, Widgets are rather displayed in sidebar but only if you don't use a full page width grid.</p>
    <p>Select inner pages Layout[ <span class="exp">options</span> ]</p>
        <select id="layout_build_category" name="layout_build_category" size="1">
            <?php
			if( $aOptions[ 'layout_build_category' ] == 'grid' ) {
			?>
            <option value="grid" selected="selected"> - FULL WIDTH GRID, NO SIDEBAR - </option>
            <option value="gridandsidebar"> - 2/3 GRID AND SIDEBAR - </option>
            <?php
			} else if( $aOptions[ 'layout_build_category' ] == 'gridandsidebar' ) {
			?>
            <option value="grid"> - FULL WIDTH GRID, NO SIDEBAR - </option>
            <option value="gridandsidebar" selected="selected"> - 2/3 GRID AND SIDEBAR - </option>
			<?php
			} else {
			?>
            <option value="grid"> - FULL WIDTH GRID, NO SIDEBAR - </option>
            <option value="gridandsidebar" selected="selected"> - 2/3 GRID AND SIDEBAR - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sshoppr_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable" id="toggle-item-toggler7">
  <tr>
    <td>
        <h2>Stock Inventory</h2>
        <p>You can easily enable or disable Stock Inventory management from here. If you deal with products that are always available in stock, there's no need for maintenance and no need to use this feature. However...</p>
        <p style="color: red;">
        Each and every product in your webshop MUST include/provide "stock" Custom Field name-value pair in disregard of this setting! If your choice here is "- NO -", Custom Fields "stock" will allways keep its Value unchanged. The value of Custom Field "stock" must be larger than 0 (zero). PLEASE READ THEME MANUALS, SECTION "6. Everything about adding a product to webshop" FOR MORE DETAILS!
        </p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Enable or disable Stock Inventory feature</strong></p>
    <p>Be sure all of your webshop products include "stock" Custom Field value(s)!</p>
    <p>Use Stock Inventory or not? [ <span class="exp">Yes or No</span> ]</p>
        <select id="use_stock_inventory" name="use_stock_inventory" size="1">
        	<?php
			if( $aOptions[ 'use_stock_inventory' ] == 'yes' ) {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
            <?php
			} else if( $aOptions[ 'use_stock_inventory' ] == 'no' ) {
			?>
        	<option value="yes"> - YES - </option>
            <option value="no" selected="selected"> - NO - </option>
            <?php
			} else {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Notify Admin if stock low</strong></p>
    <p>Admin can receive "Inventory Low" notifications by email in case certain product gets out of stock. An email address you've provided by WordPress installation will be used to receive notifications.</p>
    <p>Send "Inventory Low" notifications? [ <span class="exp">Yes or No</span> ]</p>
        <select id="stock_notify_on_low" name="stock_notify_on_low" size="1">
        	<?php
			if( $aOptions[ 'stock_notify_on_low' ] == 'yes' ) {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
            <?php
			} else if( $aOptions[ 'stock_notify_on_low' ] == 'no' ) {
			?>
        	<option value="yes"> - YES - </option>
            <option value="no" selected="selected"> - NO - </option>
            <?php
			} else {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td class="right"><input type="submit" name="sshoppr_save" value="Save Options" /></td>
  </tr>
</table>

<table class="mytable" id="toggle-item-toggler8">
  <tr>
    <td>
        <h2>Other Options/Settings</h2>
        <p>Decide whether you need it or not, it's optional...</p>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Introduction Page</strong></p>
    <p>Content of this page will be displayed on Home page only, above all other content. In order to be able to use this feature, Intro page must be created first (Pages &gt; Add New). Once created, you'll be able to select it from the list below.</p>
    <p>Use Intro Page or not? [ <span class="exp">Yes or No</span> ]</p>
        <select id="useintropage" name="useintropage" size="1">
        	<?php
			if( $aOptions[ 'useintropage' ] == 'yes' ) {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
            <?php
			} else if( $aOptions[ 'useintropage' ] == 'no' ) {
			?>
        	<option value="yes"> - YES - </option>
            <option value="no" selected="selected"> - NO - </option>
            <?php
			} else {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p>Select Intro Page [ <span class="exp">select</span> ]</p>
    <?php
	$already_selected = $aOptions[ 'intropage' ];
	
	$args = array(
    	'child_of' => 0,
    	'sort_order' => 'ASC',
    	'sort_column' => 'menu_order',
    	'hierarchical' => 0,
    	'exclude' => '',
    	'include' => '',
    	'meta_key' => '',
    	'meta_value' => '',
    	'authors' => '',
    	'parent' => 0,
    	'exclude_tree' => '',
    	'number' => '',
    	'offset' => 0 );
	
	$pages = get_pages( $args ); 
	echo '<select id="intropage" name="intropage" size="1">';
	foreach( $pages as $p ) {
		if( (int)$already_selected == (int)$p->ID ) $add_str = ' selected="selected" ';
		else $add_str = ' ';
		$option = '<option' . $add_str . 'value="' . $p->ID . '"> - ';
		$option .= $p->post_title;
		$option .= ' - </option>';
		echo $option;
	}
	echo '</select>';
	?>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Breadcrumbs</strong></p>
    <p>Do you want to enable breadcrumbs navigation? It might be very helpful with complex sitemaps.</p>
    <p>Use Breadcrumbs or not? [ <span class="exp">Yes or No</span> ]</p>
        <select id="usebread" name="usebread" size="1">
        	<?php
			if( $aOptions[ 'usebread' ] == 'yes' ) {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
            <?php
			} else if( $aOptions[ 'usebread' ] == 'no' ) {
			?>
        	<option value="yes"> - YES - </option>
            <option value="no" selected="selected"> - NO - </option>
            <?php
			} else {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Disable product reviews (comments) globally</strong></p>
    <p>If you don't like to see user reviews aka WordPress comments, you can disable it globally here.</p>
    <p>Disable reviews? [ <span class="exp">Yes or No</span> ]</p>
        <select id="gdc" name="gdc" size="1">
        	<?php
			if( $aOptions[ 'gdc' ] == 'yes' ) {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
            <?php
			} else if( $aOptions[ 'gdc' ] == 'no' ) {
			?>
        	<option value="yes"> - YES - </option>
            <option value="no" selected="selected"> - NO - </option>
            <?php
			} else {
			?>
        	<option value="yes" selected="selected"> - YES - </option>
            <option value="no"> - NO - </option>
			<?php
			}
			?>
        </select>
    </td>
  </tr>
  <tr>
    <td>
    <p><strong>Website Copyright info in footer</strong></p>
    <p>Here you can easily add copright info. HTML formatted text is allowed to be entered too.</p>
    <p>&copy; Copyright info [ <span class="exp">text, HTML is OK</span> ]</p>
    <textarea name="copytext" cols="60" rows="5" id="copytext"><?php echo stripslashes( $aOptions[ 'copytext' ] ); ?></textarea>
    </td>
  </tr>
  
  <tr>
    <td class="right"><input type="submit" name="sshoppr_save" value="Save Options" /></td>
  </tr>
</table>

    </form>
</div>

<?php
	}
}
// Register class
add_action( 'admin_menu', array( 'SofaShoppr', 'addOptions' ) );
?>
<?php
// add an extra input field to Images Repository page in order to make inserted images linkable!

function attachment_url_extra( $form_fields, $post ) {
	$aOptions = SofaShoppr::initOptions( false );
	$spage = $aOptions[ 'slidespage' ];
	if( $spage > 0 && $spage != NULL && $spage != '' && $post->post_parent == $spage ) {
		$post->post_type == 'attachment';
		$form_fields[ 'url' ] = array(
			'label' => __( 'Custom Text Field' ),
			'input' => 'text',
			'value' => get_post_meta( $post->ID, '_url', true )
		);
		$form_fields[ 'url' ][ 'label' ] = __( 'Link this image to the following URL ' );
		$form_fields[ 'url' ][ 'input' ] = 'text';
		$form_fields[ 'url' ][ 'value' ] = get_post_meta( $post->ID, '_url', true );
	}
	return $form_fields;
}

add_filter( 'attachment_fields_to_edit', 'attachment_url_extra', NULL, 2 );

function attachment_url_extra_save( $post, $attachment ) {
	if( isset( $attachment[ 'url' ] ) ) {
		if( trim( $attachment[ 'url'] ) == '' ) $post[ 'errors' ][ 'url' ][ 'errors' ][] = __( 'Error! Something went wrong with your link, check it out and try again.' );
		else update_post_meta( $post[ 'ID' ], '_url', $attachment[ 'url' ] );
	}
	return $post;
}

add_filter( 'attachment_fields_to_save', 'attachment_url_extra_save', NULL, 2 );

// get file size
function getSizeFile( $url ) {
    if( substr( $url, 0, 4 ) == 'http' ) {
        $x = array_change_key_case( get_headers( $url, 1 ), CASE_LOWER );
        if( strcasecmp( $x[ 0 ], 'HTTP/1.1 200 OK' ) != 0 ) { $x = $x[ 'content-length' ][ 1 ]; }
        else { $x = $x[ 'content-length' ]; }
    } else { $x = @filesize( $url ); }
    return $x;
}

// nice excerpt
function avatar_continue_reading_link() {
	return ' <a href="'. get_permalink() . '" class="more-link">' . __( "READ MORE", "sofa_shoppr" ) . '</a>';
}
function avatar_auto_excerpt_more( $more ) {
	return avatar_continue_reading_link();
}
add_filter( 'excerpt_more', 'avatar_auto_excerpt_more' );

// nested comments
function savatar_comments( $comment, $args, $depth ) {
   $GLOBALS[ 'comment' ] = $comment; 
?>
   
	<li class="comment odd" id="li-comment-<?php comment_ID(); ?>">
			
        <div class="gravatar">
           <?php
            $author_email = $comment->comment_author_email;
            echo get_avatar( $author_email, '60' );
            ?>
        </div>
		
        <div class="comment-meta">
            <span class="postedby"><?php comment_author_link(); ?><?php edit_comment_link( 'EDIT', ' | ', '' ); ?></span> <span class="comment-date"><?php comment_date( get_option( 'date_format' ) ); ?></span>
            <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args[ 'max_depth' ] ) ) ); ?>
        </div>
		
		<div class="comment-text">
			<?php comment_text(); ?>
        </div>
        
<?php
}

function my_replylink( $c = '', $post = null ) {
  global $comment;
  // bypass
  if( !comments_open() || $comment->comment_type == "trackback" || $comment->comment_type == "pingback" ) return $c;
  // patch
  $id = $comment->comment_ID;
  $o = '<a class="comment-reply-link" rel="' . $comment->comment_author . '" id="' . $id . '" href="' . get_permalink() . '?replytocom=' . $id . '#respond">' . __( "REPLY", "sofa_shoppr" ) . '</a>';
  return $o;
}
add_filter( 'comment_reply_link', 'my_replylink' );

//the_content() trim
function trim_the_content( $the_contents, $read_more_tag = '...READ MORE', $perma_link_to = '', $all_words = 45 ) {
	// make the list of allowed tags
	$allowed_tags = array( 'a', 'abbr', 'b', 'blockquote', 'b', 'cite', 'code', 'div', 'em', 'fon', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'img', 'label', 'i', 'p', 'pre', 'span', 'strong', 'title', 'ul', 'ol', 'li', 'object', 'embed', 'param' );
	if( $the_contents != '' && $all_words > 0 ) {
		// process allowed tags
		$allowed_tags = '<' . implode( '><', $allowed_tags ) . '>';
		$the_contents = str_replace( ' ]]>', ' ]]&gt;', $the_contents );
		$the_contents = strip_tags( $the_contents, $allowed_tags );
		// exclude HTML from counting words
		if( $all_words > count( preg_split( '/[\s]+/', strip_tags( $the_contents ), -1 ) ) ) return $the_contents;
		// count all
		$all_chunks = preg_split( '/([\s]+)/', $the_contents, -1, PREG_SPLIT_DELIM_CAPTURE );
		$the_contents = '';
		$count_words = 0;
		$enclosed_by_tag = false;
		foreach( $all_chunks as $chunk ) {
			// is tag opened?
			if( 0 < preg_match( '/<[^>]*$/s', $chunk ) ) $enclosed_by_tag = true;
			elseif( 0 < preg_match( '/>[^<]*$/s', $chunk ) ) $enclosed_by_tag = false;
			// get entire word
			if( !$enclosed_by_tag && '' != trim( $chunk ) && substr( $chunk, -1, 1 ) != '>' ) $count_words ++;
			$the_contents .= $chunk;
			if( $count_words >= $all_words && !$enclosed_by_tag ) break;
		}
                // note the class named 'more-link'. style it on your own
		$the_contents = $the_contents . '<a class="more-link" href="' . $perma_link_to . '" rel="nofollow">' . $read_more_tag . '</a>';
		// native WordPress check for unclosed tags
		$the_contents = force_balance_tags( $the_contents );
	}
	return $the_contents;
}
// get custom image size
function get_cont_custom_size_image( $cont = '', $img_type = 'thumbnail', $pid = 0 ) {
	$arrImages =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $pid );
	if( $arrImages && $cont != '' ) {
		$patterns = array( '|width=[\'"](.*?)[\'"].*?|i', '|height=[\'"](.*?)[\'"].*?|i' );
		$cont = preg_replace( $patterns, '', $cont );
		$arrKeys = array_keys( $arrImages );
		$i = 0;
		while( $i < count( $arrImages ) ) {
			// uploaded image width and height
			$temp_arr = explode( 'wp-content', wp_get_attachment_url( $arrKeys[ 0 ] ) );
			$abs_path = ABSPATH . 'wp-content' . $temp_arr[ 1 ];
			
			list( $aip_w, $aip_h ) = getimagesize( $abs_path );
			if( $img_type == 'thumbnail' ) {
				$required_file_path = wp_get_attachment_thumb_url( $arrKeys[ $i ] );
			} else if( $img_type == 'medium' ) {
				$medium_array = image_downsize( $arrKeys[ $i ], 'medium' );
				$required_file_path = $medium_array[ 0 ];
			} else if( $img_type == 'large' ) {
				// reqest large size Media settings
				$large_size_w = get_option( 'large_size_w' );
				// do we actually need downsampled image?
				if( (int)$large_size_w < (int)$aip_w ) {
					$large_array = image_downsize( $arrKeys[ $i ], 'large' );
					$required_file_path = $large_array[ 0 ];
				} else {
					$required_file_path = wp_get_attachment_url( $arrKeys[ $i ] );
				}
			}
			// save file type
			$file_extension_array = explode( '/', $arrImages[ $arrKeys[ $i ] ]->guid );
			$file_type_array = explode( '.', $file_extension_array[ count( $file_extension_array ) - 1 ] );
			// splitter
			$split_by_arr = explode( '.' . $file_type_array[ 1 ], $arrImages[ $arrKeys[ $i ] ]->guid );
			$split_by = $split_by_arr[ 0 ];
			$arr_orig = explode( 'src="' . $split_by, $cont );
			$arr_orig_first = explode( '.' . $file_type_array[ 1 ], $arr_orig[ 1 ] );
			$orig_size_tit = $arr_orig_first[ 0 ];
			$arr_chck_ext = explode( '"', $arr_orig[ 1 ] );
			$arr_first_member = explode( '.', $arr_chck_ext[ 0 ] );
			if( $arr_first_member[ 1 ] == $file_type_array[ 1 ] ) $cont = str_replace( ( $split_by . $orig_size_tit . '.' . $file_type_array[ 1 ] ), $required_file_path, $cont );
			$i ++;
		}
	} 
	return $cont;
}

// breadcrumbs
function dimox_breadcrumbs() {
 
  $delimiter = '&raquo;';
  $name = __( "Home Page", "sofa_yellooh" );
  $currentBefore = '';
  $currentAfter = '';
 
  if ( !is_home() && !is_front_page() || is_paged() ) {
 
    echo '<div id="breadcrumbs">';
 
    global $post;
    $home = get_bloginfo( 'url' );
    echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';
 
    if( is_category() ) {
      global $wp_query;
      $cat_obj = $wp_query->get_queried_object();
      $thisCat = $cat_obj->term_id;
      $thisCat = get_category( $thisCat );
      $parentCat = get_category( $thisCat->parent );
      if( $thisCat->parent != 0 ) echo( get_category_parents( $parentCat, TRUE, ' ' . $delimiter . ' ') );
      echo $currentBefore;
      single_cat_title();
      echo $currentAfter;
 
    } elseif ( is_day() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
      echo $currentBefore . get_the_time('d') . $currentAfter;
 
    } elseif ( is_month() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo $currentBefore . get_the_time('F') . $currentAfter;
 
    } elseif ( is_year() ) {
      echo $currentBefore . get_the_time('Y') . $currentAfter;
 
    } elseif ( is_single() ) {
      $cat = get_the_category(); $cat = $cat[0];
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
      echo $currentBefore;
      the_title();
      echo $currentAfter;
 
    } elseif ( is_page() && !$post->post_parent ) {
      echo $currentBefore;
      the_title();
      echo $currentAfter;
 
    } elseif ( is_page() && $post->post_parent ) {
      $parent_id  = $post->post_parent;
      $breadcrumbs = array();
      while ($parent_id) {
        $page = get_page($parent_id);
        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
        $parent_id  = $page->post_parent;
      }
      $breadcrumbs = array_reverse($breadcrumbs);
      foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
      echo $currentBefore;
      the_title();
      echo $currentAfter;
 
    } elseif ( is_search() ) {
      echo $currentBefore . get_search_query() . $currentAfter;
 
    } elseif ( is_tag() ) {
      echo $currentBefore;
      single_tag_title();
      echo $currentAfter;
 
    } elseif ( is_author() ) {
       global $author;
      $userdata = get_userdata($author);
      echo $currentBefore . $userdata->display_name . $currentAfter;
 
    } elseif ( is_404() ) {
      echo $currentBefore . __( "Error!", "sofa_shoppr" ) . $currentAfter;
    }
 
    if ( get_query_var('paged') ) {
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
      echo __( "Page ", "sofa_shoppr" ) . ' ' . get_query_var('paged');
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
    }
 
    echo '</div>';
 
  }
}

// make nice numberz
function parseInt( $string ) {
	if( preg_match( '/(\d+)/', $string, $array ) ) return $array[ 1 ];
	else return 0;
}
// menus WP3 only!
add_action( 'init', 'register__menus' );

function register__menus() {
	register_nav_menus(
		array(
			'main-menu' => __( 'Main Menu' ),
			'footer-menu' => __( 'Footer Menu' )
		)
	);
}

// custom background
add_custom_background();

// custom header
/*
define( 'NO_HEADER_TEXT', true );
define( 'HEADER_TEXTCOLOR', '' );
define( 'HEADER_IMAGE', get_bloginfo( 'stylesheet_directory' ) . '/images/big_banner.jpg' );
define( 'HEADER_IMAGE_WIDTH', 920 );
define( 'HEADER_IMAGE_HEIGHT', 280 );
function admin_header_style() {
    ?><style type="text/css">
        #banner {
            width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
            height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
        }
    </style><?php
}

add_custom_image_header( 'header_style', 'admin_header_style' );
*/

// modify serach a little bit
function filter_search_rez( $query ) {
    if ( $query->is_search ) {
        $query->set( 'post_type', 'post' );
    }
  return $query;
}

add_filter( 'pre_get_posts', 'filter_search_rez' );

// WIDGETS ---------------------------------------------------------------------------------------

// Advertising 125x125px
class SOFA_Adverts extends WP_Widget {
	function SOFA_Adverts() {
		$widget_ops = array( 'classname' => 'widget_sofa_adverts', 'description' => 'Add 125x125px advertising units.' );
		$control_ops = array( 'width' => 640, 'height' => 400 );
		$this->WP_Widget( 'sofa_adverts', 'SOFA Adverts', $widget_ops, $control_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		$before_widget = '<div class="widget imglinks">';
		$after_widget  = '</div>';
		
		$s_adverts_title = empty( $instance[ 's_adverts_title' ] ) ? __( "Advertising", "sofa_shoppr" ) : apply_filters( 'widget_s_adverts_title', $instance[ 's_adverts_title' ] );
		$s_adverts_code  = empty( $instance[ 's_adverts_code' ] ) ? '' : apply_filters( 'widget_s_adverts_code', $instance[ 's_adverts_code' ] );
		
		echo $before_widget;
		echo $before_title . $s_adverts_title . $after_title;
		echo '<div class="client-list">';
		echo $s_adverts_code;
		echo '</div>';
		echo $after_widget;
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_adverts_title' ] = strip_tags( $new_instance[ 's_adverts_title' ] );
		$instance[ 's_adverts_code' ]  = $new_instance[ 's_adverts_code' ];
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_adverts_title' => '', 's_adverts_code' => '' ) );
		$s_adverts_title = strip_tags( $instance[ 's_adverts_title' ] );
		$s_adverts_code  = $instance[ 's_adverts_code' ];
?>

<p>
<label for="<?php echo $this->get_field_id( 's_adverts_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_adverts_title' ); ?>" name="<?php echo $this->get_field_name( 's_adverts_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_adverts_title ); ?>" />
</label>
</p>

<label for="<?php echo $this->get_field_id( 's_adverts_code' ); ?>">
Advertising code (HTML):
</label>
<textarea class="widefat" rows="16" cols="50" id="<?php echo $this->get_field_id( 's_adverts_code' ); ?>" name="<?php echo $this->get_field_name( 's_adverts_code' ); ?>" type="text" value="<?php echo attribute_escape( $s_adverts_code ); ?>"><?php echo $s_adverts_code; ?></textarea>
            
<?php
	}
}
register_widget( 'SOFA_Adverts' );

// TWITTER 
class SOFA_Twitter extends WP_Widget {
	function SOFA_Twitter() {
		$widget_ops = array( 'classname' => 'widget_sofa_twitter', 'description' => 'Display Twitter Twitts for desired user.' );
		$this->WP_Widget( 'sofa_twitter', 'SOFA Twitter', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		echo $before_widget;
		
		$s_twitter_title = empty( $instance[ 's_twitter_title' ] ) ? __( "Twitter Twitts", "sofa_shoppr" ) : apply_filters( 'widget_s_twitter_title', $instance[ 's_twitter_title' ] );
		$s_twitter_user  = empty( $instance[ 's_twitter_user' ] ) ? 'dameer' : apply_filters( 'widget_s_twitter_user', $instance[ 's_twitter_user' ] );
		$s_twitts_number = empty( $instance[ 's_twitts_number' ] ) ? 'dameer' : apply_filters( 'widget_s_twitts_number', $instance[ 's_twitts_number' ] );

		echo $before_title . $s_twitter_title . $after_title;
		echo '<div class="twittering">';
		echo '<ol id="twitter_update_list"><li>&nbsp;</li></ol>';
		echo '<p class="followus"><a href="http://twitter.com/' . $s_twitter_user . '" title="Follow">' . __( "Follow Us!", "sofa_shoppr" ) . '</a></p>';
        echo '<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>';
        echo '<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/' . $s_twitter_user . '.json?callback=twitterCallback2&amp;count=' . $s_twitts_number . '"></script>';
		echo '</div>';
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_twitter_title' ] = strip_tags( $new_instance[ 's_twitter_title' ] );
		$instance[ 's_twitter_user' ]  = strip_tags( $new_instance[ 's_twitter_user' ] );
		$instance[ 's_twitts_number' ] = strip_tags( $new_instance[ 's_twitts_number' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_twitter_title' => '', 's_twitter_user' => '', 's_twitts_number' => '' ) );
		$s_twitter_title = strip_tags( $instance[ 's_twitter_title' ] );
		$s_twitter_user  = strip_tags( $instance[ 's_twitter_user' ] );
		$s_twitts_number = strip_tags( $instance[ 's_twitts_number' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_twitter_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_twitter_title' ); ?>" name="<?php echo $this->get_field_name( 's_twitter_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_twitter_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_twitter_user' ); ?>">
Twitter Username: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_twitter_user' ); ?>" name="<?php echo $this->get_field_name( 's_twitter_user' ); ?>" type="text" value="<?php echo attribute_escape( $s_twitter_user ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_twitts_number' ); ?>">
Number of Twitts to show: 
<input id="<?php echo $this->get_field_id( 's_twitts_number' ); ?>" name="<?php echo $this->get_field_name( 's_twitts_number' ); ?>" type="text" size="3" value="<?php echo attribute_escape( $s_twitts_number ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Twitter' );

// FLICKR
class SOFA_Flickr extends WP_Widget {
	function SOFA_Flickr() {
		$widget_ops = array( 'classname' => 'widget_sofa_flickr', 'description' => 'Display Flickr photos from desired user or by tag(s).' );
		$this->WP_Widget( 'sofa_flickr', 'SOFA Flickr', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		echo $before_widget;
		
		$s_flickr_title  = empty( $instance[ 's_flickr_title' ] ) ? __( "Flickr Photos", "sofa_shoppr" ) : apply_filters( 'widget_s_flickr_title', $instance[ 's_flickr_title' ] );
		$s_flickr_choice = empty( $instance[ 's_flickr_choice' ] ) ? '14897087@N04' : apply_filters( 'widget_s_flickr_choice', $instance[ 's_flickr_choice' ] );
		$s_flickr_noi    = empty( $instance[ 's_flickr_noi' ] ) ? 6 : apply_filters( 'widget_s_flickr_noi', $instance[ 's_flickr_noi' ] );
		$s_flickr_tou    = empty( $instance[ 's_flickr_tou' ] ) ? 'user' : apply_filters( 'widget_s_flickr_tou', $instance[ 's_flickr_tou' ] );
		
		if( $s_flickr_tou == 'user' ) {
			$url = 'http://www.flickr.com/badge_code_v2.gne?count=' . $s_flickr_noi . '&display=latest&size=s&layout=v&source=' . $s_flickr_tou . '&user=' . $s_flickr_choice;
		} else if( $s_flickr_tou == 'all_tag' ) {
			$url = 'http://www.flickr.com/badge_code_v2.gne?count=' . $s_flickr_noi . '&display=latest&size=s&layout=v&source=' . $s_flickr_tou . '&tag=' . $s_flickr_choice;
		}
		$html = file_get_contents( $url );
		$matched = preg_match_all( '|<a.*?href=[\'"](.*?)[\'"].*?>.*?<img.*?src=[\'"](.*?)[\'"].*?><.*?a>|i', $html, $imgs );
		if( $matched > 0 ) {
			echo $before_title . $s_flickr_title . $after_title;
			echo '<div class="flick">';
			$ci = 1;
			while( $ci <= $matched ) {
				echo '<a href="' . $imgs[ 1 ][ $ci - 1 ] . '" title="">';
				echo '<img class="flickr" src="' . $imgs[ 2 ][ $ci - 1 ] . '" alt="" width="75" height="75" />';
				echo '</a>';
				$ci ++;
			}
			echo '</div>';
		}
		
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_flickr_title' ]  = strip_tags( $new_instance[ 's_flickr_title' ] );
		$instance[ 's_flickr_choice' ] = strip_tags( $new_instance[ 's_flickr_choice' ] );
		$instance[ 's_flickr_noi' ]    = strip_tags( $new_instance[ 's_flickr_noi' ] );
		$instance[ 's_flickr_tou' ]    = strip_tags( $new_instance[ 's_flickr_tou' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_flickr_title' => '', 's_flickr_choice' => '', 's_flickr_noi' => '', 's_flickr_tou' => '' ) );
		$s_flickr_title  = strip_tags( $instance[ 's_flickr_title' ] );
		$s_flickr_choice = strip_tags( $instance[ 's_flickr_choice' ] );
		$s_flickr_noi    = strip_tags( $instance[ 's_flickr_noi' ] );
		$s_flickr_tou    = strip_tags( $instance[ 's_flickr_tou' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_flickr_title' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_flickr_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_tou' ); ?>">
Show photos by user or tag(s)? 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_flickr_tou' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_tou' ); ?>">
	<?php if( $s_flickr_tou == 'user' ) { ?>
    <option value="user" selected="selected"> - By user - </option>
    <option value="all_tag"> - By tag(s) - </option>
    <?php
    } else if( $s_flickr_tou == 'all_tag' ) {
    ?>
    <option value="user"> - By user - </option>
    <option value="all_tag" selected="selected"> - By tag(s) - </option>
    <?php
    } else {
    ?>
    <option value="user" selected="selected"> - By user - </option>
    <option value="all_tag"> - By tag(s) - </option>
    <?php
    }
    ?>
</select>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_choice' ); ?>">
If your choice was 'By tag(s)' - enter a tag or comma separated tags. Otherwise enter Flickr user ID (something like '14897087@N04'. Note: it's not a Flickr username!)
<input class="widefat" id="<?php echo $this->get_field_id( 's_flickr_choice' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_choice' ); ?>" type="text" value="<?php echo attribute_escape( $s_flickr_choice ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_noi' ); ?>">
Number of Flickr thumbs to show: 
<input id="<?php echo $this->get_field_id( 's_flickr_noi' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_noi' ); ?>" type="text" size="3" value="<?php echo attribute_escape( $s_flickr_noi ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Flickr' );

// TAG CLOUD 
class SOFA_Tags extends WP_Widget {
	function SOFA_Tags() {
		$widget_ops = array( 'classname' => 'widget_sofa_tags', 'description' => 'Display Tag Cloud.' );
		$this->WP_Widget( 'sofa_tags', 'SOFA Tags', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		echo $before_widget;
		
		$s_tag_title  = empty( $instance[ 's_tag_title' ] ) ? __( "Tag Cloud", "sofa_shoppr" ) : apply_filters( 'widget_s_tag_title', $instance[ 's_tag_title' ] );
		$s_tag_number = empty( $instance[ 's_tag_number' ] ) ? '50' : apply_filters( 'widget_s_tag_number', $instance[ 's_tag_number' ] );

		echo $before_title . $s_tag_title . $after_title;
		echo '<p>';
		$tag_defaults = array( 'smallest' => 9, 'largest' => 18, 'unit' => 'pt', 'number' => $s_tag_number, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true ); 
		wp_tag_cloud( $tag_defaults );
		echo '</p>';
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_tag_title' ]  = strip_tags( $new_instance[ 's_tag_title' ] );
		$instance[ 's_tag_number' ] = strip_tags( $new_instance[ 's_tag_number' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_tag_title' => '', 's_tag_number' => '' ) );
		$s_tag_title  = strip_tags( $instance[ 's_tag_title' ] );
		$s_tag_number = strip_tags( $instance[ 's_tag_number' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_tag_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_tag_title' ); ?>" name="<?php echo $this->get_field_name( 's_tag_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_tag_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_twitts_number' ); ?>">
Number of Tags to show (50 should work just fine): 
<input id="<?php echo $this->get_field_id( 's_tag_number' ); ?>" name="<?php echo $this->get_field_name( 's_tag_number' ); ?>" type="text" size="3" value="<?php echo attribute_escape( $s_tag_number ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Tags' );

// SECTIONAL NAVIGATION
class SOFA_Sectional extends WP_Widget {
	function SOFA_Sectional() {
		$widget_ops = array( 'classname' => 'widget_sofa_sidenav', 'description' => 'Display Categories List.' );
		$this->WP_Widget( 'sofa_sidenav', 'SOFA Categories Navigation', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		global $wpdb;
		extract( $args, EXTR_SKIP );
		
		$s_sidenav_title = empty( $instance[ 's_sidenav_title' ] ) ? __( "Navigate", "sofa_shoppr" ) : apply_filters( 'widget_s_sidenav_title', $instance[ 's_sidenav_title' ] );
		$s_exclude_cates = empty( $instance[ 's_exclude_cates' ] ) ? '' : apply_filters( 'widget_s_exclude_cates', $instance[ 's_exclude_cates' ] );
			
		echo '<div class="widget subnav">';
		echo '<h2>' . $s_sidenav_title . '</h2>';
		echo '<ul>';
		wp_list_categories( 'title_li=&show_count=1&depth=-1&exclude=' . $s_exclude_cates . '&hide_empty=0' );
		echo '</ul>';
		echo '</div>';
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_sidenav_title' ]  = strip_tags( $new_instance[ 's_sidenav_title' ] );
		$instance[ 's_exclude_cates' ]  = strip_tags( $new_instance[ 's_exclude_cates' ] );
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_sidenav_title' => '', 's_exclude_cates' => '' ) );
		$s_sidenav_title  = strip_tags( $instance[ 's_sidenav_title' ] );
		$s_exclude_cates  = strip_tags( $instance[ 's_exclude_cates' ] );
?>

<p>
Categories Navigation will automatically generate list of categories in sidebar.<br />
<label for="<?php echo $this->get_field_id( 's_sidenav_title' ); ?>">
Default Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_sidenav_title' ); ?>" name="<?php echo $this->get_field_name( 's_sidenav_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_sidenav_title ); ?>" />
</label>
</p>

<p>
Exclude the following categories from navigation (ID of categories, comma separated, for example: 6, 12, 33)<br />
<label for="<?php echo $this->get_field_id( 's_exclude_cates' ); ?>">
Enter category ID(s):
<input class="widefat" id="<?php echo $this->get_field_id( 's_exclude_cates' ); ?>" name="<?php echo $this->get_field_name( 's_exclude_cates' ); ?>" type="text" value="<?php echo attribute_escape( $s_exclude_cates ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Sectional' );

// PAGEONAL NAVIGATION
class SOFA_Pageonal extends WP_Widget {
	function SOFA_Pageonal() {
		$widget_ops = array( 'classname' => 'widget_sofa_pagenav', 'description' => 'Display Pages List.' );
		$this->WP_Widget( 'sofa_pagenav', 'SOFA Pages Navigation', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		global $wpdb;
		$aOptions = SofaShoppr::initOptions( false );
		$chpage = $aOptions[ 'chckoutpage' ];
		$orpage = $aOptions[ 'orderspage' ];
		$slpage = $aOptions[ 'slidespage' ];
		$prepend_exclude = ',' . $chpage . ',' . $orpage . ',' . $slpage;
		extract( $args, EXTR_SKIP );
		
		$s_pagenav_title = empty( $instance[ 's_pagenav_title' ] ) ? __( "Navigate", "sofa_shoppr" ) : apply_filters( 'widget_s_pagenav_title', $instance[ 's_pagenav_title' ] );
		$s_exclude_pages = empty( $instance[ 's_exclude_pages' ] ) ? '' : apply_filters( 'widget_s_exclude_pages', $instance[ 's_exclude_pages' ] );

		echo '<div class="widget subnav">';
		echo '<h2>' . $s_pagenav_title . '</h2>';
		echo '<ul>';
		wp_list_pages( 'title_li=&depth=-1&exclude=' . $s_exclude_pages . $prepend_exclude );
		echo '</ul>';
		echo '</div>';
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_pagenav_title' ]  = strip_tags( $new_instance[ 's_pagenav_title' ] );
		$instance[ 's_exclude_pages' ]  = strip_tags( $new_instance[ 's_exclude_pages' ] );
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_pagenav_title' => '', 's_exclude_pages' => '' ) );
		$s_sidenav_title  = strip_tags( $instance[ 's_pagenav_title' ] );
		$s_exclude_pages  = strip_tags( $instance[ 's_exclude_pages' ] );
?>

<p>
Pages Navigation will automatically generate list of pages in sidebar.<br />
<label for="<?php echo $this->get_field_id( 's_pagenav_title' ); ?>">
Default Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_pagenav_title' ); ?>" name="<?php echo $this->get_field_name( 's_pagenav_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_pagenav_title ); ?>" />
</label>
</p>

<p>
Exclude the following pages from navigation (ID of page(s), comma separated, for example: 5, 9, 45)<br />
<label for="<?php echo $this->get_field_id( 's_exclude_pages' ); ?>">
Enter page ID(s): 
<input class="widefat" id="<?php echo $this->get_field_id( 's_exclude_pages' ); ?>" name="<?php echo $this->get_field_name( 's_exclude_pages' ); ?>" type="text" value="<?php echo attribute_escape( $s_exclude_pages ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Pageonal' );

// RECENT COMMENTS 
class SOFA_RecentComments extends WP_Widget {
	function SOFA_RecentComments() {
		$widget_ops = array( 'classname' => 'widget_sofa_recentcomments', 'description' => 'Display N number of recent reviews.' );
		$this->WP_Widget( 'sofa_recentcomments', 'SOFA Recent Reviews', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		echo $before_widget;
		
		$s_recentcomments_title = empty( $instance[ 's_recentcomments_title' ] ) ? __( "Recent Reviews", "sofa_shoppr" ) : apply_filters( 'widget_s_recentcomments_title', $instance[ 's_recentcomments_title' ] );
		$s_recentcomments_number = empty( $instance[ 's_recentcomments_number' ] ) ? 5 : apply_filters( 'widget_s_recentcomments_number', $instance[ 's_recentcomments_number' ] );

		echo $before_title . $s_recentcomments_title . $after_title;
		
		global $wpdb;
		$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date, comment_approved, comment_type, comment_author_url, SUBSTRING(comment_content,1,90) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT $s_recentcomments_number";
		$commentz = $wpdb->get_results( $sql );
		if( $commentz ) {
			echo '<ul class="entries recentposts">';
			foreach( $commentz as $comm ) {
				echo '<li>';
				echo '<div class="post-info">';
				echo '<span class="date">' . mysql2date( get_option( 'date_format' ), $comm->comment_date ) . '</span> &bull; ';
				echo '<span class="category">' . __( "By", "sofa_shoppr" ) . ' ' . $comm->comment_author . '</span>';
				echo '</div>';
				echo '<h3 class="post-title"><a href="' . get_permalink( $comm->ID ) . '#comments" title="' . $comm->post_title . '">' . strip_tags( $comm->com_excerpt ) . '</a></h3>';
				echo '</li>';
			}
			echo '</ul>';
		} else {
			echo '<p>';
			echo __( "No Recent Reviews found!", "sofa_shoppr" );
			echo '</p>';
		}
		
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_recentcomments_title' ] = strip_tags( $new_instance[ 's_recentcomments_title' ] );
		$instance[ 's_recentcomments_number' ] = strip_tags( $new_instance[ 's_recentcomments_number' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_recentcomments_title' => '', 's_recentcomments_number' => '' ) );
		$s_recentcomments_title = strip_tags( $instance[ 's_recentcomments_title' ] );
		$s_recentcomments_number = strip_tags( $instance[ 's_recentcomments_number' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_recentcomments_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_recentcomments_title' ); ?>" name="<?php echo $this->get_field_name( 's_recentcomments_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_recentcomments_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_recentcomments_number' ); ?>">
Number of Recent Reviews to show: 
<input id="<?php echo $this->get_field_id( 's_recentcomments_number' ); ?>" name="<?php echo $this->get_field_name( 's_recentcomments_number' ); ?>" type="text" size="3" value="<?php echo attribute_escape( $s_recentcomments_number ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_RecentComments' );

// SHOPPING CART
class SOFA_Shoppingcart extends WP_Widget {
	function SOFA_Shoppingcart() {
		$widget_ops = array( 'classname' => 'widget_sofa_shoppingcart', 'description' => 'Display mini Shopping Cart in sidebar.' );
		$this->WP_Widget( 'sofa_shoppingcart', 'SOFA ShoppingCart', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		//echo $before_widget;
		
		$s_shoppingcart_title = empty( $instance[ 's_shoppingcart_title' ] ) ? __( "Your Basket", "sofa_shoppr" ) : apply_filters( 'widget_s_shoppingcart_title', $instance[ 's_shoppingcart_title' ] );

		//echo $before_title . $s_shoppingcart_title . $after_title;
		
		$aOptions = SofaShoppr::initOptions( false );
		$entrycurrency = $aOptions[ 'entrycurrency' ];
		$taxpercentage = $aOptions[ 'taxpercentage' ];
		if( $taxpercentage < 0 ) $taxpercentage = 0;
		
		$chckoutpage = $aOptions[ 'chckoutpage' ];
		$orderspage = $aOptions[ 'orderspage' ];
		$perma_orders = get_permalink( (int)$orderspage );
		
		$items_sum = 0;
		if( isset( $_COOKIE[ 'sofashoppr' ] ) ) {
			echo $before_widget;
			echo '<h2 class="widgettitle baskettitleh2">' . $s_shoppingcart_title . '</h2>';
			echo '<ul class="entries recentposts">';
			foreach( $_COOKIE[ 'sofashoppr' ] as $name => $value ) {
				// $value may contain additional item info
				$item_info_extra_array = explode( ':', $value );
				$item_size = '';
				$item_color = '';
				if( $item_info_extra_array[ 2 ] != NULL ) $item_size  = $item_info_extra_array[ 2 ];
				if( $item_info_extra_array[ 3 ] != NULL ) $item_color = $item_info_extra_array[ 3 ];
				$p_o = get_post( $name );
				$custom_fields = get_post_custom( $name );
				$item_price = ( $item_info_extra_array[ 4 ] != NULL ) ? $item_info_extra_array[ 4 ] : $custom_fields[ 'price' ][ 0 ];
				$perma_item = get_permalink( $p_o->ID );
				$title_item = stripslashes( strip_tags( $p_o->post_title ) );
				if( $item_size != '' ) $title_item .= ' | ' . $item_size;
				if( $item_color != '' ) $title_item .= ' | ' . $item_color;
				echo '<li class="basketit">';
				echo '<p class="pcell width69"><a href="' . $perma_item . '" title="' . __( "Item details", "sofa_shoppr" ) . '">' . $item_info_extra_array[ 1 ] . 'x ' . $title_item . '</a></p>';
				echo '<p class="pcell width31 aright">' . $entrycurrency . ' ' . number_format( $item_price * $item_info_extra_array[ 1 ], 2, '.', ',' ) . '</p>';
				echo '</li>';
				
				$items_sum = $items_sum + ( $item_price * $item_info_extra_array[ 1 ] );
			}
			
			echo '<li class="basketit">';
			echo '<p class="pcell width40">&nbsp;</p>';
			echo '<p class="pcell width30 aright">' . __( "Subotal", "sofa_shoppr" ) . ': </p>';
			echo '<p class="pcell width30 aright">' . $entrycurrency . ' ' . number_format( $items_sum, 2, '.', ',' ) . '</p>';
			echo '</li>';
			
			if( $taxpercentage > 0 ) echo '<li class="basketit">';
			
			if( $taxpercentage > 0 ) {
				$bare_tax = ( $items_sum * $taxpercentage ) / 100;
				$items_sum = $items_sum + $bare_tax;
			}
			
			if( $taxpercentage > 0 ) {
				echo '<p class="pcell width40">&nbsp;</p>';
				echo '<p class="pcell width30 aright">' . __( "Tax", "sofa_shoppr" ) . '(' . $taxpercentage . '%): </p>';
				echo '<p class="pcell width30 aright">' . $entrycurrency . ' ' . number_format( $bare_tax, 2, '.', ',' ) . '</p>';
			}
			
			if( $taxpercentage > 0 ) echo '</li>';
			
			$perma_chckout = get_permalink( $chckoutpage );
			echo '<li class="basketit">';
			echo '<p class="pcell width40 chckouticon accent"><span class="checkoutspan"><a href="' . $perma_chckout . '" title="' . __( "Make the payment", "sofa_shoppr" ) . '">CHECK OUT</a></span></p>';
			echo '<p class="pcell width30 aright">' . __( "Total", "sofa_shoppr" ) . ': </p>';
			echo '<p class="pcell width30 aright">' . $entrycurrency . ' ' . number_format( $items_sum, 2, '.', ',' ) . '</p>';
			echo '</li>';
		
			echo '</ul>';
			echo $after_widget;
		}
		//echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_shoppingcart_title' ] = strip_tags( $new_instance[ 's_shoppingcart_title' ] );
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_shoppingcart_title' => '' ) );
		$s_shoppingcart_title = strip_tags( $instance[ 's_shoppingcart_title' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_shoppingcart_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_shoppingcart_title' ); ?>" name="<?php echo $this->get_field_name( 's_shoppingcart_title' ); ?>" type="text" value="<?php echo attribute_escape( $s_shoppingcart_title ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Shoppingcart' );
?>